blob: e2152b0dfc2dc978902291fb30acfcbb38b9ce2b [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
6" Last Change:
7" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
K.Takata8750e3c2023-11-22 18:20:01 +09008" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Christian Brabandtf9ca1392024-02-19 20:37:11 +010012" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000013" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010014" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000015" Permission is hereby granted to use and distribute this code,
16" with or without modifications, provided that this copyright
17" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000018" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000019" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000020" expressed or implied. By using this plugin, you agree that
21" in no event will the copyright holder be liable for any damages
22" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010023"
24" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
25" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
26"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020027"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000028"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000029" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000030" (James 1:22 RSV)
31" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000032" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000033if &cp || exists("g:loaded_netrw")
34 finish
35endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020036
37" Check that vim has patches that netrw requires.
38" Patches needed for v7.4: 1557, and 213.
39" (netrw will benefit from vim's having patch#656, too)
40let s:needspatches=[1557,213]
41if exists("s:needspatches")
42 for ptch in s:needspatches
43 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
44 if !exists("s:needpatch{ptch}")
45 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
46 endif
47 let s:needpatch{ptch}= 1
48 finish
49 endif
50 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020051endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020052
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010053let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000054if !exists("s:NOTE")
55 let s:NOTE = 0
56 let s:WARNING = 1
57 let s:ERROR = 2
58endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000059
Bram Moolenaar1afcace2005-11-25 19:54:28 +000060let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010061setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020062"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010063"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010064"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000065
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000066" ======================
67" Netrw Variables: {{{1
68" ======================
69
Bram Moolenaar071d4272004-06-13 20:20:40 +000070" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020071" netrw#ErrorMsg: {{{2
72" 0=note = s:NOTE
73" 1=warning = s:WARNING
74" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010075" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
76" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
77" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010078" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020079fun! netrw#ErrorMsg(level,msg,errnum)
80" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
81
82 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020083" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020084 return
85 endif
86
87 if a:level == 1
88 let level= "**warning** (netrw) "
89 elseif a:level == 2
90 let level= "**error** (netrw) "
91 else
92 let level= "**note** (netrw) "
93 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010094" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020095
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020096 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
97 " use popup window
98 if type(a:msg) == 3
99 let msg = [level]+a:msg
100 else
101 let msg= level.a:msg
102 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200103 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200104 let s:popuperr_text= ""
105 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200106 " (default) netrw creates a one-line window to show error/warning
107 " messages (reliably displayed)
108
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100109 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200110 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100111" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200112
113 " getting messages out reliably is just plain difficult!
114 " This attempt splits the current window, creating a one line window.
115 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100116" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200117 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100118" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200119 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100120 if type(a:msg) == 3
121 for msg in a:msg
122 NetrwKeepj call setline(line("$")+1,level.msg)
123 endfor
124 else
125 NetrwKeepj call setline(line("$")+1,level.a:msg)
126 endif
127 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200128 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100129" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200130 bo 1split
131 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200132 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200133 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100134 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100135" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200136 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100137 if type(a:msg) == 3
138 for msg in a:msg
139 NetrwKeepj call setline(line("$")+1,level.msg)
140 endfor
141 else
142 NetrwKeepj call setline(line("$"),level.a:msg)
143 endif
144 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200145 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100146" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200147 if &fo !~ '[ta]'
148 syn clear
149 syn match netrwMesgNote "^\*\*note\*\*"
150 syn match netrwMesgWarning "^\*\*warning\*\*"
151 syn match netrwMesgError "^\*\*error\*\*"
152 hi link netrwMesgWarning WarningMsg
153 hi link netrwMesgError Error
154 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100155" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200156 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200157
158 else
159 " (optional) netrw will show messages using echomsg. Even if the
160 " message doesn't appear, at least it'll be recallable via :messages
161" redraw!
162 if a:level == s:WARNING
163 echohl WarningMsg
164 elseif a:level == s:ERROR
165 echohl Error
166 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100167
168 if type(a:msg) == 3
169 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100170 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100171 endfor
172 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100173 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100174 endif
175
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100176" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200177 echohl None
178 endif
179
180" call Dret("netrw#ErrorMsg")
181endfun
182
183" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100184" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100185" Loosely, varname = value.
186fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100187" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100188 if !exists(a:varname)
189 if type(a:value) == 0
190 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200191 elseif type(a:value) == 1 && a:value =~ '^[{[]'
192 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100193 elseif type(a:value) == 1
194 exe "let ".a:varname."="."'".a:value."'"
195 else
196 exe "let ".a:varname."=".a:value
197 endif
198 endif
199endfun
200
201" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000202" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200203call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000204if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100205 call s:NetrwInit("s:THINLIST",0)
206 call s:NetrwInit("s:LONGLIST",1)
207 call s:NetrwInit("s:WIDELIST",2)
208 call s:NetrwInit("s:TREELIST",3)
209 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000210endif
211
212" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200213" Default option values: {{{2
214let g:netrw_localcopycmdopt = ""
215let g:netrw_localcopydircmdopt = ""
216let g:netrw_localmkdiropt = ""
217let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200218
219" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000220" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200221if (v:version > 802 || (v:version == 802 && has("patch486"))) && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on") && has("mouse")
222 call s:NetrwInit("g:netrw_use_errorwindow",2)
223else
224 call s:NetrwInit("g:netrw_use_errorwindow",1)
225endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200226
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000227if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100228 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000229 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100230 elseif executable("curl")
231 let g:netrw_dav_cmd = "curl"
232 else
233 let g:netrw_dav_cmd = ""
234 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000235endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000236if !exists("g:netrw_fetch_cmd")
237 if executable("fetch")
238 let g:netrw_fetch_cmd = "fetch -o"
239 else
240 let g:netrw_fetch_cmd = ""
241 endif
242endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100243if !exists("g:netrw_file_cmd")
244 if executable("elinks")
245 call s:NetrwInit("g:netrw_file_cmd","elinks")
246 elseif executable("links")
247 call s:NetrwInit("g:netrw_file_cmd","links")
248 endif
249endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000250if !exists("g:netrw_ftp_cmd")
251 let g:netrw_ftp_cmd = "ftp"
252endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200253let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200254if !exists("g:netrw_ftp_options")
255 let g:netrw_ftp_options= "-i -n"
256endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000257if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100258 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100259 let g:netrw_http_cmd = "wget"
260 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100261 elseif executable("curl")
262 let g:netrw_http_cmd = "curl"
263 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200264 elseif executable("elinks")
265 let g:netrw_http_cmd = "elinks"
266 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000267 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100268 let g:netrw_http_cmd = "fetch"
269 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200270 elseif executable("links")
271 let g:netrw_http_cmd = "links"
272 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000273 else
274 let g:netrw_http_cmd = ""
275 endif
276endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100277call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100278call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100279call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
280call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200281call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200282if !exists("g:netrw_scp_cmd")
283 if executable("scp")
284 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
285 elseif executable("pscp")
286 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable('c:\private.ppk')
287 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
288 else
289 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
290 endif
291 else
292 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
293 endif
294endif
295
Bram Moolenaar5c736222010-01-06 20:54:52 +0100296call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
297call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000298
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000299if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000300 \ && exists("g:netrw_use_nt_rcp")
301 \ && g:netrw_use_nt_rcp
302 \ && executable( $SystemRoot .'/system32/rcp.exe')
303 let s:netrw_has_nt_rcp = 1
304 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000305else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000306 let s:netrw_has_nt_rcp = 0
307 let s:netrw_rcpmode = ''
308endif
309
310" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000311" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000312" Cygwin Detection ------- {{{3
313if !exists("g:netrw_cygwin")
314 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100315 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000316 let g:netrw_cygwin= 1
317 else
318 let g:netrw_cygwin= 0
319 endif
320 else
321 let g:netrw_cygwin= 0
322 endif
323endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000324" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100325call s:NetrwInit("g:netrw_alto" , &sb)
326call s:NetrwInit("g:netrw_altv" , &spr)
327call s:NetrwInit("g:netrw_banner" , 1)
328call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200329call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100330call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200331call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100332call s:NetrwInit("g:netrw_compress" , "gzip")
333call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200334if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
335 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
336 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000337endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200338call s:NetrwInit("g:netrw_cursor" , 2)
339let s:netrw_usercul = &cursorline
340let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200341"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100342call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000343" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200344call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200345call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200346call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100347call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200348call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100349call s:NetrwInit("g:netrw_fastbrowse" , 1)
350call 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 +0000351if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000352 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
353 let g:netrw_ftp_list_cmd = "ls -lF"
354 let g:netrw_ftp_timelist_cmd = "ls -tlF"
355 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000356 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000357 let g:netrw_ftp_list_cmd = "dir"
358 let g:netrw_ftp_timelist_cmd = "dir"
359 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000360 endif
361endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100362call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000363" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100364call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000365if !exists("g:netrw_ignorenetrc")
366 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
367 let g:netrw_ignorenetrc= 1
368 else
369 let g:netrw_ignorenetrc= 0
370 endif
371endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100372call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000373if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000374 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000375 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200376 " provide a pscp-based listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000377 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
378 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100379 if exists("g:netrw_list_cmd_options")
380 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
381 else
382 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
383 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000384 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200385 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100386 if exists("g:netrw_list_cmd_options")
387 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
388 else
389 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
390 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000391 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100392" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000393 let g:netrw_list_cmd= ""
394 endif
395endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100396call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000397" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200398if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200399 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200400 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
401endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100402if !exists("g:netrw_localcmdshell")
403 let g:netrw_localcmdshell= ""
404endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000405if !exists("g:netrw_localcopycmd")
406 if has("win32") || has("win95") || has("win64") || has("win16")
407 if g:netrw_cygwin
408 let g:netrw_localcopycmd= "cp"
409 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000410 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200411 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000412 endif
413 elseif has("unix") || has("macunix")
414 let g:netrw_localcopycmd= "cp"
415 else
416 let g:netrw_localcopycmd= ""
417 endif
418endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100419if !exists("g:netrw_localcopydircmd")
420 if has("win32") || has("win95") || has("win64") || has("win16")
421 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200422 let g:netrw_localcopydircmd = "cp"
423 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100424 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000425 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200426 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100427 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200428 elseif has("unix")
429 let g:netrw_localcopydircmd = "cp"
430 let g:netrw_localcopydircmdopt= " -R"
431 elseif has("macunix")
432 let g:netrw_localcopydircmd = "cp"
433 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100434 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200435 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100436 endif
437endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200438if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100439 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200440 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
441endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200442if has("win32") || has("win95") || has("win64") || has("win16")
443 if g:netrw_cygwin
444 call s:NetrwInit("g:netrw_localmkdir","mkdir")
445 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000446 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200447 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200448 endif
449else
450 call s:NetrwInit("g:netrw_localmkdir","mkdir")
451endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200452call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200453if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200454 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200455 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
456endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000457if !exists("g:netrw_localmovecmd")
458 if has("win32") || has("win95") || has("win64") || has("win16")
459 if g:netrw_cygwin
460 let g:netrw_localmovecmd= "mv"
461 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000462 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200463 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000464 endif
465 elseif has("unix") || has("macunix")
466 let g:netrw_localmovecmd= "mv"
467 else
468 let g:netrw_localmovecmd= ""
469 endif
470endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100471" following serves as an example for how to insert a version&patch specific test
472"if v:version < 704 || (v:version == 704 && !has("patch1107"))
473"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100474call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
475" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000476if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000477 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000478endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000479if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000480 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
481endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000482" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100483call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
484call s:NetrwInit("g:netrw_maxfilenamelen", 32)
485call s:NetrwInit("g:netrw_menu" , 1)
486call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200487call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100488call s:NetrwInit("g:netrw_retmap" , 0)
489if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
490 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
491elseif has("win32") || has("win95") || has("win64") || has("win16")
492 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
493else
494 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000495endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100496call s:NetrwInit("g:netrw_preview" , 0)
497call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100498call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100499call s:NetrwInit("g:netrw_sshport" , "-p")
500call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
501call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
502call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100503call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
504" Default values - q-s ---------- {{{3
505call s:NetrwInit("g:netrw_quickhelp",0)
506let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100507 \ "(create new) %:file d:directory",
508 \ "(windows split&open) o:horz v:vert p:preview",
509 \ "i:style qf:file info O:obtain r:reverse",
510 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
511 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
512 \ "(history) qb:list u:go up U:go down",
513 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100514" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
515call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100516if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
517 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
518else
519 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
520endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100521call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
522call s:NetrwInit("g:netrw_sort_options" , "")
523call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000524if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100525 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200526 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100527 else
528 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000529 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000530endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100531call s:NetrwInit("g:netrw_special_syntax" , 0)
532call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200533call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100534call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100535call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000536" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100537call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200538if !exists("g:netrw_xstrlen")
539 if exists("g:Align_xstrlen")
540 let g:netrw_xstrlen= g:Align_xstrlen
541 elseif exists("g:drawit_xstrlen")
542 let g:netrw_xstrlen= g:drawit_xstrlen
543 elseif &enc == "latin1" || !has("multi_byte")
544 let g:netrw_xstrlen= 0
545 else
546 let g:netrw_xstrlen= 1
547 endif
548endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100549call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100550call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200551call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100552call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200553if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000554" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000555" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100556call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200557if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarff034192013-04-24 18:51:19 +0200558 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200559else
Bram Moolenaarff034192013-04-24 18:51:19 +0200560 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200561endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200562call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100563call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
564call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100565if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100566 let s:treedepthstring= "│ "
567else
568 let s:treedepthstring= "| "
569endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200570call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000571
572" BufEnter event ignored by decho when following variable is true
573" Has a side effect that doau BufReadPost doesn't work, so
574" files read by network transfer aren't appropriately highlighted.
575"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576
Bram Moolenaaradc21822011-04-01 18:03:16 +0200577" ======================
578" Netrw Initialization: {{{1
579" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200580if 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 +0100581" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100582 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200583" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100584 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100585 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
586 au VimEnter * let s:initbeval= &beval
587"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100588" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
589" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
590" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
591" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
592" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
593" 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 +0200594endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200595au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200596
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200597if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100598 com! -nargs=* NetrwKeepj keepj <args>
599else
600 let g:netrw_keepj= ""
601 com! -nargs=* NetrwKeepj <args>
602endif
603
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000604" ==============================
605" Netrw Utility Functions: {{{1
606" ==============================
607
Bram Moolenaaradc21822011-04-01 18:03:16 +0200608" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100609" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100610if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100611" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100612 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100613 if &ft != "netrw"
614 return ""
615 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200616 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
617 " popup error window is still showing
618 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
619 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
620 " text under mouse hasn't changed; only close window when it changes
621 call popup_close(s:popuperr_id)
622 unlet s:popuperr_text
623 else
624 let s:popuperr_text= v:beval_text
625 endif
626 let mesg= ""
627 elseif !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval)
Bram Moolenaar8d043172014-01-23 14:24:41 +0100628 let mesg= ""
629 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
630 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
631 elseif getline(v:beval_lnum) =~ '^"\s*/'
632 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
633 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100634 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100635 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
636 let mesg = "S: edit sorting sequence"
637 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
638 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
639 elseif v:beval_text == "Quick" || v:beval_text == "Help"
640 let mesg = "Help: press <F1>"
641 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
642 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
643 else
644 let mesg= ""
645 endif
646 return mesg
647 endfun
648"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100649" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
650" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
651" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
652" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
653" 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 +0200654endif
655
Bram Moolenaar071d4272004-06-13 20:20:40 +0000656" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200657" netrw#Explore: launch the local browser in the directory of the current file {{{2
658" indx: == -1: Nexplore
659" == -2: Pexplore
660" == +: this is overloaded:
661" * If Nexplore/Pexplore is in use, then this refers to the
662" indx'th item in the w:netrw_explore_list[] of items which
663" matched the */pattern **/pattern *//pattern **//pattern
664" * If Hexplore or Vexplore, then this will override
665" g:netrw_winsize to specify the qty of rows or columns the
666" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100667" 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 +0200668" dosplit==1: the window will be split before running the local browser
669" style == 0: Explore style == 1: Explore!
670" == 2: Hexplore style == 3: Hexplore!
671" == 4: Vexplore style == 5: Vexplore!
672" == 6: Texplore
673fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100674" 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 +0100675" 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 +0200676 if !exists("b:netrw_curdir")
677 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100678" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200679 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100680
681 " record current file for Rexplore's benefit
682 if &ft != "netrw"
683 let w:netrw_rexfile= expand("%:p")
684 endif
685
686 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200687 let curdir = simplify(b:netrw_curdir)
688 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200689 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
690 let curdir= substitute(curdir,'\','/','g')
691 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100692" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100693
694 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
695 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
696 " try Explore again.
697 if a:0 > 0
698" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100699 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
700 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
701 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
702 \ '~'.expand("<slnum>"))
703 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
704" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100705 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
706" call Dret("netrw#Explore : returning from retry")
707 return
708" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100709" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100710 endif
711 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200712
713 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200714 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100715" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100716 sil! let keepregstar = @*
717 sil! let keepregplus = @+
718 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200719 sil! let keepregslash= @/
720
Bram Moolenaar8d043172014-01-23 14:24:41 +0100721 " if dosplit
722 " -or- file has been modified AND file not hidden when abandoned
723 " -or- Texplore used
724 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100725" 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 +0200726 call s:SaveWinVars()
727 let winsz= g:netrw_winsize
728 if a:indx > 0
729 let winsz= a:indx
730 endif
731
732 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100733" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200734 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200735 if winsz == 0|let winsz= ""|endif
736 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100737" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200738
739 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100740" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200741 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200742 if winsz == 0|let winsz= ""|endif
743 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100744" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200745
746 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100747" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200748 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200749 if winsz == 0|let winsz= ""|endif
750 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100751" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200752
753 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100754" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200755 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200756 if winsz == 0|let winsz= ""|endif
757 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100758" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200759
760 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100761" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200762 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200763 if winsz == 0|let winsz= ""|endif
764 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100765" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200766
767 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100768" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200769 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200770 if winsz == 0|let winsz= ""|endif
771 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100772" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200773
774 elseif a:style == 6 " Texplore
775 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100776" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100778" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200779 call s:RestoreBufVars()
780 endif
781 call s:RestoreWinVars()
782" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100783" 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 +0200784 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100785 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200786
787 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
796 if dirname !~ '/$'
797 let dirname= dirname."/"
798 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100799" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200800 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100801" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100803" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200804 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100805" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200806 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100807" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200808 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100809" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200810 let dirname= a:1
811 endif
812 else
813 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100814" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200815 call s:NetrwClearExplore()
816" call Dret("netrw#Explore : cleared list")
817 return
818 endif
819
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100820" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200821 if dirname =~ '\.\./\=$'
822 let dirname= simplify(fnamemodify(dirname,':p:h'))
823 elseif dirname =~ '\.\.' || dirname == '.'
824 let dirname= simplify(fnamemodify(dirname,':p'))
825 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100826" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200827
828 if dirname =~ '^\*//'
829 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100830" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200831 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
832 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100833" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200834 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
835
836 elseif dirname =~ '^\*\*//'
837 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100838" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200839 let pattern= substitute(dirname,'^\*\*//','','')
840 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100841" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200842
843 elseif dirname =~ '/\*\*/'
844 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100845" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200846 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
847 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
848 let b:netrw_curdir = prefixdir
849 else
850 let b:netrw_curdir= getcwd().'/'.prefixdir
851 endif
852 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
853 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100854" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
855" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200856
857 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200858 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200859 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100860" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200861
862 elseif dirname=~ '^\*\*/'
863 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
864 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100865" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200866
867 else
868 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100869" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200870 endif
871
872 if starpat == 0 && a:indx >= 0
873 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100874" 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 +0200875 if dirname == ""
876 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100877" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200878 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200879 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200880 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200881 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200882 if dirname == ""
883 let dirname= getcwd()
884 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100885 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100886 " depending on whether backslashes have been converted to forward slashes by earlier code).
887 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200888 let dirname= b:netrw_curdir."/".dirname
889 endif
890 elseif dirname !~ '^/'
891 let dirname= b:netrw_curdir."/".dirname
892 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100893" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200894 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100895" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
896" 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 +0200897 endif
898 if exists("w:netrw_bannercnt")
899 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
900 " If one wants to return the same place in the netrw window, use :Rex instead.
901 exe w:netrw_bannercnt
902 endif
903
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100904" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200905 " ---------------------------------------------------------------------
906 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
907" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100908" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200909" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100910" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200911" endif
912 " ---------------------------------------------------------------------
913
914 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
915 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
916 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
917 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
918 elseif a:indx <= 0
919 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100920" 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 +0200921 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100922" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200923 let s:didstarstar= 1
924 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
925 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
926 endif
927
928 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100929" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200930 if !exists("w:netrw_explore_indx")
931 let w:netrw_explore_indx= 0
932 endif
933
934 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100935" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200936
937 if indx == -1
938 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100939" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200940 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100941 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200942 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100943" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100944 if @* != keepregstar | sil! let @* = keepregstar | endif
945 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100946 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200947 sil! let @/ = keepregslash
948" call Dret("netrw#Explore")
949 return
950 endif
951 let indx= w:netrw_explore_indx
952 if indx < 0 | let indx= 0 | endif
953 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
954 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100955" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200956 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
957 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100958" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200959 endwhile
960 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100961" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200962
963 elseif indx == -2
964 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100965" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200966 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100967 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200968 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100969" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100970 if @* != keepregstar | sil! let @* = keepregstar | endif
971 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100972 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200973 sil! let @/ = keepregslash
974" call Dret("netrw#Explore")
975 return
976 endif
977 let indx= w:netrw_explore_indx
978 if indx < 0 | let indx= 0 | endif
979 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
980 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100981" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200982 while indx >= 0 && curfile == w:netrw_explore_list[indx]
983 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100984" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200985 endwhile
986 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100987" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200988
989 else
990 " Explore -- initialize
991 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100992" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100993 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200994 let w:netrw_explore_indx= 0
995 if !exists("b:netrw_curdir")
996 let b:netrw_curdir= getcwd()
997 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100998" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200999
1000 " switch on starpat to build the w:netrw_explore_list of files
1001 if starpat == 1
1002 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001003" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
1004" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001005 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001006 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001007 catch /^Vim\%((\a\+)\)\=:E480/
1008 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1009" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1010 return
1011 endtry
1012 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1013 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1014
1015 elseif starpat == 2
1016 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001017" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1018" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001019 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001020 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001021 catch /^Vim\%((\a\+)\)\=:E480/
1022 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1023 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001024 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001025" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001026 if @* != keepregstar | sil! let @* = keepregstar | endif
1027 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001028 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001029 sil! let @/ = keepregslash
1030" call Dret("netrw#Explore : no files matched pattern")
1031 return
1032 endtry
1033 let s:netrw_curdir = b:netrw_curdir
1034 let w:netrw_explore_list = getqflist()
1035 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1036 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1037
1038 elseif starpat == 3
1039 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001040" 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 +02001041 let filepat= substitute(dirname,'^\*/','','')
1042 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001043" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1044" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001045 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1046 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1047
1048 elseif starpat == 4
1049 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001050" 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 +02001051 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1052 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1053 endif " switch on starpat to build w:netrw_explore_list
1054
1055 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001056" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1057" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001058
1059 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001060 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001061 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001062" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001063 if @* != keepregstar | sil! let @* = keepregstar | endif
1064 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001065 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001066 sil! let @/ = keepregslash
1067" call Dret("netrw#Explore : no files matched")
1068 return
1069 endif
1070 endif " if indx ... endif
1071
1072 " NetrwStatusLine support - for exploring support
1073 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001074" 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 +02001075
1076 " wrap the indx around, but issue a note
1077 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001078" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001079 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1080 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001081 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001082 endif
1083
1084 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001085" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001086 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001087" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001088
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001089" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001090 call netrw#LocalBrowseCheck(newdir)
1091 if !exists("w:netrw_liststyle")
1092 let w:netrw_liststyle= g:netrw_liststyle
1093 endif
1094 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001095 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001096 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001097 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001098 endif
1099 let w:netrw_explore_mtchcnt = indx + 1
1100 let w:netrw_explore_bufnr = bufnr("%")
1101 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001102 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001103" 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 +02001104
1105 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001106" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001107 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001108 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 +02001109 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001110 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001111" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001112 if @* != keepregstar | sil! let @* = keepregstar | endif
1113 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001114 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001115 sil! let @/ = keepregslash
1116" call Dret("netrw#Explore : missing +path_extra")
1117 return
1118 endif
1119
1120 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001121" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001122 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1123 sil! unlet w:netrw_treedict
1124 sil! unlet w:netrw_treetop
1125 endif
1126 let newdir= dirname
1127 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001128 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001129 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001130 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001131 endif
1132 endif
1133
1134 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001135" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1136" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001137 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001138" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001139 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001140 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001141" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001142 let s:explore_prvdir = b:netrw_curdir
1143 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001144 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001145 if b:netrw_curdir !~ '/$'
1146 let dirlen= dirlen + 1
1147 endif
1148 let prvfname= ""
1149 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001150" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001151 if fname =~ '^'.b:netrw_curdir
1152 if s:explore_match == ""
1153 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1154 else
1155 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1156 endif
1157 elseif fname !~ '^/' && fname != prvfname
1158 if s:explore_match == ""
1159 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1160 else
1161 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1162 endif
1163 endif
1164 let prvfname= fname
1165 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001166" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001167 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1168 exe "2match netrwMarkFile /".s:explore_match."/"
1169 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001170 endif
1171 echo "<s-up>==Pexplore <s-down>==Nexplore"
1172 else
1173 2match none
1174 if exists("s:explore_match") | unlet s:explore_match | endif
1175 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001176" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001177 endif
1178
Bram Moolenaara6878372014-03-22 21:02:50 +01001179 " since Explore may be used to initialize netrw's browser,
1180 " there's no danger of a late FocusGained event on initialization.
1181 " Consequently, set s:netrw_events to 2.
1182 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001183 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001184" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001185 if @* != keepregstar | sil! let @* = keepregstar | endif
1186 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001187 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001188 sil! let @/ = keepregslash
1189" call Dret("netrw#Explore : @/<".@/.">")
1190endfun
1191
1192" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001193" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001194" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1195" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1196" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1197" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1198" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001199fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001200" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001201 let curwin= winnr()
1202
Bram Moolenaara6878372014-03-22 21:02:50 +01001203 if a:0 > 0 && a:1 != ""
1204 " if a netrw window is already on the left-side of the tab
1205 " and a directory has been specified, explore with that
1206 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001207" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001208 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001209" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001210 exe "1wincmd w"
1211 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001212" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001213 exe "Explore ".fnameescape(a1)
1214 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001215 let s:lexplore_win= curwin
1216 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001217 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001218" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001219 unlet t:netrw_lexposn
1220 endif
1221" call Dret("netrw#Lexplore")
1222 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001223 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001224 exe curwin."wincmd w"
1225 else
1226 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001227" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001228 endif
1229
Bram Moolenaar8d043172014-01-23 14:24:41 +01001230 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001231 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001232 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001233" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001234 else
1235 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001236" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001237 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001238" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001239
1240 if lexwinnr > 0
1241 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001242" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001243 exe lexwinnr."wincmd w"
1244 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001245 let t:netrw_lexposn = winsaveview()
1246" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001247" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001248 close
1249 if lexwinnr < curwin
1250 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001251 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001252 if lexwinnr != curwin
1253 exe curwin."wincmd w"
1254 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001255 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001256" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001257
1258 else
1259 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001260" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001261 exe "1wincmd w"
1262 let keep_altv = g:netrw_altv
1263 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001264 if a:count != 0
1265 let netrw_winsize = g:netrw_winsize
1266 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001267 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001268 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001269" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001270 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 +02001271" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001272 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001273" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001274 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001275 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001276 elseif curfile =~ '^\a\{3,}://'
1277" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001278 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001279 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001280" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001281 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001282 endif
1283 if a:count != 0
1284 let g:netrw_winsize = netrw_winsize
1285 endif
1286 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001287 let g:netrw_altv = keep_altv
1288 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001289 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1290 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001291 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001292 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001293" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1294" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001295 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001296" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001297" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1298 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001299 unlet t:netrw_lexposn
1300 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001301 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001302
1303 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001304 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001305 if a:rightside
1306 let g:netrw_chgwin= 1
1307 else
1308 let g:netrw_chgwin= 2
1309 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001310" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001311 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001312
Bram Moolenaar8d043172014-01-23 14:24:41 +01001313" call Dret("netrw#Lexplore")
1314endfun
1315
1316" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001317" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001318" supports :NetrwClean -- remove netrw from first directory on runtimepath
1319" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001320fun! netrw#Clean(sys)
1321" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001322
1323 if a:sys
1324 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1325 else
1326 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1327 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001328" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001329 let diddel= 0
1330 let diddir= ""
1331
1332 if choice == 1
1333 for dir in split(&rtp,',')
1334 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001335" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001336 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1337 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1338 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1339 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1340 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1341 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 +00001342 let diddir= dir
1343 let diddel= diddel + 1
1344 if !a:sys|break|endif
1345 endif
1346 endfor
1347 endif
1348
1349 echohl WarningMsg
1350 if diddel == 0
1351 echomsg "netrw is either not installed or not removable"
1352 elseif diddel == 1
1353 echomsg "removed one copy of netrw from <".diddir.">"
1354 else
1355 echomsg "removed ".diddel." copies of netrw"
1356 endif
1357 echohl None
1358
Bram Moolenaara6878372014-03-22 21:02:50 +01001359" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001360endfun
1361
Bram Moolenaar5c736222010-01-06 20:54:52 +01001362" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001363" netrw#MakeTgt: make a target out of the directory name provided {{{2
1364fun! netrw#MakeTgt(dname)
1365" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1366 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001367 let svpos = winsaveview()
1368" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001369 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1370" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001371 if s:netrwmftgt_islocal
1372 let netrwmftgt= simplify(a:dname)
1373 else
1374 let netrwmftgt= a:dname
1375 endif
1376 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1377 " re-selected target, so just clear it
1378 unlet s:netrwmftgt s:netrwmftgt_islocal
1379 else
1380 let s:netrwmftgt= netrwmftgt
1381 endif
1382 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001383 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001384 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001385" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1386 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001387" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001388endfun
1389
Bram Moolenaara6878372014-03-22 21:02:50 +01001390" ---------------------------------------------------------------------
1391" netrw#Obtain: {{{2
1392" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001393" islocal=0 obtain from remote source
1394" =1 obtain from local source
1395" fname : a filename or a list of filenames
1396" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001397fun! netrw#Obtain(islocal,fname,...)
1398" 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 +02001399 " NetrwStatusLine support - for obtaining support
1400
1401 if type(a:fname) == 1
1402 let fnamelist= [ a:fname ]
1403 elseif type(a:fname) == 3
1404 let fnamelist= a:fname
1405 else
1406 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 +01001407" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001408 return
1409 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001410" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001411 if a:0 > 0
1412 let tgtdir= a:1
1413 else
1414 let tgtdir= getcwd()
1415 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001416" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001417
1418 if exists("b:netrw_islocal") && b:netrw_islocal
1419 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001420" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001421 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1422 let topath= s:ComposePath(tgtdir,"")
1423 if (has("win32") || has("win95") || has("win64") || has("win16"))
1424 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001425" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001426 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001427" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001428 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001429 if v:shell_error != 0
1430 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 +01001431" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001432 return
1433 endif
1434 endfor
1435 else
1436 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001437" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1438 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1439" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001440 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001441 if v:shell_error != 0
1442 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 +01001443" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001444 return
1445 endif
1446 endif
1447 elseif !exists("b:netrw_curdir")
1448 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1449 else
1450 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1451 endif
1452
1453 else
1454 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001455" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001456 if type(a:fname) == 1
1457 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1458 endif
1459 call s:NetrwMethod(b:netrw_curdir)
1460
1461 if b:netrw_method == 4
1462 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001463" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001464 if exists("g:netrw_port") && g:netrw_port != ""
1465 let useport= " ".g:netrw_scpport." ".g:netrw_port
1466 else
1467 let useport= ""
1468 endif
1469 if b:netrw_fname =~ '/'
1470 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1471 else
1472 let path= ""
1473 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001474 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001475 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 +02001476
1477 elseif b:netrw_method == 2
1478 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001479" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001480 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001481 let tmpbufnr= bufnr("%")
1482 setl ff=unix
1483 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001484 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001485" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001486 endif
1487
1488 if exists("b:netrw_fname") && b:netrw_fname != ""
1489 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001490" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001491 endif
1492
1493 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001494 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001495" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001496 endif
1497 for fname in fnamelist
1498 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001499" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001500 endfor
1501 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001502 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 +02001503 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001504 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001505 endif
1506 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1507 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1508 let debugkeep= &debug
1509 setl debug=msg
1510 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1511 let &debug= debugkeep
1512 endif
1513
1514 elseif b:netrw_method == 3
1515 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001516" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001517 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001518 let tmpbufnr= bufnr("%")
1519 setl ff=unix
1520
1521 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001522 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001523" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001524 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001525 NetrwKeepj put ='open '.g:netrw_machine
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_uid") && g:netrw_uid != ""
1530 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001531 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001532" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001533 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001534 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001535 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001536" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001537 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001538 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001539" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001540 endif
1541 endif
1542
1543 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001544 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001545" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001546 endif
1547
1548 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001549 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001550" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001551 endif
1552
1553 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001554 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001555" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001556 endif
1557
1558 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001559 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001560" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001561 endif
1562 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001563 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001564 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001565" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001566
1567 " perform ftp:
1568 " -i : turns off interactive prompting from ftp
1569 " -n unix : DON'T use <.netrc>, even though it exists
1570 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001571 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1572 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001573 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001574 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1575 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001576" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001577 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001578 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001579 endif
1580 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001581
1582 elseif b:netrw_method == 9
1583 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001584" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001585 if a:fname =~ '/'
1586 let localfile= substitute(a:fname,'^.*/','','')
1587 else
1588 let localfile= a:fname
1589 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001590 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 +02001591
Bram Moolenaarff034192013-04-24 18:51:19 +02001592 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001593 " probably a badly formed url; protocol not recognized
1594" call Dret("netrw#Obtain : unsupported method")
1595 return
1596
1597 else
1598 " protocol recognized but not supported for Obtain (yet?)
1599 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001600 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001601 endif
1602" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001603 return
1604 endif
1605
1606 " restore status line
1607 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001608 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001609 endif
1610
1611 endif
1612
1613 " cleanup
1614 if exists("tmpbufnr")
1615 if bufnr("%") != tmpbufnr
1616 exe tmpbufnr."bw!"
1617 else
1618 q!
1619 endif
1620 endif
1621
Bram Moolenaara6878372014-03-22 21:02:50 +01001622" call Dret("netrw#Obtain")
1623endfun
1624
1625" ---------------------------------------------------------------------
1626" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1627fun! netrw#Nread(mode,fname)
1628" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001629 let svpos= winsaveview()
1630" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001631 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001632" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1633 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001634
1635 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1636 if exists("w:netrw_bannercnt")
1637 " start with cursor just after the banner
1638 exe w:netrw_bannercnt
1639 endif
1640 endif
1641" call Dret("netrw#Nread")
1642endfun
1643
1644" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001645" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1646" Options get restored by s:NetrwOptionsRestore()
1647"
1648" Option handling:
1649" * save user's options (s:NetrwOptionsSave)
1650" * set netrw-safe options (s:NetrwOptionsSafe)
1651" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1652" * restore user's options (s:netrwOPtionsRestore)
1653" - restore a user option when != safe option (s:NetrwRestoreSetting)
1654" vt: (variable type) normally its either "w:" or "s:"
1655fun! s:NetrwOptionsSave(vt)
1656" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1657" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001658" 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." hid=".&hid,'~'.expand("<slnum>"))
1659" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001660
1661 if !exists("{a:vt}netrw_optionsave")
1662 let {a:vt}netrw_optionsave= 1
1663 else
1664" call Dret("s:NetrwOptionsSave : options already saved")
1665 return
1666 endif
1667" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1668
1669 " Save current settings and current directory
1670" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1671 let s:yykeep = @@
1672 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1673 let {a:vt}netrw_aikeep = &l:ai
1674 let {a:vt}netrw_awkeep = &l:aw
1675 let {a:vt}netrw_bhkeep = &l:bh
1676 let {a:vt}netrw_blkeep = &l:bl
1677 let {a:vt}netrw_btkeep = &l:bt
1678 let {a:vt}netrw_bombkeep = &l:bomb
1679 let {a:vt}netrw_cedit = &cedit
1680 let {a:vt}netrw_cikeep = &l:ci
1681 let {a:vt}netrw_cinkeep = &l:cin
1682 let {a:vt}netrw_cinokeep = &l:cino
1683 let {a:vt}netrw_comkeep = &l:com
1684 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001685 let {a:vt}netrw_cuckeep = &l:cuc
1686 let {a:vt}netrw_culkeep = &l:cul
1687" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001688 let {a:vt}netrw_diffkeep = &l:diff
1689 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001690 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1691 let {a:vt}netrw_ffkeep = &l:ff
1692 endif
1693 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1694 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001695 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001696 let {a:vt}netrw_hidkeep = &l:hidden
1697 let {a:vt}netrw_imkeep = &l:im
1698 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001699 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001700 let {a:vt}netrw_lskeep = &l:ls
1701 let {a:vt}netrw_makeep = &l:ma
1702 let {a:vt}netrw_magickeep = &l:magic
1703 let {a:vt}netrw_modkeep = &l:mod
1704 let {a:vt}netrw_nukeep = &l:nu
1705 let {a:vt}netrw_rnukeep = &l:rnu
1706 let {a:vt}netrw_repkeep = &l:report
1707 let {a:vt}netrw_rokeep = &l:ro
1708 let {a:vt}netrw_selkeep = &l:sel
1709 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001710 if !g:netrw_use_noswf
1711 let {a:vt}netrw_swfkeep = &l:swf
1712 endif
1713 let {a:vt}netrw_tskeep = &l:ts
1714 let {a:vt}netrw_twkeep = &l:tw " textwidth
1715 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1716 let {a:vt}netrw_wrapkeep = &l:wrap
1717 let {a:vt}netrw_writekeep = &l:write
1718
1719 " save a few selected netrw-related variables
1720" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1721 if g:netrw_keepdir
1722 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001723" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001724 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001725 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001726 sil! let {a:vt}netrw_starkeep = @*
1727 sil! let {a:vt}netrw_pluskeep = @+
1728 endif
1729 sil! let {a:vt}netrw_slashkeep= @/
1730
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001731" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001732" 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>"))
1733" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1734endfun
1735
1736" ---------------------------------------------------------------------
1737" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1738" Use s:NetrwSaveOptions() to save user settings
1739" Use s:NetrwOptionsRestore() to restore user settings
1740fun! s:NetrwOptionsSafe(islocal)
1741" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1742" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1743" 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>"))
1744 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1745 call s:NetrwSetSafeSetting("&l:ai",0)
1746 call s:NetrwSetSafeSetting("&l:aw",0)
1747 call s:NetrwSetSafeSetting("&l:bl",0)
1748 call s:NetrwSetSafeSetting("&l:bomb",0)
1749 if a:islocal
1750 call s:NetrwSetSafeSetting("&l:bt","nofile")
1751 else
1752 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1753 endif
1754 call s:NetrwSetSafeSetting("&l:ci",0)
1755 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001756 if g:netrw_fastbrowse > a:islocal
1757 call s:NetrwSetSafeSetting("&l:bh","hide")
1758 else
1759 call s:NetrwSetSafeSetting("&l:bh","delete")
1760 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001761 call s:NetrwSetSafeSetting("&l:cino","")
1762 call s:NetrwSetSafeSetting("&l:com","")
1763 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1764 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1765 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001766 if &go =~ 'a' | set go-=a | endif
1767 if &go =~ 'A' | set go-=A | endif
1768 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001769 call s:NetrwSetSafeSetting("&l:hid",0)
1770 call s:NetrwSetSafeSetting("&l:im",0)
1771 setl isk+=@ isk+=* isk+=/
1772 call s:NetrwSetSafeSetting("&l:magic",1)
1773 if g:netrw_use_noswf
1774 call s:NetrwSetSafeSetting("swf",0)
1775 endif
1776 call s:NetrwSetSafeSetting("&l:report",10000)
1777 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1778 call s:NetrwSetSafeSetting("&l:spell",0)
1779 call s:NetrwSetSafeSetting("&l:tw",0)
1780 call s:NetrwSetSafeSetting("&l:wig","")
1781 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001782
1783 " set up cuc and cul based on g:netrw_cursor and listing style
1784 " COMBAK -- cuc cul related
1785 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001786
1787 " allow the user to override safe options
1788" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1789 if &ft == "netrw"
1790" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1791 keepalt NetrwKeepj doau FileType netrw
1792 endif
1793
1794" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1795" 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>"))
1796" call Dret("s:NetrwOptionsSafe")
1797endfun
1798
1799" ---------------------------------------------------------------------
1800" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1801fun! s:NetrwOptionsRestore(vt)
1802" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001803" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001804" 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 +01001805 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001806" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001807
1808 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1809 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001810" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001811 filetype detect
1812" 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>"))
1813 else
1814 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001815 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001816" 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 +02001817" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001818 return
1819 endif
1820 unlet {a:vt}netrw_optionsave
1821
1822 if exists("+acd")
1823 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001824" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001825 let curdir = getcwd()
1826 let &l:acd = {a:vt}netrw_acdkeep
1827 unlet {a:vt}netrw_acdkeep
1828 if &l:acd
1829 call s:NetrwLcd(curdir)
1830 endif
1831 endif
1832 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001833" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001834 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1835 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1836 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1837 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1838 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001839" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001840 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1841 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1842 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1843 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1844 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001845" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001846 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1847 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1848 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1849 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1850 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001851 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001852" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1853 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1854 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001855 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001856 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1857" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1858 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1859 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1860" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1861 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1862" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1863 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1864 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001865 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001866 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1867 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1868" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1869 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1870 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1871 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1872 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1873" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001874 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001875 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1876 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1877 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001878 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001879" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001880 call s:NetrwRestoreSetting("s:yykeep","@@")
1881 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1882 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1883 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1884 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1885
Bram Moolenaara6878372014-03-22 21:02:50 +01001886 if exists("{a:vt}netrw_swfkeep")
1887 if &directory == ""
1888 " user hasn't specified a swapfile directory;
1889 " netrw will temporarily set the swapfile directory
1890 " to the current directory as returned by getcwd().
1891 let &l:directory= getcwd()
1892 sil! let &l:swf = {a:vt}netrw_swfkeep
1893 setl directory=
1894 unlet {a:vt}netrw_swfkeep
1895 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001896 if !g:netrw_use_noswf
1897 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1898 sil! let &l:swf= {a:vt}netrw_swfkeep
1899 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001900 unlet {a:vt}netrw_swfkeep
1901 endif
1902 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001903 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001904 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1905 if exists("{a:vt}netrw_dirkeep")
1906 call s:NetrwLcd(dirkeep)
1907 unlet {a:vt}netrw_dirkeep
1908 endif
1909 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001910 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001911" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001912 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1913 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001914 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001915 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001916
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001917" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1918" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1919" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1920" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1921" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001922 " Moved the filetype detect here from NetrwGetFile() because remote files
1923 " were having their filetype detect-generated settings overwritten by
1924 " NetrwOptionRestore.
1925 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001926" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1927 filetype detect
1928" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001929 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001930" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001931" 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 +02001932" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001933endfun
1934
1935" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001936" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1937" but only when the options' value and the safe setting differ
1938" Doing this means that netrw will not come up as having changed a
1939" setting last when it really didn't actually change it.
1940"
1941" Called from s:NetrwOptionsSafe
1942" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1943fun! s:NetrwSetSafeSetting(setting,safesetting)
1944" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001945
Bram Moolenaar85850f32019-07-19 22:05:51 +02001946 if a:setting =~ '^&'
1947" call Decho("fyi: a:setting starts with &")
1948 exe "let settingval= ".a:setting
1949" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001950
Bram Moolenaar85850f32019-07-19 22:05:51 +02001951 if settingval != a:safesetting
1952" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1953 if type(a:safesetting) == 0
1954 exe "let ".a:setting."=".a:safesetting
1955 elseif type(a:safesetting) == 1
1956 exe "let ".a:setting."= '".a:safesetting."'"
1957 else
1958 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1959 endif
1960 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001961 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001962
Bram Moolenaar85850f32019-07-19 22:05:51 +02001963" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001964endfun
1965
1966" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001967" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1968" but only if the setting value differs from the associated keepvar.
1969" Doing this means that netrw will not come up as having changed a
1970" setting last when it really didn't actually change it.
1971"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001972" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001973" keepvars are set up by s:NetrwOptionsSave
1974fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001975""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001976
Bram Moolenaar85850f32019-07-19 22:05:51 +02001977 " typically called from s:NetrwOptionsRestore
1978 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1979 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001980 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001981 if exists(a:keepvar)
1982 exe "let keepvarval= ".a:keepvar
1983 exe "let setting= ".a:setting
1984
1985"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1986"" call Decho("fyi: keepvarval=".keepvarval)
1987"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1988
1989 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001990"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001991 if type(a:setting) == 0
1992 exe "let ".a:setting."= ".keepvarval
1993 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001994 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001995 else
1996 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1997 endif
1998 endif
1999
2000 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01002001 endif
2002
Bram Moolenaar85850f32019-07-19 22:05:51 +02002003"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02002004endfun
2005
2006" ---------------------------------------------------------------------
2007" NetrwStatusLine: {{{2
2008fun! NetrwStatusLine()
2009
2010" vvv NetrwStatusLine() debugging vvv
2011" let g:stlmsg=""
2012" if !exists("w:netrw_explore_bufnr")
2013" let g:stlmsg="!X<explore_bufnr>"
2014" elseif w:netrw_explore_bufnr != bufnr("%")
2015" let g:stlmsg="explore_bufnr!=".bufnr("%")
2016" endif
2017" if !exists("w:netrw_explore_line")
2018" let g:stlmsg=" !X<explore_line>"
2019" elseif w:netrw_explore_line != line(".")
2020" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2021" endif
2022" if !exists("w:netrw_explore_list")
2023" let g:stlmsg=" !X<explore_list>"
2024" endif
2025" ^^^ NetrwStatusLine() debugging ^^^
2026
2027 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")
2028 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002029 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002030 let &laststatus = s:netrw_users_ls
2031 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2032 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2033 return ""
2034 else
2035 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2036 endif
2037endfun
2038
Bram Moolenaar85850f32019-07-19 22:05:51 +02002039" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002040" Netrw Transfer Functions: {{{1
2041" ===============================
2042
Bram Moolenaar071d4272004-06-13 20:20:40 +00002043" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002044" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002045" mode: =0 read remote file and insert before current line
2046" =1 read remote file and insert after current line
2047" =2 replace with remote file
2048" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002049fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002050" 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 +00002051
Bram Moolenaar5c736222010-01-06 20:54:52 +01002052 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002053 call s:NetrwOptionsSave("w:")
2054 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002055 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002056 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2057 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2058 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002059" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002060
Bram Moolenaar5c736222010-01-06 20:54:52 +01002061 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002062 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002063 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002064 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002065 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002066 elseif a:mode == 2 " replace with remote file
2067 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002068 elseif a:mode == 3 " skip read of file (leave as temporary)
2069 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002070 else
2071 exe a:mode
2072 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002073 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002074 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002075" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002076
Bram Moolenaar5c736222010-01-06 20:54:52 +01002077 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002078 let tmpfile= s:GetTempfile("")
2079 if tmpfile == ""
2080" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002081 return
2082 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002083
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002084 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002085
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002086 " attempt to repeat with previous host-file-etc
2087 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002088" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002089 let choice = b:netrw_lastfile
2090 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002091
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002092 else
2093 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002094" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002095
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002096 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002097 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002098 echomsg 'NetRead Usage:'
2099 echomsg ':Nread machine:path uses rcp'
2100 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2101 echomsg ':Nread "machine id password path" uses ftp'
2102 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2103 echomsg ':Nread fetch://machine/path uses fetch'
2104 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2105 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002106 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002107 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002108 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2109 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2110 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2111 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002112 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002113 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002114
Bram Moolenaar9964e462007-05-05 17:54:07 +00002115 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002116 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002117" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002118 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002119 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002120 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002121 else
2122 " case "... ... ..."
2123 let choice = strpart(choice,1,strlen(choice)-1)
2124 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002125
Bram Moolenaar9964e462007-05-05 17:54:07 +00002126 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002127 let wholechoice = wholechoice . " " . choice
2128 let ichoice = ichoice + 1
2129 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002130 if !exists("g:netrw_quiet")
2131 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2132 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002133" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002134 return
2135 endif
2136 let choice= a:{ichoice}
2137 endwhile
2138 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2139 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140 endif
2141 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002142
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002143" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002144 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002145
Bram Moolenaar5c736222010-01-06 20:54:52 +01002146 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002147 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002148 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002149" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002150 return
2151 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002152 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002153
Bram Moolenaar8d043172014-01-23 14:24:41 +01002154 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002155" 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 +02002156 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002157" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002158 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002159" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002160 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002162
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002163 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002164 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002165 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002166 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2167 echo "(netrw) Processing your read request..."
2168 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002169
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002170 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002171 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002172 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002173" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002174 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002175 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002176 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002177 " ER: the tmpfile is full path: rcp sees C:\... as host C
2178 if s:netrw_has_nt_rcp == 1
2179 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2180 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2181 else
2182 " Any way needed it machine contains a '.'
2183 let uid_machine = g:netrw_machine .'.'. $USERNAME
2184 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002185 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002186 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2187 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2188 else
2189 let uid_machine = g:netrw_machine
2190 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002192 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 +00002193 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002194 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002195
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002196 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002197 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002198 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002199" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002200 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002201 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002202 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002203 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002204 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002206 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002207 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002208" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002209 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002210 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002211" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002212 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002213 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 +00002214 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002215 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002216 endif
2217 " 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 +00002218 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002219 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002220 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002221 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002222 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002223 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002224 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002225 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002226 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2227 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002228 q!
2229 endif
2230 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002231 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002232 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002233
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002235 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002236 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2237 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002238" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002239 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002240 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002241 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002242 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002243 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002244 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002245" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002246 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002247 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002248" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002249 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002250
Bram Moolenaar97d62492012-11-15 21:28:22 +01002251 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002252 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002253 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002255 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002256 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002257 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002258" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002259 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002260 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002261" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002262 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002263 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002264
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002265 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002266 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002267" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002268 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002269 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002270 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002271" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002272 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002273 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002274" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002275
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002276 " perform ftp:
2277 " -i : turns off interactive prompting from ftp
2278 " -n unix : DON'T use <.netrc>, even though it exists
2279 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002280 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002281 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2283 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002284" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002285 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002286 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002287 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002288 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002289 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002290 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002291 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002292
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002293 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002294 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002295 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002296" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002297 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002298 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002299 else
2300 let useport= ""
2301 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002302 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2303 " This is workaround to avoid mis-handle windows local-path:
2304 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2305 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2306 else
2307 let tmpfile_get = tmpfile
2308 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002309 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 +00002310 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002311 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002312
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002313 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002314 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002315 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002316" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002317 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002318 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002319 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002320 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002321" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002322 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002323 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002324
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002325 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2326 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002327" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002328 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002329 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 +00002330 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002331 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 +00002332 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002333 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002334
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002335 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002336 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002337" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002338 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2339 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002340" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2341" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2342 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 +00002343 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002344" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002345 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002346 endif
2347 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002348" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002349 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002350
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002351 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002352 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002353 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002354" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002355
Bram Moolenaar5c736222010-01-06 20:54:52 +01002356 if !executable(g:netrw_dav_cmd)
2357 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2358" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2359 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002360 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002361 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002362 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 +01002363 else
2364 " Construct execution string (four lines) which will be passed through filter
2365 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2366 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002367 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002368 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002369 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002370 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002371 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002372 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002373 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002374 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002375 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002376 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2377 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002378
Bram Moolenaar5c736222010-01-06 20:54:52 +01002379 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002380 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002381 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002382 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002383 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002384 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002385 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002386
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002388 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002389 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002390" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002391 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 +00002392 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002394
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002395 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002396 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002397 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002398 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002399" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002400 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002401 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002402 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002403 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002404" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002405 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002406 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002407 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002408 let netrw_option= "http"
2409 else
2410 let netrw_option= "ftp"
2411 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002412" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002413
Bram Moolenaar446cb832008-06-24 21:56:24 +00002414 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002415 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 +00002416 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002417 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 +00002418 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002419
Bram Moolenaar446cb832008-06-24 21:56:24 +00002420 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002421 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002422" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002423 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002424
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002425 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002426 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002427 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002428" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2429 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 +00002430 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002431 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002432
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002433 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002434 " NetRead: (file) NetRead Method #10 {{{3
2435 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002436" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2437 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002438 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2439 let b:netrw_lastfile = choice
2440
2441 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002442 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002443 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002444 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002445 endif
2446 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002447
Bram Moolenaar5c736222010-01-06 20:54:52 +01002448 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002449 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002450" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002451 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002452 unlet b:netrw_fname
2453 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002454 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 +01002455" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002456 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002457 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002458 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002459
Bram Moolenaar9964e462007-05-05 17:54:07 +00002460" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002461endfun
2462
2463" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002464" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002465fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002466" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002467
Bram Moolenaar5c736222010-01-06 20:54:52 +01002468 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002469 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002470 call s:NetrwOptionsSave("w:")
2471 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002472
Bram Moolenaar5c736222010-01-06 20:54:52 +01002473 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002474 let tmpfile= s:GetTempfile("")
2475 if tmpfile == ""
2476" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002477 return
2478 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002479
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002480 if a:0 == 0
2481 let ichoice = 0
2482 else
2483 let ichoice = 1
2484 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002485
Bram Moolenaar9964e462007-05-05 17:54:07 +00002486 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002487" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002488 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002489 " For binary writes, always write entire file.
2490 " (line numbers don't really make sense for that).
2491 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002492" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002493 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002494 elseif g:netrw_cygwin
2495 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002496 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002497" 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 +01002498 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002499 else
2500 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002501" 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 +01002502 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002503 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002504
Bram Moolenaar9964e462007-05-05 17:54:07 +00002505 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002506 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002507 " on the temporary file's name. Deletion of the temporary file during
2508 " cleanup then causes an error message.
2509 0file!
2510 endif
2511
Bram Moolenaar5c736222010-01-06 20:54:52 +01002512 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002513 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002514
Bram Moolenaar9964e462007-05-05 17:54:07 +00002515 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002516 " attempt to repeat with previous host-file-etc
2517 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002518" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002519 let choice = b:netrw_lastfile
2520 let ichoice= ichoice + 1
2521 else
2522 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002523
Bram Moolenaar8d043172014-01-23 14:24:41 +01002524 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002525 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002526 echomsg 'NetWrite Usage:"'
2527 echomsg ':Nwrite machine:path uses rcp'
2528 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2529 echomsg ':Nwrite "machine id password path" uses ftp'
2530 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2531 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2532 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2533 echomsg ':Nwrite rcp://machine/path uses rcp'
2534 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2535 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2536 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002537 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002538 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002539
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002540 elseif match(choice,"^\"") != -1
2541 if match(choice,"\"$") != -1
2542 " case "..."
2543 let choice=strpart(choice,1,strlen(choice)-2)
2544 else
2545 " case "... ... ..."
2546 let choice = strpart(choice,1,strlen(choice)-1)
2547 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002548
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002549 while match(choice,"\"$") == -1
2550 let wholechoice= wholechoice . " " . choice
2551 let ichoice = ichoice + 1
2552 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002553 if !exists("g:netrw_quiet")
2554 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2555 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002556" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002557 return
2558 endif
2559 let choice= a:{ichoice}
2560 endwhile
2561 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2562 endif
2563 endif
2564 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002565 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002566" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002567
Bram Moolenaar9964e462007-05-05 17:54:07 +00002568 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002569 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002570 if !exists("b:netrw_method") || b:netrw_method < 0
2571" call Dfunc("netrw#NetWrite : unsupported method")
2572 return
2573 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002574
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002575 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002576 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002577 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002578 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2579 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002580" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002581 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002582
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002583 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002584 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002585 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002586" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002587 if s:netrw_has_nt_rcp == 1
2588 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2589 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2590 else
2591 let uid_machine = g:netrw_machine .'.'. $USERNAME
2592 endif
2593 else
2594 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2595 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2596 else
2597 let uid_machine = g:netrw_machine
2598 endif
2599 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002600 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 +00002601 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002602
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002603 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002604 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002605 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002607 let netrw_fname = b:netrw_fname
2608
2609 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2610 let bhkeep = &l:bh
2611 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002612 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002613 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002614
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002615" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002616 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002617 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002618" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002619 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002620 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002621" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002622 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002623 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002624" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002626 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 +00002627 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002628" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2629 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 endif
2631 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2632 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002633 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002634 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002635 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002636 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002638
2639 " remove enew buffer (quietly)
2640 let filtbuf= bufnr("%")
2641 exe curbuf."b!"
2642 let &l:bh = bhkeep
2643 exe filtbuf."bw!"
2644
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002646
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002647 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002648 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002649 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002650 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002651" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002652 let netrw_fname = b:netrw_fname
2653 let bhkeep = &l:bh
2654
2655 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2656 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002657 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002658 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002659 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002660
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002661 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002662 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002663" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002664 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002665 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002666" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002667 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002668 if exists("g:netrw_uid") && g:netrw_uid != ""
2669 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002670 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002671" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002672 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002673 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002674 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002675" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002676 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002677 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002678" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002679 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002680 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002681 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002682" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002683 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002684 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002685" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002686 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002687 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002688" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002689 " save choice/id/password for future use
2690 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002691
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002692 " perform ftp:
2693 " -i : turns off interactive prompting from ftp
2694 " -n unix : DON'T use <.netrc>, even though it exists
2695 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002696 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002697 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002698 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2699 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002700 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002701 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002702 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002703 let mod=1
2704 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002705
2706 " remove enew buffer (quietly)
2707 let filtbuf= bufnr("%")
2708 exe curbuf."b!"
2709 let &l:bh= bhkeep
2710 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002711
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002712 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002713 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002714 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002715" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002716 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002717 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002718 else
2719 let useport= ""
2720 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002721 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 +00002722 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002723
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002724 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002725 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002726 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002727" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002728 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2729 if executable(curl)
2730 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002731 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 +01002732 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002733 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002734 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002735
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002736 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002737 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002738 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002739" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002740
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002741 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002742 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2743 let bhkeep = &l:bh
2744
2745 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2746 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002747 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002748 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002749
Bram Moolenaarff034192013-04-24 18:51:19 +02002750 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002751 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002752 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002753 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002754 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002755 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002756 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002757 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002758 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002759 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002760
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002761 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002762 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002763 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002764
2765 " remove enew buffer (quietly)
2766 let filtbuf= bufnr("%")
2767 exe curbuf."b!"
2768 let &l:bh = bhkeep
2769 exe filtbuf."bw!"
2770
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002771 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002772
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002773 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002774 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002775 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002776" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002777 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 +00002778 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002779
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002780 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002781 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002782 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002783" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002784 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002785 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2786 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2787 else
2788 let uid_machine = g:netrw_machine
2789 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002790
2791 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2792 let bhkeep = &l:bh
2793 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002794 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002795 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002796
Bram Moolenaarff034192013-04-24 18:51:19 +02002797 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002798 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002799" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002800 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002801 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002802 let filtbuf= bufnr("%")
2803 exe curbuf."b!"
2804 let &l:bh = bhkeep
2805 exe filtbuf."bw!"
2806 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002807
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002808 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002809 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002810 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002811 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002812 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002814 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002815
Bram Moolenaar5c736222010-01-06 20:54:52 +01002816 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002817" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002818 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002819" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002820 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002821 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002822 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002823
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002824 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002825 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002826 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002827" 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 +02002828 elseif !exists("leavemod")
2829 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002830" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002831 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002832" 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 +00002833 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002834
Bram Moolenaar9964e462007-05-05 17:54:07 +00002835" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002836endfun
2837
2838" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002839" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002840" uses NetRead to get a copy of the file into a temporarily file,
2841" then sources that file,
2842" then removes that file.
2843fun! netrw#NetSource(...)
2844" call Dfunc("netrw#NetSource() a:0=".a:0)
2845 if a:0 > 0 && a:1 == '?'
2846 " give help
2847 echomsg 'NetSource Usage:'
2848 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2849 echomsg ':Nsource fetch://machine/path uses fetch'
2850 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002851 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002852 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2853 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2854 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2855 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2856 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002857 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002858 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002859 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002860 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002861" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002862 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002863" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002864 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002865" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002866 if delete(s:netrw_tmpfile)
2867 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2868 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002869 unlet s:netrw_tmpfile
2870 else
2871 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2872 endif
2873 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002874 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002875 endif
2876" call Dret("netrw#NetSource")
2877endfun
2878
Bram Moolenaar8d043172014-01-23 14:24:41 +01002879" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002880" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2881" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002882fun! netrw#SetTreetop(iscmd,...)
2883" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2884" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002885
Bram Moolenaar85850f32019-07-19 22:05:51 +02002886 " iscmd==0: netrw#SetTreetop called using gn mapping
2887 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2888" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002889 " clear out the current tree
2890 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002891" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002892 let inittreetop= w:netrw_treetop
2893 unlet w:netrw_treetop
2894 endif
2895 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002896" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002897 unlet w:netrw_treedict
2898 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002899" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002900
Bram Moolenaar85850f32019-07-19 22:05:51 +02002901 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002902 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002903" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002904 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002905 if isdirectory(s:NetrwFile(a:1))
2906" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002907 let treedir = a:1
2908 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002909 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002910 let treedir = b:netrw_curdir."/".a:1
2911 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002912" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002913 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002914 " normally the cursor is left in the message window.
2915 " However, here this results in the directory being listed in the message window, which is not wanted.
2916 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002917 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002918 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002919 let treedir = "."
2920 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002921 endif
2922 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002923" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002924
2925 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002926 let islocal= expand("%") !~ '^\a\{3,}://'
2927" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002928
2929 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002930 if islocal
2931 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2932 else
2933 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2934 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002935
Bram Moolenaara6878372014-03-22 21:02:50 +01002936" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002937endfun
2938
Bram Moolenaar9964e462007-05-05 17:54:07 +00002939" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002940" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002941" readcmd == %r : replace buffer with newly read file
2942" == 0r : read file at top of buffer
2943" == r : read file after current line
2944" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002945fun! s:NetrwGetFile(readcmd, tfile, method)
2946" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002947
2948 " readcmd=='t': simply do nothing
2949 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002950" 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 +01002951" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002952 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002953 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002954
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955 " get name of remote filename (ie. url and all)
2956 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002957" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002958
Bram Moolenaar9964e462007-05-05 17:54:07 +00002959 if exists("*NetReadFixup")
2960 " for the use of NetReadFixup (not otherwise used internally)
2961 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002962 endif
2963
Bram Moolenaar9964e462007-05-05 17:54:07 +00002964 if a:readcmd[0] == '%'
2965 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002966" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002967
2968 " rename the current buffer to the temp file (ie. tfile)
2969 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002970 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002971 else
2972 let tfile= a:tfile
2973 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002974 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002975
2976 " edit temporary file (ie. read the temporary file in)
2977 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002978" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002979 call zip#Browse(tfile)
2980 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002981" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002982 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002983 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002984" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002985 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002986 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002987" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002988 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002989 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002990" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002991 call tar#Browse(tfile)
2992 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002993" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002994 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002995 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002996" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002997 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002998 endif
2999
3000 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02003001 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003002
Bram Moolenaar71badf92023-04-22 22:40:14 +01003003 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01003004 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003005 " Note that isk must not include a "/" for scripts.vim
3006 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01003007" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
3008" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003009" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003010" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3011 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003012 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003013 filetype detect
3014" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003015 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003016" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003017 let line1 = 1
3018 let line2 = line("$")
3019
Bram Moolenaar8d043172014-01-23 14:24:41 +01003020 elseif !&ma
3021 " 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 +01003022 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003023" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003024 return
3025
Bram Moolenaar9964e462007-05-05 17:54:07 +00003026 elseif s:FileReadable(a:tfile)
3027 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003028" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003029 let curline = line(".")
3030 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003031" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003032 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003033 let line1= curline + 1
3034 let line2= line("$") - lastline + 1
3035
3036 else
3037 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003038" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3039" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003040 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003041" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003042 return
3043 endif
3044
3045 " User-provided (ie. optional) fix-it-up command
3046 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003047" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003048 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003049" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003050" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003051 endif
3052
Bram Moolenaaradc21822011-04-01 18:03:16 +02003053 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003054 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003055 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003056 endif
3057
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003058" 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 +00003059
3060 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003061" redraw!
3062
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003063" 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 +00003064" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003065endfun
3066
Bram Moolenaar9964e462007-05-05 17:54:07 +00003067" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003068" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003069" Input:
3070" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3071" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003072" b:netrw_method= 1: rcp
3073" 2: ftp + <.netrc>
3074" 3: ftp + machine, id, password, and [path]filename
3075" 4: scp
3076" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003077" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003078" 7: rsync
3079" 8: fetch
3080" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003081" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003082" g:netrw_machine= hostname
3083" b:netrw_fname = filename
3084" g:netrw_port = optional port number (for ftp)
3085" g:netrw_choice = copy of input url (choice)
3086fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003087" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003088
Bram Moolenaar251e1912011-06-19 05:09:16 +02003089 " sanity check: choice should have at least three slashes in it
3090 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3091 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3092 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003093" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003094 return
3095 endif
3096
Bram Moolenaar5c736222010-01-06 20:54:52 +01003097 " record current g:netrw_machine, if any
3098 " curmachine used if protocol == ftp and no .netrc
3099 if exists("g:netrw_machine")
3100 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003101" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003102 else
3103 let curmachine= "N O T A HOST"
3104 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003105 if exists("g:netrw_port")
3106 let netrw_port= g:netrw_port
3107 endif
3108
3109 " insure that netrw_ftp_cmd starts off every method determination
3110 " with the current g:netrw_ftp_cmd
3111 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003112
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003113 " initialization
3114 let b:netrw_method = 0
3115 let g:netrw_machine = ""
3116 let b:netrw_fname = ""
3117 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003118 let g:netrw_choice = a:choice
3119
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003120 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003121 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003122 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3123 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003124 " rcpurm : rcp://[user@]host/filename Use rcp
3125 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003127 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003128 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003129 " rsyncurm : rsync://host[:port]/path Use rsync
3130 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3131 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003132 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003133 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3134 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003135 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3136 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003137 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003138 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003139 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003140 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003141 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003142 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003143 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003144 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003145
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003146" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003147 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003148 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003149 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003150" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003151 let b:netrw_method = 1
3152 let userid = substitute(a:choice,rcpurm,'\1',"")
3153 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3154 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003155 if userid != ""
3156 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003158
Bram Moolenaaradc21822011-04-01 18:03:16 +02003159 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003160 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003161" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003162 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003163 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3164 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3165 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003166
Bram Moolenaar15146672011-10-20 22:22:38 +02003167 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003168 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003169" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003170 let b:netrw_method = 5
3171 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3172 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003173 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003174
Bram Moolenaaradc21822011-04-01 18:03:16 +02003175 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003176 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003177" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003178 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003179 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003180 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3181 else
3182 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3183 endif
3184 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003185
Bram Moolenaaradc21822011-04-01 18:03:16 +02003186 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003187 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003188" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003189 let b:netrw_method = 7
3190 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3191 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003192
Bram Moolenaaradc21822011-04-01 18:03:16 +02003193 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003194 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003195" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003196 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003197 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3198 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3199 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003200" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003201 if userid != ""
3202 let g:netrw_uid= userid
3203 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003204
Bram Moolenaaradc21822011-04-01 18:03:16 +02003205 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003206 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003207 call NetUserPass("ftp:".g:netrw_machine)
3208 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003209 " if there's a change in hostname, require password re-entry
3210 unlet s:netrw_passwd
3211 endif
3212 if exists("netrw_port")
3213 unlet netrw_port
3214 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003215 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003216
Bram Moolenaar446cb832008-06-24 21:56:24 +00003217 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003218 let b:netrw_method = 3
3219 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003220 let host= substitute(g:netrw_machine,'\..*$','','')
3221 if exists("s:netrw_hup[host]")
3222 call NetUserPass("ftp:".host)
3223
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003224 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003225" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3226" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003227 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003228 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003229" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003230 endif
3231 let b:netrw_method= 2
3232 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003233" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003234 let b:netrw_method= 2
3235 else
3236 if !exists("g:netrw_uid") || g:netrw_uid == ""
3237 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003238 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003239 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003240 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003241 endif
3242 let b:netrw_method= 3
3243 endif
3244 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003245
Bram Moolenaaradc21822011-04-01 18:03:16 +02003246 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003247 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003248" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003249 let b:netrw_method = 8
3250 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3251 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3252 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3253 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003254
Bram Moolenaaradc21822011-04-01 18:03:16 +02003255 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003256 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003257" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003259 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3260 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003261 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003262 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003263 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003264
Bram Moolenaaradc21822011-04-01 18:03:16 +02003265 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003266 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003267" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003268 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003269 let b:netrw_method = 3
3270 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3271 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003272
Bram Moolenaar9964e462007-05-05 17:54:07 +00003273 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003274 let b:netrw_method = 2
3275 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3276 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3277 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003278
Bram Moolenaaradc21822011-04-01 18:03:16 +02003279 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003280 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003281" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003282 let b:netrw_method = 9
3283 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3284 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003285
Bram Moolenaaradc21822011-04-01 18:03:16 +02003286 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003287 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003288" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003289 let b:netrw_method = 1
3290 let userid = substitute(a:choice,rcphf,'\2',"")
3291 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3292 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003293" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3294" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3295" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3296" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003297 if userid != ""
3298 let g:netrw_uid= userid
3299 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003300
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003301 " Method#10: file://user@hostname/...path-to-file {{{3
3302 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003303" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003304 let b:netrw_method = 10
3305 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003306" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003307
Bram Moolenaaradc21822011-04-01 18:03:16 +02003308 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003309 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003310 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003311 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003312 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003313 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003315 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003316
Bram Moolenaar81695252004-12-29 20:58:21 +00003317 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003318 " remove any leading [:#] from port number
3319 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3320 elseif exists("netrw_port")
3321 " retain port number as implicit for subsequent ftp operations
3322 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003323 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003324
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003325" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3326" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3327" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3328" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003329" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003330" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003331" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003332" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003333" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003334" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003335" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003336" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338
3339" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003340" NetReadFixup: this sort of function is typically written by the user {{{2
3341" to handle extra junk that their system's ftp dumps
3342" into the transfer. This function is provided as an
3343" example and as a fix for a Windows 95 problem: in my
3344" experience, win95's ftp always dumped four blank lines
3345" at the end of the transfer.
3346if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3347 fun! NetReadFixup(method, line1, line2)
3348" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003349
3350 " sanity checks -- attempt to convert inputs to integers
3351 let method = a:method + 0
3352 let line1 = a:line1 + 0
3353 let line2 = a:line2 + 0
3354 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3355" call Dret("NetReadFixup")
3356 return
3357 endif
3358
Bram Moolenaar9964e462007-05-05 17:54:07 +00003359 if method == 3 " ftp (no <.netrc>)
3360 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003361 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003362 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003363 call histdel("/",-1)
3364 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003365 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003366
Bram Moolenaar9964e462007-05-05 17:54:07 +00003367" call Dret("NetReadFixup")
3368 endfun
3369endif
3370
3371" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003372" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003373" Usage: :call NetUserPass() -- will prompt for userid and password
3374" :call NetUserPass("uid") -- will prompt for password
3375" :call NetUserPass("uid","password") -- sets global userid and password
3376" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3377" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378fun! NetUserPass(...)
3379
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003380" call Dfunc("NetUserPass() a:0=".a:0)
3381
3382 if !exists('s:netrw_hup')
3383 let s:netrw_hup= {}
3384 endif
3385
Bram Moolenaar071d4272004-06-13 20:20:40 +00003386 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003387 " case: no input arguments
3388
3389 " change host and username if not previously entered; get new password
3390 if !exists("g:netrw_machine")
3391 let g:netrw_machine= input('Enter hostname: ')
3392 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003394 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395 let g:netrw_uid= input('Enter username: ')
3396 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003397 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003398 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003399
3400 " set up hup database
3401 let host = substitute(g:netrw_machine,'\..*$','','')
3402 if !exists('s:netrw_hup[host]')
3403 let s:netrw_hup[host]= {}
3404 endif
3405 let s:netrw_hup[host].uid = g:netrw_uid
3406 let s:netrw_hup[host].passwd = s:netrw_passwd
3407
3408 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003409 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003410
3411 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003412 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003413 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003414" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003415 let host = substitute(a:1,'^ftp:','','')
3416 let host = substitute(host,'\..*','','')
3417 if exists("s:netrw_hup[host]")
3418 let g:netrw_uid = s:netrw_hup[host].uid
3419 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003420" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3421" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003422 else
3423 let g:netrw_uid = input("Enter UserId: ")
3424 let s:netrw_passwd = inputsecret("Enter Password: ")
3425 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003426
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003427 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003428 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003429" 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 +02003430 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003431 if g:netrw_machine =~ '[0-9.]\+'
3432 let host= g:netrw_machine
3433 else
3434 let host= substitute(g:netrw_machine,'\..*$','','')
3435 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003436 else
3437 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003438 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003439 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003440" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003441 if exists("g:netrw_passwd")
3442 " ask for password if one not previously entered
3443 let s:netrw_passwd= g:netrw_passwd
3444 else
3445 let s:netrw_passwd = inputsecret("Enter Password: ")
3446 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003447 endif
3448
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003449" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003450 if exists("host")
3451 if !exists('s:netrw_hup[host]')
3452 let s:netrw_hup[host]= {}
3453 endif
3454 let s:netrw_hup[host].uid = g:netrw_uid
3455 let s:netrw_hup[host].passwd = s:netrw_passwd
3456 endif
3457
3458 elseif a:0 == 2
3459 let g:netrw_uid = a:1
3460 let s:netrw_passwd = a:2
3461
3462 elseif a:0 == 3
3463 " enter hostname, user-id, and password into the hup dictionary
3464 let host = substitute(a:1,'^\a\+:','','')
3465 let host = substitute(host,'\..*$','','')
3466 if !exists('s:netrw_hup[host]')
3467 let s:netrw_hup[host]= {}
3468 endif
3469 let s:netrw_hup[host].uid = a:2
3470 let s:netrw_hup[host].passwd = a:3
3471 let g:netrw_uid = s:netrw_hup[host].uid
3472 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003473" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3474" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003476
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003477" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003478endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479
Bram Moolenaar85850f32019-07-19 22:05:51 +02003480" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003481" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003482" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003484" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003485" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3486fun! s:ExplorePatHls(pattern)
3487" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3488 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003489" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003490 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003491" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003492 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3493" call Dret("s:ExplorePatHls repat<".repat.">")
3494 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003495endfun
3496
3497" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003498" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003499" 0: (user: <mb>) bookmark current directory
3500" 1: (user: <gb>) change to the bookmarked directory
3501" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003502" 3: (browsing) records current directory history
3503" 4: (user: <u>) go up (previous) directory, using history
3504" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003505" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003506fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003507" 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 +02003508 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3509" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3510 return
3511 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003512
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003513 let ykeep = @@
3514 let curbufnr = bufnr("%")
3515
Bram Moolenaar9964e462007-05-05 17:54:07 +00003516 if a:chg == 0
3517 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003518" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003519 if exists("s:netrwmarkfilelist_{curbufnr}")
3520 call s:NetrwBookmark(0)
3521 echo "bookmarked marked files"
3522 else
3523 call s:MakeBookmark(a:curdir)
3524 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003525 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003526
KSR-Yasudaf4498252023-10-06 03:34:17 +09003527 try
3528 call s:NetrwBookHistSave()
3529 catch
3530 endtry
3531
Bram Moolenaar9964e462007-05-05 17:54:07 +00003532 elseif a:chg == 1
3533 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003534" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003535 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003536" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003537 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003538 else
3539 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3540 endif
3541
3542 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003543" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003544 let didwork= 0
3545 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003546" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003547 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003548" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003549 let cnt= 1
3550 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003551" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003552 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003553 let didwork = 1
3554 let cnt = cnt + 1
3555 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003556 endif
3557
3558 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003559 " Note: history is saved only when PerformListing is done;
3560 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3561 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003562 let first = 1
3563 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003564 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003565 while ( first || cnt != g:netrw_dirhistcnt )
3566" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003567 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003568" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003569 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003570 let didwork= 1
3571 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003572 let histcnt = histcnt + 1
3573 let first = 0
3574 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003575 if cnt < 0
3576 let cnt= cnt + g:netrw_dirhistmax
3577 endif
3578 endwhile
3579 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003580 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003581 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003582 if didwork
3583 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3584 endif
3585
3586 elseif a:chg == 3
3587 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003588" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003589 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 +02003590 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003591 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3592 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003593 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003594" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003595 endif
3596
3597 elseif a:chg == 4
3598 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003599" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003600 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003601 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3602 if g:netrw_dirhistcnt < 0
3603 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003604 endif
3605 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003606 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003607 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003608 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3609" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003610 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003611 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003612" call Decho("setl ma noro",'~'.expand("<slnum>"))
3613 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003614 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003615" call Decho("setl nomod",'~'.expand("<slnum>"))
3616" 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 +00003617 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003618" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3619 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003620 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003621 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003622 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003623 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003624 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003625 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003626 echo "Sorry, no predecessor directory exists yet"
3627 endif
3628
3629 elseif a:chg == 5
3630 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003631" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003632 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003633 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3634 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3635" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003636 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003637" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003638 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003639 sil! NetrwKeepj %d _
3640" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3641" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003642 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003643" 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 +02003644 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003645" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3646 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003647 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003648 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3649 if g:netrw_dirhistcnt < 0
3650 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003651 endif
3652 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003653 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003654 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003655 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003656 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003657 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003658
3659 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003660" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003661 if exists("s:netrwmarkfilelist_{curbufnr}")
3662 call s:NetrwBookmark(1)
3663 echo "removed marked files from bookmarks"
3664 else
3665 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003666 let iremove = v:count
3667 let dremove = g:netrw_bookmarklist[iremove - 1]
3668" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003669 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003670" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3671 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3672 echo "removed ".dremove." from g:netrw_bookmarklist"
3673" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003674 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003675" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003676
3677 try
3678 call s:NetrwBookHistSave()
3679 catch
3680 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003681 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003682 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003683 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003684 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003685" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003686endfun
3687
3688" ---------------------------------------------------------------------
3689" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003690" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003691" Sister function: s:NetrwBookHistSave()
3692fun! s:NetrwBookHistRead()
3693" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003694 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003695" 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 +02003696 return
3697 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003698 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003699
3700 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003701 if !exists("s:netrw_initbookhist")
3702 let home = s:NetrwHome()
3703 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003704 if filereadable(s:NetrwFile(savefile))
3705" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003706 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003707 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003708
3709 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003710 if g:netrw_dirhistmax > 0
3711 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003712 if filereadable(s:NetrwFile(savefile))
3713" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003714 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003715 endif
3716 let s:netrw_initbookhist= 1
3717 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003718 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003719 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003720
Bram Moolenaar97d62492012-11-15 21:28:22 +01003721 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003722" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3723" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003724" call Dret("s:NetrwBookHistRead")
3725endfun
3726
3727" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003728" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003729" Sister function: s:NetrwBookHistRead()
3730" I used to do this via viminfo but that appears to
3731" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003732" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3733" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003734" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003735fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003736" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003737 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003738" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003739 return
3740 endif
3741
Bram Moolenaar5c736222010-01-06 20:54:52 +01003742 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003743" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003744 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003745
3746 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003747 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003748" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003749 if g:netrw_use_noswf
3750 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3751 else
3752 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3753 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003754 setl nocin noai noci magic nospell nohid wig= noaw
3755 setl ma noro write
3756 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003757 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003758
Bram Moolenaar85850f32019-07-19 22:05:51 +02003759 " rename enew'd file: .netrwhist -- no attempt to merge
3760 " record dirhistmax and current dirhistcnt
3761 " save history
3762" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003763 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003764 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003765 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3766 if g:netrw_dirhistmax > 0
3767 let lastline = line("$")
3768 let cnt = g:netrw_dirhistcnt
3769 let first = 1
3770 while ( first || cnt != g:netrw_dirhistcnt )
3771 let lastline= lastline + 1
3772 if exists("g:netrw_dirhist_{cnt}")
3773 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3774" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3775 endif
3776 let first = 0
3777 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3778 if cnt < 0
3779 let cnt= cnt + g:netrw_dirhistmax
3780 endif
3781 endwhile
3782 exe "sil! w! ".savefile
3783" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3784 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003785
Bram Moolenaar85850f32019-07-19 22:05:51 +02003786 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003787 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003788 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003789" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003790 " merge and write .netrwbook
3791 let savefile= s:NetrwHome()."/.netrwbook"
3792
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003793 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003794 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003795 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003796 for bdm in booklist
3797 if index(g:netrw_bookmarklist,bdm) == -1
3798 call add(g:netrw_bookmarklist,bdm)
3799 endif
3800 endfor
3801 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003802 endif
3803
3804 " construct and save .netrwbook
3805 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003806 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003807" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003808 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003809
3810 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003811 let bgone= bufnr("%")
3812 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003813 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003814
3815" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003816endfun
3817
3818" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003819" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3820" list of the contents of a local or remote directory. It is assumed that the
3821" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3822" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003823" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003824fun! s:NetrwBrowse(islocal,dirname)
3825 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003826" 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 +02003827" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3828" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3829" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003830
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003831 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3832 " This is useful when one edits a local file, then :e ., then :Rex
3833 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3834 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003835" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003836 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003837
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003838 " s:NetrwBrowse : initialize history {{{3
3839 if !exists("s:netrw_initbookhist")
3840 NetrwKeepj call s:NetrwBookHistRead()
3841 endif
3842
3843 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003844 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003845 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003846" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003847 else
3848 let dirname= a:dirname
3849 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003850
Bram Moolenaar85850f32019-07-19 22:05:51 +02003851 " repoint t:netrw_lexbufnr if appropriate
3852 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3853" call Decho("set repointlexbufnr to true!")
3854 let repointlexbufnr= 1
3855 endif
3856
3857 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003858 if exists("s:netrw_skipbrowse")
3859 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003860" 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 +01003861" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003862 return
3863 endif
3864 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003865 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003866" call Dret("s:NetrwBrowse : missing shellescape()")
3867 return
3868 endif
3869 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003870 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003871" call Dret("s:NetrwBrowse : missing fnameescape()")
3872 return
3873 endif
3874
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003875 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003876 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003877
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003878 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003879 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3880 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3881" call Decho("clearing marked files",'~'.expand("<slnum>"))
3882 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3883 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003884 endif
3885
3886 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003887 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003888" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3889" 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 +02003890 if s:NetrwLcd(dirname)
3891" call Dret("s:NetrwBrowse : lcd failure")
3892 return
3893 endif
3894 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003895" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003896
Bram Moolenaar5c736222010-01-06 20:54:52 +01003897 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003898 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003899" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003900 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003901" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003902 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003903 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003904 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003905" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003906
3907 " remove any filetype indicator from end of dirname, except for the
3908 " "this is a directory" indicator (/).
3909 " There shouldn't be one of those here, anyway.
3910 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003911" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003912 call s:RemotePathAnalysis(dirname)
3913
3914 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3915 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003916 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003917 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003918" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003919 let b:netrw_curdir = dirname
3920 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003921 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003922 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3923 sil call netrw#NetRead(2,url)
3924 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003925" call Decho("url<".url.">",'~'.expand("<slnum>"))
3926" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3927" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003928 if s:path =~ '.bz2'
3929 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3930 elseif s:path =~ '.gz'
3931 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3932 elseif s:path =~ '.gz'
3933 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3934 else
3935 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3936 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003937 endif
3938
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003939 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003940 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003941 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003942" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003943 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944" 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 +00003945
Bram Moolenaar446cb832008-06-24 21:56:24 +00003946" call Dret("s:NetrwBrowse : file<".s:fname.">")
3947 return
3948 endif
3949
Bram Moolenaaradc21822011-04-01 18:03:16 +02003950 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003951 call s:UseBufWinVars()
3952
3953 " set up some variables {{{3
3954 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003955 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003956 let s:last_sort_by = g:netrw_sort_by
3957
3958 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003959 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003960
Bram Moolenaar97d62492012-11-15 21:28:22 +01003961 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003962" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003963 let svpos = winsaveview()
3964" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003965 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003966
Bram Moolenaar446cb832008-06-24 21:56:24 +00003967 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003968 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3969 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3970" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3971" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3972 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3973 else
3974" " call Decho("2match none",'~'.expand("<slnum>"))
3975 2match none
3976 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003977 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003978 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003979 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003980" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003981 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003982" 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 +01003983" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003984 return
3985 endif
3986
3987 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003988" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003989 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003990 if b:netrw_curdir =~ '[/\\]$'
3991 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3992 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003993 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3994 let b:netrw_curdir= b:netrw_curdir."/"
3995 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003996 if b:netrw_curdir == ''
3997 if has("amiga")
3998 " On the Amiga, the empty string connotes the current directory
3999 let b:netrw_curdir= getcwd()
4000 else
4001 " under unix, when the root directory is encountered, the result
4002 " from the preceding substitute is an empty string.
4003 let b:netrw_curdir= '/'
4004 endif
4005 endif
4006 if !a:islocal && b:netrw_curdir !~ '/$'
4007 let b:netrw_curdir= b:netrw_curdir.'/'
4008 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004009" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004010
4011 " ------------
4012 " (local only) {{{3
4013 " ------------
4014 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004015" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004016
4017 " Set up ShellCmdPost handling. Append current buffer to browselist
4018 call s:LocalFastBrowser()
4019
4020 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
4021 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004022" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
4023" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004024 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004025 if s:NetrwLcd(b:netrw_curdir)
4026" call Dret("s:NetrwBrowse : lcd failure")
4027 return
4028 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004029 endif
4030 endif
4031
4032 " --------------------------------
4033 " remote handling: {{{3
4034 " --------------------------------
4035 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004036" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004037
Bram Moolenaar97d62492012-11-15 21:28:22 +01004038 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004039" 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 +02004040 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004041 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004042" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004043 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4044 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4045 if dirname !~ '/$'
4046 let dirname= dirname.'/'
4047 endif
4048 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004049" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004050 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004051 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004052" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004053 endif
4054
4055 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4056 if dirname !~ dirpat
4057 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004058 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004059 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004060 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004061" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004062 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004063" 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 +00004064" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4065 return
4066 endif
4067 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004068" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004069 endif " (additional remote handling)
4070
Bram Moolenaar85850f32019-07-19 22:05:51 +02004071 " -------------------------------
4072 " Perform Directory Listing: {{{3
4073 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004074 NetrwKeepj call s:NetrwMaps(a:islocal)
4075 NetrwKeepj call s:NetrwCommands(a:islocal)
4076 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004077
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004078 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004079 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004080" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4081
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004082 " If there is a rexposn: restore position with rexposn
4083 " Otherwise : set rexposn
4084 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004085" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4086 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4087 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4088 NetrwKeepj exe w:netrw_bannercnt
4089 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004090 else
4091 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4092 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004093 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004094 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004095" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004096 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004097 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004098
Bram Moolenaar85850f32019-07-19 22:05:51 +02004099 " repoint t:netrw_lexbufnr if appropriate
4100 if exists("repointlexbufnr")
4101 let t:netrw_lexbufnr= bufnr("%")
4102" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4103 endif
4104
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004105 " restore position
4106 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004107" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4108 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004109 endif
4110
Bram Moolenaara6878372014-03-22 21:02:50 +01004111 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004112 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4113 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004114" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4115" 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 +02004116" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004117 return
4118endfun
4119
4120" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004121" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4122" may not apply correctly; ie. netrw's idea of the current directory may
4123" differ from vim's. This function insures that netrw's idea of the current
4124" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004125" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004126fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004127" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4128" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4129" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4130" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4131" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004132
4133 " clean up any leading treedepthstring
4134 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4135 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004136" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004137 else
4138 let fname= a:fname
4139 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004140
4141 if g:netrw_keepdir
4142 " vim's idea of the current directory possibly may differ from netrw's
4143 if !exists("b:netrw_curdir")
4144 let b:netrw_curdir= getcwd()
4145 endif
4146
4147 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004148 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004149 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004150 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004151" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004152 else
4153 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004154 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004155" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004156 endif
4157
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004158 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004159 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004160 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004161" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004162 else
4163 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004164 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004165" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004166 endif
4167 else
4168 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004169 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004170" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4171" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4172" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004173 endif
4174
Bram Moolenaar85850f32019-07-19 22:05:51 +02004175" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004176 return ret
4177endfun
4178
4179" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004180" s:NetrwFileInfo: supports qf (query for file information) {{{2
4181fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004182" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004183 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004184 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004185 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004186 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004187 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004188 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004189 let lsopt= "-lsadh --si"
4190 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004191" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004192 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004193
4194 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004195 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004196" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004197
Bram Moolenaara6878372014-03-22 21:02:50 +01004198 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004199 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004200" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004201
4202 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004203 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004204" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004205
Bram Moolenaar446cb832008-06-24 21:56:24 +00004206 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004207" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004208 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004209" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004210 endif
4211 else
4212 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004213" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4214 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004215 let fname= substitute(a:fname,".$","","")
4216 else
4217 let fname= a:fname
4218 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004219 let t = getftime(s:NetrwFile(fname))
4220 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004221 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004222 let sz= s:NetrwHumanReadable(sz)
4223 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004224 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4225" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004226 endif
4227 else
4228 echo "sorry, \"qf\" not supported yet for remote files"
4229 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004230 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004231" call Dret("s:NetrwFileInfo")
4232endfun
4233
4234" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004235" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4236fun! s:NetrwFullPath(filename)
4237" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4238 let filename= a:filename
4239 if filename !~ '^/'
4240 let filename= resolve(getcwd().'/'.filename)
4241 endif
4242 if filename != "/" && filename =~ '/$'
4243 let filename= substitute(filename,'/$','','')
4244 endif
4245" " call Dret("s:NetrwFullPath <".filename.">")
4246 return filename
4247endfun
4248
4249" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004250" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004251" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004252" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004253" Nov 09, 2020: tst952 shows that when user does :set hidden that NetrwGetBuffer will come up with a [No Name] buffer (hid fix)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004254fun! s:NetrwGetBuffer(islocal,dirname)
4255" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004256" 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." hid=".&hid,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004257" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4258" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004259 let dirname= a:dirname
4260
4261 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004262" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004263 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004264" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004265 let s:netrwbuf= {}
4266 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004267" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4268" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4269
4270 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4271 let bufnum = -1
4272
4273 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4274 if has_key(s:netrwbuf,"NetrwTreeListing")
4275 let bufnum= s:netrwbuf["NetrwTreeListing"]
4276 else
4277 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4278 endif
4279" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4280 if !bufexists(bufnum)
4281 call remove(s:netrwbuf,"NetrwTreeListing"])
4282 let bufnum= -1
4283 endif
4284 elseif bufnr("NetrwTreeListing") != -1
4285 let bufnum= bufnr("NetrwTreeListing")
4286" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4287 else
4288" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4289 let bufnum= -1
4290 endif
4291
4292 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004293 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004294" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004295 if !bufexists(bufnum)
4296 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4297 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004298 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004299
Bram Moolenaar446cb832008-06-24 21:56:24 +00004300 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004301" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004302 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004303 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004304" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4305
Bram Moolenaar71badf92023-04-22 22:40:14 +01004306 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004307 " IF the buffer already has the desired name
4308 " AND it is empty
4309 let curbuf = bufname("%")
4310 if curbuf == '.'
4311 let curbuf = getcwd()
4312 endif
4313" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004314" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004315" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4316" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4317" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4318" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4319 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004320" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4321 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004322 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004323" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004324 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004325 " Aug 14, 2021: was thinking about looking for a [No Name] buffer here and using it, but that might cause problems
Bram Moolenaar446cb832008-06-24 21:56:24 +00004326
4327 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004328 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004329" 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 +00004330 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004331" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004332 " name the buffer
4333 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4334 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004335" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004336 let w:netrw_treebufnr = bufnr("%")
4337 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004338 if g:netrw_use_noswf
4339 setl nobl bt=nofile noswf
4340 else
4341 setl nobl bt=nofile
4342 endif
4343 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4344 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4345 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4346 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004347" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004348 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004349 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004350 " enter the new buffer into the s:netrwbuf dictionary
4351 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4352" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4353" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004354 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004355" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004356
4357 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004358" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004359 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004360 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004361 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004362
4363 if &ft == "netrw"
4364" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4365 exe "sil! NetrwKeepj noswapfile b ".bufnum
4366" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004367 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004368" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4369 call s:NetrwEditBuf(bufnum)
4370" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004371 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004372" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004373 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004374 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004375 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004376
4377 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004378 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004379
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004380 if line("$") <= 1 && getline(1) == ""
4381 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004382 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004383" 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>"))
4384" 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 +01004385" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4386 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004387
Bram Moolenaar97d62492012-11-15 21:28:22 +01004388 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004389" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004390 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004391 sil NetrwKeepj %d _
4392" 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>"))
4393" 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 +01004394" 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 +00004395 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004396
Bram Moolenaar446cb832008-06-24 21:56:24 +00004397 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004398" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4399" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004400 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004401 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004402 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004403" 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>"))
4404" 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 +01004405" 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 +00004406 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004407
Bram Moolenaar446cb832008-06-24 21:56:24 +00004408 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004409" 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>"))
4410" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4411" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004412 return 1
4413 endif
4414 endif
4415
4416 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4417 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4418 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4419 " med 1 D H
4420 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004421" 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 +00004422 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004423 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004424 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004425
4426 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004427" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4428" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4429 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004430
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004431" 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>"))
4432" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4433" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004434 return 0
4435endfun
4436
4437" ---------------------------------------------------------------------
4438" s:NetrwGetcwd: get the current directory. {{{2
4439" Change backslashes to forward slashes, if any.
4440" If doesc is true, escape certain troublesome characters
4441fun! s:NetrwGetcwd(doesc)
4442" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4443 let curdir= substitute(getcwd(),'\\','/','ge')
4444 if curdir !~ '[\/]$'
4445 let curdir= curdir.'/'
4446 endif
4447 if a:doesc
4448 let curdir= fnameescape(curdir)
4449 endif
4450" call Dret("NetrwGetcwd <".curdir.">")
4451 return curdir
4452endfun
4453
4454" ---------------------------------------------------------------------
4455" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4456fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004457" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4458" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4459 let keepsol= &l:sol
4460 setl nosol
4461
Bram Moolenaar446cb832008-06-24 21:56:24 +00004462 call s:UseBufWinVars()
4463
4464 " insure that w:netrw_liststyle is set up
4465 if !exists("w:netrw_liststyle")
4466 if exists("g:netrw_liststyle")
4467 let w:netrw_liststyle= g:netrw_liststyle
4468 else
4469 let w:netrw_liststyle= s:THINLIST
4470 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004471" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004472 endif
4473
4474 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4475 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004476" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004477 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004478 let dirname= "./"
4479 let curline= getline('.')
4480
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004481 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004482 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004483 let s:netrw_skipbrowse= 1
4484 echo 'Pressing "s" also works'
4485
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004486 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004487 let s:netrw_skipbrowse= 1
4488 echo 'Press "S" to edit sorting sequence'
4489
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004490 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004491 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004492 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004493
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004494 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004495 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004496 let s:netrw_skipbrowse= 1
4497 echo 'Pressing "a" also works'
4498
4499 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004500 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004501 endif
4502
4503 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004504" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004505 NetrwKeepj norm! 0
4506 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004507
4508 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004509" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004510 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004511 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4512
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004513 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004514" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004515 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004516 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004517
4518 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004519" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004520 let dirname= getline('.')
4521
4522 if !exists("b:netrw_cpf")
4523 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004524 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 +01004525 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004526" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004527 endif
4528
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004529" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004530 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004531" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4532" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004533 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004534 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004535 else
4536 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004537 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004538 endif
4539 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004540 let eofname= filestart + b:netrw_cpf + 1
4541 if eofname <= col("$")
4542 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004543 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004544 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004545 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004546 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004547 let dirname = @a
4548 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004549" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004550 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004551" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004552 endif
4553
4554 " symlinks are indicated by a trailing "@". Remove it before further processing.
4555 let dirname= substitute(dirname,"@$","","")
4556
4557 " executables are indicated by a trailing "*". Remove it before further processing.
4558 let dirname= substitute(dirname,"\*$","","")
4559
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004560 let &l:sol= keepsol
4561
Bram Moolenaar446cb832008-06-24 21:56:24 +00004562" call Dret("s:NetrwGetWord <".dirname.">")
4563 return dirname
4564endfun
4565
4566" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004567" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4568" g:netrw_bufsettings will be used after the listing is produced.
4569" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004570fun! s:NetrwListSettings(islocal)
4571" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004572" 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 +00004573 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004574" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4575 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4576 setl bt=nofile nobl ma nonu nowrap noro nornu
4577 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004578 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004579 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004580 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004581" call Dredir("ls!","s:NetrwListSettings")
4582" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004583 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004584 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004585 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004586 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004587 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004588 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004589 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004590" 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 +00004591" call Dret("s:NetrwListSettings")
4592endfun
4593
4594" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004595" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004596" islocal=0: remote browsing
4597" =1: local browsing
4598fun! s:NetrwListStyle(islocal)
4599" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004600
Bram Moolenaar97d62492012-11-15 21:28:22 +01004601 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004602 let fname = s:NetrwGetWord()
4603 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004604 let svpos = winsaveview()
4605" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004606 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004607" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4608" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4609" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004610
Bram Moolenaar85850f32019-07-19 22:05:51 +02004611 " repoint t:netrw_lexbufnr if appropriate
4612 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4613" call Decho("set repointlexbufnr to true!")
4614 let repointlexbufnr= 1
4615 endif
4616
Bram Moolenaar446cb832008-06-24 21:56:24 +00004617 if w:netrw_liststyle == s:THINLIST
4618 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004619" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004620 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4621
4622 elseif w:netrw_liststyle == s:LONGLIST
4623 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004624" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004625 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4626
4627 elseif w:netrw_liststyle == s:WIDELIST
4628 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004629" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004630 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4631
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004632 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004633" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004634 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4635
4636 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004637 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004638 let g:netrw_liststyle = s:THINLIST
4639 let w:netrw_liststyle = g:netrw_liststyle
4640 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4641 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004642 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004643" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004644
4645 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004646" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4647 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004648 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004649" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004650 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004651" 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 +00004652
4653 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004654" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004655 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004656 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004657
Bram Moolenaar85850f32019-07-19 22:05:51 +02004658 " repoint t:netrw_lexbufnr if appropriate
4659 if exists("repointlexbufnr")
4660 let t:netrw_lexbufnr= bufnr("%")
4661" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4662 endif
4663
Bram Moolenaar13600302014-05-22 18:26:40 +02004664 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004665" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4666 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004667 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004668
4669" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4670endfun
4671
4672" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004673" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4674fun! s:NetrwBannerCtrl(islocal)
4675" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4676
Bram Moolenaar97d62492012-11-15 21:28:22 +01004677 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004678 " toggle the banner (enable/suppress)
4679 let g:netrw_banner= !g:netrw_banner
4680
4681 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004682 let svpos= winsaveview()
4683" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004684 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4685
4686 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004687 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4688 let fname= s:NetrwGetWord()
4689 sil NetrwKeepj $
4690 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4691" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4692 if result <= 0 && exists("w:netrw_bannercnt")
4693 exe "NetrwKeepj ".w:netrw_bannercnt
4694 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004695 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004696 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004697" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4698endfun
4699
4700" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004701" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4702"
4703" No bang: enters files/directories into Netrw's bookmark system
4704" No argument and in netrw buffer:
4705" if there are marked files: bookmark marked files
4706" otherwise : bookmark file/directory under cursor
4707" No argument and not in netrw buffer: bookmarks current open file
4708" Has arguments: globs them individually and bookmarks them
4709"
4710" With bang: deletes files/directories from Netrw's bookmark system
4711fun! s:NetrwBookmark(del,...)
4712" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4713 if a:0 == 0
4714 if &ft == "netrw"
4715 let curbufnr = bufnr("%")
4716
4717 if exists("s:netrwmarkfilelist_{curbufnr}")
4718 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004719" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004720 let svpos = winsaveview()
4721" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004722 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004723 for fname in s:netrwmarkfilelist_{curbufnr}
4724 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4725 endfor
4726 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4727 call s:NetrwUnmarkList(curbufnr,curdir)
4728 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004729" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4730 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004731 else
4732 let fname= s:NetrwGetWord()
4733 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4734 endif
4735
4736 else
4737 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004738" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004739 let fname= expand("%")
4740 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4741 endif
4742
4743 else
4744 " bookmark specified files
4745 " attempts to infer if working remote or local
4746 " by deciding if the current file begins with an url
4747 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004748 let islocal= expand("%") !~ '^\a\{3,}://'
4749" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004750 let i = 1
4751 while i <= a:0
4752 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004753 if v:version > 704 || (v:version == 704 && has("patch656"))
4754 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004755 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004756 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004757 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004758 else
4759 let mbfiles= [a:{i}]
4760 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004761" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004762 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004763" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004764 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4765 endfor
4766 let i= i + 1
4767 endwhile
4768 endif
4769
4770 " update the menu
4771 call s:NetrwBookmarkMenu()
4772
4773" call Dret("s:NetrwBookmark")
4774endfun
4775
4776" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004777" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4778" .2.[cnt] for bookmarks, and
4779" .3.[cnt] for history
4780" (see s:NetrwMenu())
4781fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004782 if !exists("s:netrw_menucnt")
4783 return
4784 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004785" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004786
4787 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004788 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004789 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004790" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004791 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4792 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004793 endif
4794 if !exists("s:netrw_initbookhist")
4795 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004796 endif
4797
4798 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004799 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004800 let cnt= 1
4801 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004802" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004803 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004804
4805 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004806 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004807
4808 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004809 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 +01004810 let cnt= cnt + 1
4811 endfor
4812
4813 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004814
4815 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004816 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004817 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004818 let first = 1
4819 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004820 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004821 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004822 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004823 if exists("g:netrw_dirhist_{cnt}")
4824 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004825" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004826 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4827 endif
4828 let first = 0
4829 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4830 if cnt < 0
4831 let cnt= cnt + g:netrw_dirhistmax
4832 endif
4833 endwhile
4834 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004835
Bram Moolenaar9964e462007-05-05 17:54:07 +00004836 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004837" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004838endfun
4839
4840" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004841" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4842" directory and a new directory name. Also, if the
4843" "new directory name" is actually a file,
4844" NetrwBrowseChgDir() edits the file.
4845fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004846" call Dfunc("s:NetrwBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." win#".winnr()." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004847" 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 +00004848
Bram Moolenaar97d62492012-11-15 21:28:22 +01004849 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004850 if !exists("b:netrw_curdir")
4851 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4852 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004853 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004854" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4855" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004856" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004857" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004858 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004859 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004860" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004861
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004862 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004863" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004864 call s:SavePosn(s:netrw_posn)
4865 NetrwKeepj call s:NetrwOptionsSave("s:")
4866 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004867 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004868 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004869 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004870 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004871 endif
4872 let newdir = a:newdir
4873 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004874 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004875" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004876" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004877" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004878
4879 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004880" 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 +01004881 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004882" call Decho("win#".winnr()." 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 +01004883 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004884 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004885" 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 +01004886 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004887" 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 +02004888 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004889 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004890 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004891 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004892" 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 +01004893 endif
4894 endif
4895" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004896" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004897 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004898
Bram Moolenaar446cb832008-06-24 21:56:24 +00004899 " set up o/s-dependent directory recognition pattern
4900 if has("amiga")
4901 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004902 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 let dirpat= '[\/]$'
4904 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004905" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906
4907 if dirname !~ dirpat
4908 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004909 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004910 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004911" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004912 endif
4913
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004914" 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 +01004915 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004916 " ------------------------------
4917 " NetrwBrowseChgDir: edit a file {{{3
4918 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004919" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004920
Bram Moolenaar97d62492012-11-15 21:28:22 +01004921 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004922 let s:rexposn_{bufnr("%")}= winsaveview()
4923" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004924" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4925" 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 +01004926
Bram Moolenaar446cb832008-06-24 21:56:24 +00004927 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004928" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4929" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004930" let newdir = s:NetrwTreePath(s:netrw_treetop)
4931" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004932 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004933 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4934" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4935 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004936 if dirname =~ '/$'
4937 let dirname= dirname.newdir
4938 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004939 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004940 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004941" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4942" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004943 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004944" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004945 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004946 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004947 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004948 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004949" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004950 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004951 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004952" 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 +02004953 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004954 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004955 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004956" " call Decho("edit-a-file: s:didsplit does not exist; g:netrw_browse_split=".string(g:netrw_browse_split)." win#".winnr()." g:netrw_chgwin=".g:netrw_chgwin",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004957 if type(g:netrw_browse_split) == 3
4958 " open file in server
4959 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004960" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004961 call s:NetrwServerEdit(a:islocal,dirname)
4962" call Dret("s:NetrwBrowseChgDir")
4963 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004964
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004965 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004966 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004967" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004968 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4969 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004970 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004971 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004972 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004973 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004974
Bram Moolenaar446cb832008-06-24 21:56:24 +00004975 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004976 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004977" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004978 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4979 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004980 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004981 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004982 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004983 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004984
Bram Moolenaar446cb832008-06-24 21:56:24 +00004985 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004986 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004987" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004988 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004989 if !exists("b:netrw_curdir")
4990 let b:netrw_curdir= getcwd()
4991 endif
4992 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004993
Bram Moolenaar446cb832008-06-24 21:56:24 +00004994 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004995 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004996" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004997 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004998 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004999" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005000 return
5001 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005002 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005003
Bram Moolenaar9964e462007-05-05 17:54:07 +00005004 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00005005 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005006" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005007 call s:NetrwMenu(0)
5008 " optional change to window
5009 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005010" call Decho("edit-a-file: changing window to #".g:netrw_chgwin.": (due to g:netrw_chgwin)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005011 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09005012 " if g:netrw_chgwin is set to one more than the last window, then
5013 " vertically split the last window to make that window available.
5014 let curwin= winnr()
5015 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
5016 vs
5017 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02005018 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005019 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00005020 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005021 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00005022 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005023
Bram Moolenaar9964e462007-05-05 17:54:07 +00005024 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005025
Bram Moolenaar446cb832008-06-24 21:56:24 +00005026 " the point where netrw actually edits the (local) file
5027 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01005028 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005029 if !&mod
5030 " if e the new file would fail due to &mod, then don't change any of the flags
5031 let dolockout= 1
5032 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005033 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005034" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005035 " some like c-^ to return to the last edited file
5036 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005037 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5038 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005039 call s:NetrwEditFile("e","",dirname)
5040" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005041 " COMBAK -- cuc cul related
5042 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005043 if &hidden || &bufhidden == "hide"
5044 " file came from vim's hidden storage. Don't "restore" options with it.
5045 let dorestore= 0
5046 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005047 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005048" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005049 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005050
5051 " handle g:Netrw_funcref -- call external-to-netrw functions
5052 " This code will handle g:Netrw_funcref as an individual function reference
5053 " or as a list of function references. It will ignore anything that's not
5054 " a function reference. See :help Funcref for information about function references.
5055 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005056" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005057 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005058" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005059 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005060 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005061" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005062 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005063 if type(Fncref) == 2
5064 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005065 endif
5066 endfor
5067 endif
5068 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005069 endif
5070
5071 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005072 " ----------------------------------------------------
5073 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5074 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005075" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005076 let dirname = newdir
5077 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005078 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005079 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005080
5081 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005082 " ---------------------------------------------
5083 " NetrwBrowseChgDir: refresh the directory list {{{3
5084 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005085" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005086 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005087 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005088
5089 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005090 " --------------------------------------
5091 " NetrwBrowseChgDir: go up one directory {{{3
5092 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005093" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005094
5095 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5096 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005097" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5098" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005099 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005100 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005101 endif
5102
5103 if has("amiga")
5104 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005105" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005106 if a:islocal
5107 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5108 let dirname= substitute(dirname,'/$','','')
5109 else
5110 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5111 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005112" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005113
Bram Moolenaar8d043172014-01-23 14:24:41 +01005114 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
5115 " windows
5116 if a:islocal
5117 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5118 if dirname == ""
5119 let dirname= '/'
5120 endif
5121 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005122 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005123 endif
5124 if dirname =~ '^\a:$'
5125 let dirname= dirname.'/'
5126 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005127" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005128
Bram Moolenaar446cb832008-06-24 21:56:24 +00005129 else
5130 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005131" 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 +00005132 if a:islocal
5133 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5134 if dirname == ""
5135 let dirname= '/'
5136 endif
5137 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005138 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005139 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005140" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005141 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005142 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005143 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005144
5145 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005146 " --------------------------------------
5147 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5148 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005149" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005150 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5151" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005152 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005153 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005154" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5155 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005156 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005157 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005158" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005159 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005160 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005161" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005162
5163 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005164" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005165 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005166" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167 let haskey= 1
5168 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005169" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005170 endif
5171
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005172 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005173" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005174 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005175 if has_key(w:netrw_treedict,treedir."/")
5176 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005177" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005178 let haskey = 1
5179 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005180" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005181 endif
5182 endif
5183
5184 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005185" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005186 if !haskey && treedir =~ '/$'
5187 let treedir= substitute(treedir,'/$','','')
5188 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005189" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005190 let haskey = 1
5191 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005192" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005193 endif
5194 endif
5195
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005196" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005197 if haskey
5198 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005199" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005200 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005201" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5202" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005203 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005204 else
5205 " go down one directory
5206 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005207" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5208" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005209 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005210 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005211" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005212 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005213
5214 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005215 " ----------------------------------------
5216 " NetrwBrowseChgDir: Go down one directory {{{3
5217 " ----------------------------------------
5218 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005219" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005220 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005221 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005222 endif
5223
Bram Moolenaar97d62492012-11-15 21:28:22 +01005224 " --------------------------------------
5225 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5226 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005227 if dorestore
5228 " dorestore is zero'd when a local file was hidden or bufhidden;
5229 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005230" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005231 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005232" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005233" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005234 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005235 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005236" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005237 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005238" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5239" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005240 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005241" 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 +02005242 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005243" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5244" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005245 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005246" 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 +02005247 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005248 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005249 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005250 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005251
Bram Moolenaar446cb832008-06-24 21:56:24 +00005252" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5253 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005254endfun
5255
5256" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005257" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5258" for thin, long, and wide: cursor placed just after banner
5259" for tree, keeps cursor on current filename
5260fun! s:NetrwBrowseUpDir(islocal)
5261" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005262 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5263 " this test needed because occasionally this function seems to be incorrectly called
5264 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005265 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005266 " directories.
5267" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5268 return
5269 endif
5270
Bram Moolenaara6878372014-03-22 21:02:50 +01005271 norm! 0
5272 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005273" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005274 let curline= getline(".")
5275 let swwline= winline() - 1
5276 if exists("w:netrw_treetop")
5277 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005278 elseif exists("b:netrw_curdir")
5279 let w:netrw_treetop= b:netrw_curdir
5280 else
5281 let w:netrw_treetop= getcwd()
5282 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005283 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005284 let curfile = getline(".")
5285 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005286 if a:islocal
5287 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5288 else
5289 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5290 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005291" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5292" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5293 if w:netrw_treetop == '/'
5294 keepj call search('^\M'.curfile,"w")
5295 elseif curfile == '../'
5296 keepj call search('^\M'.curfile,"wb")
5297 else
5298" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5299 while 1
5300 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5301 let treepath= s:NetrwTreePath(w:netrw_treetop)
5302" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5303 if treepath == curpath
5304 break
5305 endif
5306 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005307 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005308
Bram Moolenaara6878372014-03-22 21:02:50 +01005309 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005310" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005311 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005312 if exists("b:netrw_curdir")
5313 let curdir= b:netrw_curdir
5314 else
5315 let curdir= expand(getcwd())
5316 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005317 if a:islocal
5318 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5319 else
5320 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5321 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005322 call s:RestorePosn(s:netrw_posn)
5323 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005324 let curdir= '\<'. escape(curdir, '~'). '/'
5325 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005326 endif
5327" call Dret("s:NetrwBrowseUpDir")
5328endfun
5329
5330" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005331" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005332" given filename; typically this means given their extension.
5333" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005334fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005335 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005336" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005337
Bram Moolenaar91359012019-11-30 17:57:03 +01005338 if a:remote == 0 && isdirectory(a:fname)
5339 " if its really just a local directory, then do a "gf" instead
5340" call Decho("remote≡0 and a:fname<".a:fname."> ".(isdirectory(a:fname)? "is a directory" : "is not a directory"),'~'.expand("<slnum>"))
Bram Moolenaar29634562020-01-09 21:46:04 +01005341" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5342 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005343" call Dret("netrw#BrowseX")
5344 return
5345 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5346 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5347" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5348" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5349" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5350" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5351 norm! gf
5352" call Dret("netrw#BrowseX")
5353 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005354 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005355" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005356
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005357 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5358 let remote = a:remote
5359 else
5360 let remote = 0
5361 endif
5362
Bram Moolenaar97d62492012-11-15 21:28:22 +01005363 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005364 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005365" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005366
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005367 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5368 let awkeep = &aw
5369 set noaw
5370
Bram Moolenaar5c736222010-01-06 20:54:52 +01005371 " special core dump handler
5372 if a:fname =~ '/core\(\.\d\+\)\=$'
5373 if exists("g:Netrw_corehandler")
5374 if type(g:Netrw_corehandler) == 2
5375 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005376" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005377 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005378 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005379 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005380" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005381 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005382 if type(Fncref) == 2
5383 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005384 endif
5385 endfor
5386 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005387" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005388 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005389 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005390 let &aw= awkeep
5391" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005392 return
5393 endif
5394 endif
5395
Bram Moolenaar446cb832008-06-24 21:56:24 +00005396 " set up the filename
5397 " (lower case the extension, make a local copy of a remote file)
5398 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5399 if has("win32") || has("win95") || has("win64") || has("win16")
5400 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005401 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005402 if exten =~ "[\\/]"
5403 let exten= ""
5404 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005405" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005406
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005407 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005408 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005409" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005410 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005411 call netrw#NetRead(3,a:fname)
5412 " attempt to rename tempfile
5413 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005414 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005415" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5416" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005417 if s:netrw_tmpfile != newname && newname != ""
5418 if rename(s:netrw_tmpfile,newname) == 0
5419 " renaming succeeded
5420" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5421 let fname= newname
5422 else
5423 " renaming failed
5424" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5425 let fname= s:netrw_tmpfile
5426 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005427 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005428 let fname= s:netrw_tmpfile
5429 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005430 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005431" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005432 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005433 " special ~ handler for local
5434 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005435" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5436 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005437 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005438 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005439" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5440" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005441
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005442 " set up redirection (avoids browser messages)
5443 " by default, g:netrw_suppress_gx_mesg is true
5444 if g:netrw_suppress_gx_mesg
5445 if &srr =~ "%s"
5446 if (has("win32") || has("win95") || has("win64") || has("win16"))
5447 let redir= substitute(&srr,"%s","nul","")
5448 else
5449 let redir= substitute(&srr,"%s","/dev/null","")
5450 endif
5451 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5452 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005453 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005454 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005455 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005456 else
5457 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005458 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005459" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005460
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005461 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005462 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005463" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005464 if g:netrw_browsex_viewer =~ '\s'
5465 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5466 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5467 let oviewer = ''
5468 let cnt = 1
5469 while !executable(viewer) && viewer != oviewer
5470 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5471 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5472 let cnt = cnt + 1
5473 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005474" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005475 endwhile
5476 else
5477 let viewer = g:netrw_browsex_viewer
5478 let viewopt = ""
5479 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005480" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005481 endif
5482
5483 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005484" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005485 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005486" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005487 let ret= netrwFileHandlers#Invoke(exten,fname)
5488
5489 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005490" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005491 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005492 let ret= v:shell_error
5493
5494 elseif has("win32") || has("win64")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005495" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005496 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005497 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005498 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005499 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005500 else
5501 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5502 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005503 let ret= v:shell_error
5504
Bram Moolenaar97d62492012-11-15 21:28:22 +01005505 elseif has("win32unix")
5506 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005507" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005508 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005509" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005510 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005511 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005512" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005513 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005514 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005515" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005516 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005517 else
5518 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5519 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005520 let ret= v:shell_error
5521
Bram Moolenaar85850f32019-07-19 22:05:51 +02005522 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005523" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5524 if a:fname =~ '^https\=://'
5525 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5526 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005527" call Decho("fname<".fname.">")
5528" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005529 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5530
5531 else
5532 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5533 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005534 let ret= v:shell_error
5535
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005536 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5537" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5538 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5539 let ret= v:shell_error
5540
5541 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5542" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5543 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5544 let ret= v:shell_error
5545
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005546 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005547" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005548 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005549 let ret= v:shell_error
5550
5551 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005552" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005553 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005554 let ret= v:shell_error
5555
5556 else
5557 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005558" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005559 let ret= netrwFileHandlers#Invoke(exten,fname)
5560 endif
5561
5562 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5563 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005564" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005565 let ret= netrwFileHandlers#Invoke(exten,fname)
5566 endif
5567
Bram Moolenaarc236c162008-07-13 17:41:49 +00005568 " restoring redraw! after external file handlers
5569 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005570
5571 " cleanup: remove temporary file,
5572 " delete current buffer if success with handler,
5573 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005574 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005575 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005576" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005577"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005578" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005579" endif
5580
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005581 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005582 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005583 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005584 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005585 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005586 if use_ctrlo
5587 exe "sil! NetrwKeepj norm! \<c-o>"
5588 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005589 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005590" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005591 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005592 let @@ = ykeep
5593 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005594
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005595" call Dret("netrw#BrowseX")
5596endfun
5597
5598" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005599" netrw#GX: gets word under cursor for gx support {{{2
5600" See also: netrw#BrowseXVis
5601" netrw#BrowseX
5602fun! netrw#GX()
5603" call Dfunc("netrw#GX()")
5604 if &ft == "netrw"
5605 let fname= s:NetrwGetWord()
5606 else
5607 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5608 endif
5609" call Dret("netrw#GX <".fname.">")
5610 return fname
5611endfun
5612
5613" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005614" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5615fun! netrw#BrowseXVis()
5616" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005617 let akeep = @a
5618 norm! gv"ay
5619 let gxfile= @a
5620 let @a = akeep
5621 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005622" call Dret("netrw#BrowseXVis")
5623endfun
5624
5625" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005626" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5627" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5628" to become an unlisted buffer, so in that case don't bwipe it.
5629fun! s:NetrwBufRename(newname)
5630" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5631" call Dredir("ls!","s:NetrwBufRename (before rename)")
5632 let oldbufname= bufname(bufnr("%"))
5633" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5634
5635 if oldbufname != a:newname
5636" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5637 let b:junk= 1
5638" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5639 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005640" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005641 let oldbufnr= bufnr(oldbufname)
5642" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5643" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5644 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5645" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5646 exe "bwipe! ".oldbufnr
5647" else " Decho
5648" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005649" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5650" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5651" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005652 endif
5653" call Dredir("ls!","s:NetrwBufRename (after rename)")
5654" else " Decho
5655" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5656 endif
5657
5658" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5659endfun
5660
5661" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005662" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005663fun! netrw#CheckIfRemote(...)
5664" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5665 if a:0 > 0
5666 let curfile= a:1
5667 else
5668 let curfile= expand("%")
5669 endif
5670" call Decho("curfile<".curfile.">")
5671 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005672" call Dret("netrw#CheckIfRemote 1")
5673 return 1
5674 else
5675" call Dret("netrw#CheckIfRemote 0")
5676 return 0
5677 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005678endfun
5679
5680" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005681" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5682fun! s:NetrwChgPerm(islocal,curdir)
5683" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005684 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005685 call inputsave()
5686 let newperm= input("Enter new permission: ")
5687 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005688 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5689 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5690" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005691 call system(chgperm)
5692 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005693 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005694 endif
5695 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005696 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005697 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005698 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005699" call Dret("s:NetrwChgPerm")
5700endfun
5701
5702" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005703" s:CheckIfKde: checks if kdeinit is running {{{2
5704" Returns 0: kdeinit not running
5705" 1: kdeinit is running
5706fun! s:CheckIfKde()
5707" call Dfunc("s:CheckIfKde()")
5708 " seems kde systems often have gnome-open due to dependencies, even though
5709 " gnome-open's subsidiary display tools are largely absent. Kde systems
5710 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5711 if !exists("s:haskdeinit")
5712 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005713 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005714 if v:shell_error
5715 let s:haskdeinit = 0
5716 endif
5717 else
5718 let s:haskdeinit= 0
5719 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005720" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005721 endif
5722
5723" call Dret("s:CheckIfKde ".s:haskdeinit)
5724 return s:haskdeinit
5725endfun
5726
5727" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005728" s:NetrwClearExplore: clear explore variables (if any) {{{2
5729fun! s:NetrwClearExplore()
5730" call Dfunc("s:NetrwClearExplore()")
5731 2match none
5732 if exists("s:explore_match") |unlet s:explore_match |endif
5733 if exists("s:explore_indx") |unlet s:explore_indx |endif
5734 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5735 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5736 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5737 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5738 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5739 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5740 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5741" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005742" call Dret("s:NetrwClearExplore")
5743endfun
5744
5745" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005746" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5747fun! s:NetrwEditBuf(bufnum)
5748" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5749 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5750" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5751 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5752 else
5753" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005754 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005755 endif
5756" call Dret("s:NetrwEditBuf")
5757endfun
5758
5759" ---------------------------------------------------------------------
5760" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5761" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5762fun! s:NetrwEditFile(cmd,opt,fname)
5763" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5764 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5765" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5766 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5767 else
5768" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5769 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5770 endif
5771" call Dret("s:NetrwEditFile")
5772endfun
5773
5774" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005775" s:NetrwExploreListUniq: {{{2
5776fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005777" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005778
5779 " this assumes that the list is already sorted
5780 let newexplist= []
5781 for member in a:explist
5782 if !exists("uniqmember") || member != uniqmember
5783 let uniqmember = member
5784 let newexplist = newexplist + [ member ]
5785 endif
5786 endfor
5787
Bram Moolenaar15146672011-10-20 22:22:38 +02005788" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005789 return newexplist
5790endfun
5791
5792" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005793" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5794fun! s:NetrwForceChgDir(islocal,newdir)
5795" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005796 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005797 if a:newdir !~ '/$'
5798 " ok, looks like force is needed to get directory-style treatment
5799 if a:newdir =~ '@$'
5800 let newdir= substitute(a:newdir,'@$','/','')
5801 elseif a:newdir =~ '[*=|\\]$'
5802 let newdir= substitute(a:newdir,'.$','/','')
5803 else
5804 let newdir= a:newdir.'/'
5805 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005806" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005807 else
5808 " should already be getting treatment as a directory
5809 let newdir= a:newdir
5810 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005811 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005812 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005813 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005814" call Dret("s:NetrwForceChgDir")
5815endfun
5816
5817" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005818" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005819" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5820" expr : this is the expression to follow the directory. Will use s:ComposePath()
5821" pare =1: remove the current directory from the resulting glob() filelist
5822" =0: leave the current directory in the resulting glob() filelist
5823fun! s:NetrwGlob(direntry,expr,pare)
5824" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005825 if netrw#CheckIfRemote()
5826 keepalt 1sp
5827 keepalt enew
5828 let keep_liststyle = w:netrw_liststyle
5829 let w:netrw_liststyle = s:THINLIST
5830 if s:NetrwRemoteListing() == 0
5831 keepj keepalt %s@/@@
5832 let filelist= getline(1,$)
5833 q!
5834 else
5835 " remote listing error -- leave treedict unchanged
5836 let filelist= w:netrw_treedict[a:direntry]
5837 endif
5838 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005839 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5840 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5841 if a:pare
5842 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5843 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005844 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005845 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5846 if a:pare
5847 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5848 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005849 endif
5850" call Dret("s:NetrwGlob ".string(filelist))
5851 return filelist
5852endfun
5853
5854" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005855" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5856fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005857" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005858 if a:newfile =~ '[/@*=|\\]$'
5859 let newfile= substitute(a:newfile,'.$','','')
5860 else
5861 let newfile= a:newfile
5862 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005863 if a:islocal
5864 call s:NetrwBrowseChgDir(a:islocal,newfile)
5865 else
5866 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5867 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005868" call Dret("s:NetrwForceFile")
5869endfun
5870
5871" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005872" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5873" and switches the hiding mode. The actual hiding is done by
5874" s:NetrwListHide().
5875" g:netrw_hide= 0: show all
5876" 1: show not-hidden files
5877" 2: show hidden files only
5878fun! s:NetrwHide(islocal)
5879" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005880 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005881 let svpos= winsaveview()
5882" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005883
5884 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005885" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5886" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005887
5888 " hide the files in the markfile list
5889 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005890" 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 +00005891 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5892 " remove fname from hiding list
5893 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5894 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5895 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005896" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005897 else
5898 " append fname to hiding list
5899 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5900 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5901 else
5902 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5903 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005904" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005905 endif
5906 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005907 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005908 let g:netrw_hide= 1
5909
5910 else
5911
5912 " switch between show-all/show-not-hidden/show-hidden
5913 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005914 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005915 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005916 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005917 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005918" call Dret("NetrwHide")
5919 return
5920 endif
5921 endif
5922
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005923 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005924" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5925 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005926 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005927" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005928endfun
5929
5930" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005931" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5932fun! s:NetrwHideEdit(islocal)
5933" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5934
5935 let ykeep= @@
5936 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005937 let svpos= winsaveview()
5938" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005939
5940 " get new hiding list from user
5941 call inputsave()
5942 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5943 call inputrestore()
5944 let g:netrw_list_hide= newhide
5945" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5946
5947 " refresh the listing
5948 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5949
5950 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005951" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5952 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005953 let @@= ykeep
5954
5955" call Dret("NetrwHideEdit")
5956endfun
5957
5958" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005959" s:NetrwHidden: invoked by "gh" {{{2
5960fun! s:NetrwHidden(islocal)
5961" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005962 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005963 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005964 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005965" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005966
5967 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005968 " remove .file pattern from hiding list
5969" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005970 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005971 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005972" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005973 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5974 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005975" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005976 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5977 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005978 if g:netrw_list_hide =~ '^,'
5979 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5980 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005981
5982 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005983 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005984" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5985 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005986 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005987" call Dret("s:NetrwHidden")
5988endfun
5989
5990" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005991" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5992fun! s:NetrwHome()
5993 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005994 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005995 else
5996 " go to vim plugin home
5997 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005998 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005999 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006000 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01006001 let home= basehome."/.vim"
6002 break
6003 endif
6004 endfor
6005 if home == ""
6006 " just pick the first directory
6007 let home= substitute(&rtp,',.*$','','')
6008 endif
6009 if (has("win32") || has("win95") || has("win64") || has("win16"))
6010 let home= substitute(home,'/','\\','g')
6011 endif
6012 endif
6013 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006014 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006015" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006016 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02006017" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006018 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01006019 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006020" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006021 call mkdir(home)
6022 endif
6023 endif
6024 let g:netrw_home= home
6025 return home
6026endfun
6027
6028" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006029" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
6030fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006031 if exists("s:netrwdrag")
6032 return
6033 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006034 if &ft != "netrw"
6035 return
6036 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006037" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006038
Bram Moolenaar97d62492012-11-15 21:28:22 +01006039 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006040 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006041 while getchar(0) != 0
6042 "clear the input stream
6043 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006044 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006045 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006046 let mouse_lnum = v:mouse_lnum
6047 let wlastline = line('w$')
6048 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006049" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6050" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006051 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6052 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006053 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006054" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6055 return
6056 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006057 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006058 " 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 +01006059 " without this test when its disabled.
6060 " 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 +01006061" 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 +01006062 if v:mouse_col > virtcol('.')
6063 let @@= ykeep
6064" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6065 return
6066 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006067
Bram Moolenaar446cb832008-06-24 21:56:24 +00006068 if a:islocal
6069 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006070 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006071 endif
6072 else
6073 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006074 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006075 endif
6076 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006077 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006078" call Dret("s:NetrwLeftmouse")
6079endfun
6080
6081" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006082" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6083fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006084 if &ft != "netrw"
6085 return
6086 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006087" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6088 call s:NetrwMarkFileTgt(a:islocal)
6089" call Dret("s:NetrwCLeftmouse")
6090endfun
6091
6092" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006093" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6094" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006095" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006096" a:islocal=2 : <c-r> used, remote
6097" a:islocal=3 : <c-r> used, local
6098fun! s:NetrwServerEdit(islocal,fname)
6099" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6100 let islocal = a:islocal%2 " =0: remote =1: local
6101 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006102" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006103
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006104 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006105 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006106 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006107" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006108 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006109 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006110 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6111 unlet s:netrw_browse_split_{winnr()}
6112 endif
6113 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6114" call Dret("s:NetrwServerEdit")
6115 return
6116 endif
6117
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006118" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006119 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006120" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006121
6122 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006123" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006124 let srvrname = g:netrw_browse_split[0]
6125 let tabnum = g:netrw_browse_split[1]
6126 let winnum = g:netrw_browse_split[2]
6127
6128 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006129" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006130
6131 if !ctrlr
6132 " user must have closed the server window and the user did not use <c-r>, but
6133 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006134" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006135 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006136 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006137 endif
6138 let g:netrw_browse_split= 0
6139 if exists("s:netrw_browse_split_".winnr())
6140 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6141 endif
6142 call s:NetrwBrowseChgDir(islocal,a:fname)
6143" call Dret("s:NetrwServerEdit")
6144 return
6145
6146 elseif has("win32") && executable("start")
6147 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006148" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006149 call system("start gvim --servername ".srvrname)
6150
6151 else
6152 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006153" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006154 call system("gvim --servername ".srvrname)
6155 endif
6156 endif
6157
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006158" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006159 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6160 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006161 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006162
6163 else
6164
6165 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6166
6167 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006168" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006169 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006170 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006171 endif
6172 let g:netrw_browse_split= 0
6173 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6174" call Dret("s:NetrwServerEdit")
6175 return
6176
6177 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006178" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006179 if has("win32") && executable("start")
6180 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006181" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006182 call system("start gvim --servername ".g:netrw_servername)
6183 else
6184 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006185" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006186 call system("gvim --servername ".g:netrw_servername)
6187 endif
6188 endif
6189 endif
6190
6191 while 1
6192 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006193" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6194 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006195 break
6196 catch /^Vim\%((\a\+)\)\=:E241/
6197 sleep 200m
6198 endtry
6199 endwhile
6200
6201 if exists("g:netrw_browse_split")
6202 if type(g:netrw_browse_split) != 3
6203 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6204 endif
6205 unlet g:netrw_browse_split
6206 endif
6207 let g:netrw_browse_split= [g:netrw_servername,1,1]
6208 endif
6209
6210 else
6211 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6212 endif
6213
6214" call Dret("s:NetrwServerEdit")
6215endfun
6216
6217" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006218" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6219fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006220 if &ft != "netrw"
6221 return
6222 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006223" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006224
Bram Moolenaar8d043172014-01-23 14:24:41 +01006225 let s:ngw= s:NetrwGetWord()
6226 call s:NetrwMarkFile(a:islocal,s:ngw)
6227
6228" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006229endfun
6230
6231" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006232" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6233" Used to mark multiple files.
6234fun! s:NetrwSLeftdrag(islocal)
6235" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6236 if !exists("s:netrwdrag")
6237 let s:netrwdrag = winnr()
6238 if a:islocal
6239 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006240 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006241 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006242 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006243 endif
6244 let ngw = s:NetrwGetWord()
6245 if !exists("s:ngw") || s:ngw != ngw
6246 call s:NetrwMarkFile(a:islocal,ngw)
6247 endif
6248 let s:ngw= ngw
6249" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6250endfun
6251
6252" ---------------------------------------------------------------------
6253" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6254fun! s:NetrwSLeftrelease(islocal)
6255" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6256 if exists("s:netrwdrag")
6257 nunmap <s-leftrelease>
6258 let ngw = s:NetrwGetWord()
6259 if !exists("s:ngw") || s:ngw != ngw
6260 call s:NetrwMarkFile(a:islocal,ngw)
6261 endif
6262 if exists("s:ngw")
6263 unlet s:ngw
6264 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006265 unlet s:netrwdrag
6266 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006267" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006268endfun
6269
6270" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006271" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6272" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006273fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006274" 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 +02006275" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006276 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006277
6278 " 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 +02006279 " How-it-works: take the hiding command, convert it into a range.
6280 " Duplicate characters don't matter.
6281 " Remove all such characters from the '/~@#...890' string.
6282 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006283" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006284 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006285 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006286" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006287
6288 while listhide != ""
6289 if listhide =~ ','
6290 let hide = substitute(listhide,',.*$','','e')
6291 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6292 else
6293 let hide = listhide
6294 let listhide = ""
6295 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006296" call Decho("..extracted pattern from listhide: hide<".hide."> g:netrw_sort_by<".g:netrw_sort_by.'>','~'.expand("<slnum>"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006297 if g:netrw_sort_by =~ '^[ts]'
6298 if hide =~ '^\^'
6299" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6300 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6301 elseif hide =~ '^\\(\^'
6302 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6303 endif
6304" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6305 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306
6307 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006308" 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 +00006309 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006310" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006311 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006312 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006313" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006314 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006315 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006316" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006317 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006318
Bram Moolenaar446cb832008-06-24 21:56:24 +00006319 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006320 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006321" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006322 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006323" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006324 endif
6325
Bram Moolenaaradc21822011-04-01 18:03:16 +02006326 " remove any blank lines that have somehow remained.
6327 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006328 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006329
Bram Moolenaar97d62492012-11-15 21:28:22 +01006330 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006331" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006332endfun
6333
6334" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006335" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006336" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006337fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006338" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006339
Bram Moolenaar97d62492012-11-15 21:28:22 +01006340 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006341 " get name of new directory from user. A bare <CR> will skip.
6342 " if its currently a directory, also request will be skipped, but with
6343 " a message.
6344 call inputsave()
6345 let newdirname= input("Please give directory name: ")
6346 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006347" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006348
6349 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006350 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006351" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006352 return
6353 endif
6354
6355 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006356" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006357
6358 " Local mkdir:
6359 " sanity checks
6360 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006361" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6362 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006363 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006364 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006365 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006366 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006367" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006368 return
6369 endif
6370 if s:FileReadable(fullnewdir)
6371 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006372 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006373 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006374 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006375" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006376 return
6377 endif
6378
6379 " requested new local directory is neither a pre-existing file or
6380 " directory, so make it!
6381 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006382 if has("unix")
6383 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6384 else
6385 call mkdir(fullnewdir,"p")
6386 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006387 else
6388 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006389 if s:NetrwLcd(b:netrw_curdir)
6390" call Dret("s:NetrwMakeDir : lcd failure")
6391 return
6392 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006393" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006394 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006395 if v:shell_error != 0
6396 let @@= ykeep
6397 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 +01006398" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006399 return
6400 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006401 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006402" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006403 if s:NetrwLcd(netrw_origdir)
6404" call Dret("s:NetrwBrowse : lcd failure")
6405 return
6406 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006407 endif
6408 endif
6409
6410 if v:shell_error == 0
6411 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006412" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006413 let svpos= winsaveview()
6414" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006415 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006416" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6417 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006418 elseif !exists("g:netrw_quiet")
6419 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6420 endif
6421" redraw!
6422
6423 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006424 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006425" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006426 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6427 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006428 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006429 if v:shell_error == 0
6430 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006431 let svpos= winsaveview()
6432" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006433 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006434" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6435 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006436 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006437 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006438 endif
6439" redraw!
6440
6441 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006442 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006443 let svpos= winsaveview()
6444" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006445" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006446 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006447" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006448 let remotepath= b:netrw_fname
6449 else
6450 let remotepath= ""
6451 endif
6452 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006453 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006454" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6455 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006456
Bram Moolenaar446cb832008-06-24 21:56:24 +00006457 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006458 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006459 let svpos= winsaveview()
6460" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006461" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006462 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006463" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006464 let remotepath= b:netrw_fname
6465 else
6466 let remotepath= ""
6467 endif
6468 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006469 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006470" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6471 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006472 endif
6473
Bram Moolenaar97d62492012-11-15 21:28:22 +01006474 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006475" call Dret("s:NetrwMakeDir")
6476endfun
6477
6478" ---------------------------------------------------------------------
6479" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6480fun! s:TreeSqueezeDir(islocal)
6481" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6482 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6483 " its a tree-listing style
6484 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006485 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006486 let depth = strchars(substitute(curdepth,' ','','g'))
6487 let srch = -1
6488" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6489" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006490" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006491" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6492 if depth >= 2
6493 NetrwKeepj norm! 0
6494 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6495 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6496" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6497" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6498 elseif depth == 1
6499 NetrwKeepj norm! 0
6500 let treedepthchr= substitute(s:treedepthstring,' ','','')
6501 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6502" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6503 endif
6504 if srch > 0
6505" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6506 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6507 exe srch
6508 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006509 endif
6510" call Dret("s:TreeSqueezeDir")
6511endfun
6512
6513" ---------------------------------------------------------------------
6514" s:NetrwMaps: {{{2
6515fun! s:NetrwMaps(islocal)
6516" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6517
Bram Moolenaar85850f32019-07-19 22:05:51 +02006518 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006519 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006520" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006521 if !hasmapto("<Plug>NetrwReturn")
6522 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006523" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006524 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6525 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006526" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006527 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6528 endif
6529 endif
6530 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006531" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006532 endif
6533
Bram Moolenaar85850f32019-07-19 22:05:51 +02006534 " generate default <Plug> maps {{{3
6535 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006536 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006537 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6538 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6539 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6540 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6541 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6542 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6543 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6544 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6545 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6546 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6547" ---------------------------------------------------------------------
6548" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6549" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6550" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6551" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6552" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6553" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6554" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6555" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6556" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6557" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6558" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6559" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6560" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6561" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6562" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6563" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6564" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6565" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6566" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6567" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6568" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6569" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6570" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6571" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6572" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6573" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6574" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6575" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6576" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6577" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6578" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6579" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6580" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6581" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6582" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6583" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6584" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6585" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6586" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6587" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6588" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6589" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6590" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6591" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6592" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6593" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6594" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6595
Bram Moolenaara6878372014-03-22 21:02:50 +01006596 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006597" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006598 " local normal-mode maps {{{3
6599 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6600 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6601 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6602 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6603 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6604 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6605 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6606 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6607 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6608 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6609 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6610" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006611 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6612 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6613 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006614 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006615 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006616 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6617 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6618 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6619 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006620 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6621 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6622 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6623 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6624 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6625 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6626 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6627 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6628 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6629 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6630 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6631 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6632 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006633 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006634 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006635 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6636 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6637 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6638 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6639 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006640 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006641 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006642 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6643 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006644 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6645 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6646 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006647 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006648 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006649 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6650 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006651 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006652 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006653 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6654 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6655 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006656 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6657 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006658
6659 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 +01006660 if !hasmapto('<Plug>NetrwHideEdit')
6661 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006662 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006663 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006664 if !hasmapto('<Plug>NetrwRefresh')
6665 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006666 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006667 nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(exists("w:netrw_liststyle") && exists("w:netrw_treetop") && w:netrw_liststyle == 3)? w:netrw_treetop : './'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006668 if s:didstarstar || !mapcheck("<s-down>","n")
6669 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006670 endif
6671 if s:didstarstar || !mapcheck("<s-up>","n")
6672 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006673 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006674 if !hasmapto('<Plug>NetrwTreeSqueeze')
6675 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006676 endif
6677 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006678 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6679 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006680 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6681 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6682 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6683 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6684 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6685 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6686 imap <buffer> <leftmouse> <Plug>ILeftmouse
6687 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006688 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6689 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6690 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6691 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6692 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006693 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006694 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6695 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006696 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006697 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6698 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6699 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6700 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6701 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6702 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6703 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006704 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6705
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006706 " support user-specified maps
6707 call netrw#UserMaps(1)
6708
Bram Moolenaar85850f32019-07-19 22:05:51 +02006709 else
6710 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006711" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006712 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006713 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6714 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6715 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6716 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6717 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6718 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6719 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6720 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6721 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6722 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6723 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6724" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006725 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6726 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6727 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6728 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6729 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6730 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6731 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6732 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006733 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006734 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006735 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6736 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6737 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6738 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6739 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6740 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6741 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6742 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6743 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6744 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6745 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006746 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006747 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006748 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6749 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6750 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6751 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6752 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006753 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6754 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6755 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6756 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006757 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006758 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6759 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006760 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006761 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 +01006762 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6763 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6764 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6765 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6766 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6767 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6768 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6769 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6770 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006771 if !hasmapto('<Plug>NetrwHideEdit')
6772 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006773 endif
6774 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6775 if !hasmapto('<Plug>NetrwRefresh')
6776 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006777 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006778 if !hasmapto('<Plug>NetrwTreeSqueeze')
6779 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006780 endif
6781 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006782
6783 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006784 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006785
6786 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6787 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006788 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006789 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006790 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006791 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006792 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006793 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006794 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006795 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006796 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006797 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006798 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6799 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6800 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006801 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006802 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006803 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6804 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006805 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006806 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6807 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6808 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6809 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6810 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6811 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6812 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006813 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006814
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006815 " support user-specified maps
6816 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006817 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006818
6819" call Dret("s:NetrwMaps")
6820endfun
6821
6822" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006823" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006824" If -buffer, the command is only available from within netrw buffers
6825" Otherwise, the command is available from any window, so long as netrw
6826" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006827fun! s:NetrwCommands(islocal)
6828" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6829
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006830 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6831 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006832 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 +01006833 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006834 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006835 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006836 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006837 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006838 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006839
6840" call Dret("s:NetrwCommands")
6841endfun
6842
6843" ---------------------------------------------------------------------
6844" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6845" glob()ing only works with local files
6846fun! s:NetrwMarkFiles(islocal,...)
6847" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006848 let curdir = s:NetrwGetCurdir(a:islocal)
6849 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006850 while i <= a:0
6851 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006852 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006853 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006854 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006855 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006856 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006857 else
6858 let mffiles= [a:{i}]
6859 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006860" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006861 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006862" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006863 call s:NetrwMarkFile(a:islocal,mffile)
6864 endfor
6865 let i= i + 1
6866 endwhile
6867" call Dret("s:NetrwMarkFiles")
6868endfun
6869
6870" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006871" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006872fun! s:NetrwMarkTarget(...)
6873" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6874 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006875 let curdir = s:NetrwGetCurdir(1)
6876 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006877 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006878 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6879 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006880 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006881" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006882 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006883 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6884 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006885 let svpos = winsaveview()
6886" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006887 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006888" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6889 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006890" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006891endfun
6892
6893" ---------------------------------------------------------------------
6894" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6895" mark and unmark files. If a markfile list exists,
6896" then the rename and delete functions will use it instead
6897" of whatever may happen to be under the cursor at that
6898" moment. When the mouse and gui are available,
6899" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006900"
6901" Creates two lists
6902" s:netrwmarkfilelist -- holds complete paths to all marked files
6903" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6904"
6905" Creates a marked file match string
6906" s:netrwmarfilemtch_# -- used with 2match to display marked files
6907"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006908" Creates a buffer version of islocal
6909" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006910fun! s:NetrwMarkFile(islocal,fname)
6911" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006912" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006913
6914 " sanity check
6915 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006916" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006917 return
6918 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006919 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006920
Bram Moolenaar97d62492012-11-15 21:28:22 +01006921 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006922 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006923 if a:fname =~ '^\a'
6924 let leader= '\<'
6925 else
6926 let leader= ''
6927 endif
6928 if a:fname =~ '\a$'
6929 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6930 else
6931 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6932 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006933
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006934 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006935 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006936" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6937" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6938" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006939 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006940
6941 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006942 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006943" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006944 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006945 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006946
6947 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006948 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006949" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006950 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6951 if s:netrwmarkfilelist_{curbufnr} == []
6952 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006953" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006954 call s:NetrwUnmarkList(curbufnr,curdir)
6955 else
6956 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006957" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006958 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006959 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006960 for fname in s:netrwmarkfilelist_{curbufnr}
6961 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006962 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006963 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006964 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006965 endif
6966 let first= 0
6967 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006968" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006969 endif
6970 endif
6971
6972 else
6973 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006974" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006975
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006976" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006977 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006978 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6979" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006980
6981 " build initial markfile matching pattern
6982 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006983 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006984 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006985 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006986 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006987" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006988 endif
6989
6990 " handle global markfilelist
6991 if exists("s:netrwmarkfilelist")
6992 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6993 if index(s:netrwmarkfilelist,dname) == -1
6994 " append new filename to global markfilelist
6995 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006996" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006997 else
6998 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006999" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
7000" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007001 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007002" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007003 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007004" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007005 unlet s:netrwmarkfilelist
7006 endif
7007 endif
7008 else
7009 " initialize new global-directory markfilelist
7010 let s:netrwmarkfilelist= []
7011 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007012" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007013 endif
7014
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007015 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02007016 if has("syntax") && exists("g:syntax_on") && g:syntax_on
7017 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
7018" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
7019 if exists("g:did_drchip_netrwlist_syntax")
7020 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
7021 endif
7022 else
7023" " call Decho("2match none",'~'.expand("<slnum>"))
7024 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01007025 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007026 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007027 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007028" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
7029" 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 +00007030endfun
7031
7032" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007033" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7034" mA: move the argument list to marked file list (tomflist=1)
7035" Uses the global marked file list
7036fun! s:NetrwMarkFileArgList(islocal,tomflist)
7037" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7038
7039 let svpos = winsaveview()
7040" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7041 let curdir = s:NetrwGetCurdir(a:islocal)
7042 let curbufnr = bufnr("%")
7043
7044 if a:tomflist
7045 " mA: move argument list to marked file list
7046 while argc()
7047 let fname= argv(0)
7048" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7049 exe "argdel ".fnameescape(fname)
7050 call s:NetrwMarkFile(a:islocal,fname)
7051 endwhile
7052
7053 else
7054 " ma: move marked file list to argument list
7055 if exists("s:netrwmarkfilelist")
7056
7057 " for every filename in the marked list
7058 for fname in s:netrwmarkfilelist
7059" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7060 exe "argadd ".fnameescape(fname)
7061 endfor " for every file in the marked list
7062
7063 " unmark list and refresh
7064 call s:NetrwUnmarkList(curbufnr,curdir)
7065 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7066" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7067 NetrwKeepj call winrestview(svpos)
7068 endif
7069 endif
7070
7071" call Dret("s:NetrwMarkFileArgList")
7072endfun
7073
7074" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007075" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7076" compress/decompress files using the programs
7077" in g:netrw_compress and g:netrw_uncompress,
7078" using g:netrw_compress_suffix to know which to
7079" do. By default:
7080" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007081" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007082fun! s:NetrwMarkFileCompress(islocal)
7083" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007084 let svpos = winsaveview()
7085" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007086 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007087 let curbufnr = bufnr("%")
7088
Bram Moolenaarff034192013-04-24 18:51:19 +02007089 " sanity check
7090 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007091 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007092" call Dret("s:NetrwMarkFileCompress")
7093 return
7094 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007095" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007096
Bram Moolenaar446cb832008-06-24 21:56:24 +00007097 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007098
7099 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007100 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007101 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007102" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007103 if exists("g:netrw_decompress['".sfx."']")
7104 " fname has a suffix indicating that its compressed; apply associated decompression routine
7105 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007106" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007107 let exe= netrw#WinPath(exe)
7108 if a:islocal
7109 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007110 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007111 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007112 call system(exe." ".fname)
7113 if v:shell_error
7114 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007115 endif
7116 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007117 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7118 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007119 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007120
Bram Moolenaarff034192013-04-24 18:51:19 +02007121 endif
7122 unlet sfx
7123
Bram Moolenaar446cb832008-06-24 21:56:24 +00007124 if exists("exe")
7125 unlet exe
7126 elseif a:islocal
7127 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007128 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007129 if v:shell_error
7130 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7131 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007132 else
7133 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007134 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007135 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007136 endfor " for every file in the marked list
7137
Bram Moolenaar446cb832008-06-24 21:56:24 +00007138 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007139 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007140" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7141 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007142 endif
7143" call Dret("s:NetrwMarkFileCompress")
7144endfun
7145
7146" ---------------------------------------------------------------------
7147" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7148" If no marked files, then set up directory as the
7149" target. Currently does not support copying entire
7150" directories. Uses the local-buffer marked file list.
7151" Returns 1=success (used by NetrwMarkFileMove())
7152" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007153fun! s:NetrwMarkFileCopy(islocal,...)
7154" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7155
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007156 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007157 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007158 if b:netrw_curdir !~ '/$'
7159 if !exists("b:netrw_curdir")
7160 let b:netrw_curdir= curdir
7161 endif
7162 let b:netrw_curdir= b:netrw_curdir."/"
7163 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007164
Bram Moolenaarff034192013-04-24 18:51:19 +02007165 " sanity check
7166 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007167 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007168" call Dret("s:NetrwMarkFileCopy")
7169 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007170 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007171" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007172
Bram Moolenaar446cb832008-06-24 21:56:24 +00007173 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007174 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007175" call Dret("s:NetrwMarkFileCopy 0")
7176 return 0
7177 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007178" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007179
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007180 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007181 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007182" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007183 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007184 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7185" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7186 return
7187 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007188
7189 " copy marked files while within the same directory (ie. allow renaming)
7190 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7191 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7192 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007193" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007194 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007195 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7196 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007197" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007198 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007199 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007200 let oldname = a:1
7201 else
7202 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007203" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007204 let s:recursive= 1
7205 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7206 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7207 if ret == 0
7208 break
7209 endif
7210 endfor
7211 unlet s:recursive
7212 call s:NetrwUnmarkList(curbufnr,curdir)
7213" call Dret("s:NetrwMarkFileCopy ".ret)
7214 return ret
7215 endif
7216
7217 call inputsave()
7218 let newname= input("Copy ".oldname." to : ",oldname,"file")
7219 call inputrestore()
7220 if newname == ""
7221" call Dret("s:NetrwMarkFileCopy 0")
7222 return 0
7223 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007224 let args= s:ShellEscape(oldname)
7225 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007226 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007227 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7228 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007229 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007230 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7231 let args= substitute(args,'/','\\','g')
7232 let tgt = substitute(tgt, '/','\\','g')
7233 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007234 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7235 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7236 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7237 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7238" call Decho("args <".args.">",'~'.expand("<slnum>"))
7239" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007240 if isdirectory(s:NetrwFile(args))
7241" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007242 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007243" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007244 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7245 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7246 " contents to a target. One must append the source directory name to the target to get xcopy to
7247 " do the right thing.
7248 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007249" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007250 endif
7251 else
7252 let copycmd= g:netrw_localcopycmd
7253 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007254 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007255 let copycmd = substitute(copycmd,'\s.*$','','')
7256 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007257 let copycmd = netrw#WinPath(copycmd).copycmdargs
7258 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007259 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007260 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007261" call Decho("args <".args.">",'~'.expand("<slnum>"))
7262" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7263" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7264" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007265 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007266 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007267 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007268 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 +01007269 else
7270 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7271 endif
7272" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007273 return 0
7274 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007275
7276 elseif a:islocal && !s:netrwmftgt_islocal
7277 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007278" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007279 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007280
7281 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007282 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007283" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007284 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007285
7286 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007287 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007288" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007289 let curdir = getcwd()
7290 let tmpdir = s:GetTempfile("")
7291 if tmpdir !~ '/'
7292 let tmpdir= curdir."/".tmpdir
7293 endif
7294 if exists("*mkdir")
7295 call mkdir(tmpdir)
7296 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007297 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007298 if v:shell_error != 0
7299 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 +01007300" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007301 return
7302 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007303 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007304 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007305 if s:NetrwLcd(tmpdir)
7306" call Dret("s:NetrwMarkFileCopy : lcd failure")
7307 return
7308 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007309 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007310 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007311 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007312 if getcwd() == tmpdir
7313 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007314 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007315 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007316 if s:NetrwLcd(curdir)
7317" call Dret("s:NetrwMarkFileCopy : lcd failure")
7318 return
7319 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007320 if delete(tmpdir,"d")
7321 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007322 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007323 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007324 if s:NetrwLcd(curdir)
7325" call Dret("s:NetrwMarkFileCopy : lcd failure")
7326 return
7327 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007328 endif
7329 endif
7330 endif
7331
7332 " -------
7333 " cleanup
7334 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007335" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007336 " remove markings from local buffer
7337 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007338" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7339" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7340" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7341" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7342" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7343" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7344 if exists("s:recursive")
7345" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7346 else
7347" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007348 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007349 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007350 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007351 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007352 else
7353 " refresh local and targets for fast browsing
7354 if !exists("s:recursive")
7355 " remove markings from local buffer
7356" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7357 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7358 endif
7359
7360 " refresh buffers
7361 if s:netrwmftgt_islocal
7362" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7363 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7364 endif
7365 if a:islocal && s:netrwmftgt != curdir
7366" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7367 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7368 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007369 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007370
Bram Moolenaar446cb832008-06-24 21:56:24 +00007371" call Dret("s:NetrwMarkFileCopy 1")
7372 return 1
7373endfun
7374
7375" ---------------------------------------------------------------------
7376" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7377" invoke vim's diff mode on the marked files.
7378" Either two or three files can be so handled.
7379" Uses the global marked file list.
7380fun! s:NetrwMarkFileDiff(islocal)
7381" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7382 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007383
Bram Moolenaarff034192013-04-24 18:51:19 +02007384 " sanity check
7385 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007386 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007387" call Dret("s:NetrwMarkFileDiff")
7388 return
7389 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007390 let curdir= s:NetrwGetCurdir(a:islocal)
7391" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007392
Bram Moolenaara6878372014-03-22 21:02:50 +01007393 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007394 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007395 for fname in s:netrwmarkfilelist
7396 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007397 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007398" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007399 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007400 diffthis
7401 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007402 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007403" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007404 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007405 diffthis
7406 else
7407 break
7408 endif
7409 endfor
7410 call s:NetrwUnmarkList(curbufnr,curdir)
7411 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007412
Bram Moolenaar446cb832008-06-24 21:56:24 +00007413" call Dret("s:NetrwMarkFileDiff")
7414endfun
7415
7416" ---------------------------------------------------------------------
7417" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7418" Uses global markfilelist
7419fun! s:NetrwMarkFileEdit(islocal)
7420" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7421
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007422 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007423 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007424
7425 " sanity check
7426 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007427 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007428" call Dret("s:NetrwMarkFileEdit")
7429 return
7430 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007431" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007432
Bram Moolenaar446cb832008-06-24 21:56:24 +00007433 if exists("s:netrwmarkfilelist_{curbufnr}")
7434 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007435 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007436 " unmark markedfile list
7437" call s:NetrwUnmarkList(curbufnr,curdir)
7438 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007439" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007440 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007441 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007442 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007443
Bram Moolenaar446cb832008-06-24 21:56:24 +00007444" call Dret("s:NetrwMarkFileEdit")
7445endfun
7446
7447" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007448" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007449fun! s:NetrwMarkFileQFEL(islocal,qfel)
7450" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7451 call s:NetrwUnmarkAll()
7452 let curbufnr= bufnr("%")
7453
7454 if !empty(a:qfel)
7455 for entry in a:qfel
7456 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007457" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007458 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007459" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007460 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7461 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7462 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7463 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007464" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007465 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7466 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007467" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007468 endif
7469 endfor
7470 echo "(use me to edit marked files)"
7471 else
7472 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7473 endif
7474
7475" call Dret("s:NetrwMarkFileQFEL")
7476endfun
7477
7478" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007479" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7480" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7481" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7482fun! s:NetrwMarkFileExe(islocal,enbloc)
7483" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007484 let svpos = winsaveview()
7485" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007486 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007487 let curbufnr = bufnr("%")
7488
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007489 if a:enbloc == 0
7490 " individually apply command to files, one at a time
7491 " sanity check
7492 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7493 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7494" call Dret("s:NetrwMarkFileExe")
7495 return
7496 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007497" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007498
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007499 if exists("s:netrwmarkfilelist_{curbufnr}")
7500 " get the command
7501 call inputsave()
7502 let cmd= input("Enter command: ","","file")
7503 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007504" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007505 if cmd == ""
7506" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7507 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007508 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007509
7510 " apply command to marked files, individually. Substitute: filename -> %
7511 " If no %, then append a space and the filename to the command
7512 for fname in s:netrwmarkfilelist_{curbufnr}
7513 if a:islocal
7514 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007515 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007516 endif
7517 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007518 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007519 endif
7520 if cmd =~ '%'
7521 let xcmd= substitute(cmd,'%',fname,'g')
7522 else
7523 let xcmd= cmd.' '.fname
7524 endif
7525 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007526" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007527 let ret= system(xcmd)
7528 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007529" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007530 let ret= s:RemoteSystem(xcmd)
7531 endif
7532 if v:shell_error < 0
7533 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7534 break
7535 else
7536 echo ret
7537 endif
7538 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007539
7540 " unmark marked file list
7541 call s:NetrwUnmarkList(curbufnr,curdir)
7542
7543 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007544 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007545" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7546 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007547 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007548 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007549 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007550
7551 else " apply command to global list of files, en bloc
7552
7553 call inputsave()
7554 let cmd= input("Enter command: ","","file")
7555 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007556" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007557 if cmd == ""
7558" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7559 return
7560 endif
7561 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007562 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007563 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007564 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007565 endif
7566 if a:islocal
7567 call system(cmd)
7568 if v:shell_error < 0
7569 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7570 endif
7571 else
7572 let ret= s:RemoteSystem(cmd)
7573 endif
7574 call s:NetrwUnmarkAll()
7575
7576 " refresh the listing
7577 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007578" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7579 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007580
7581 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007582
Bram Moolenaar446cb832008-06-24 21:56:24 +00007583" call Dret("s:NetrwMarkFileExe")
7584endfun
7585
7586" ---------------------------------------------------------------------
7587" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7588" as the marked file(s) (toggles suffix presence)
7589" Uses the local marked file list.
7590fun! s:NetrwMarkHideSfx(islocal)
7591" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007592 let svpos = winsaveview()
7593" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007594 let curbufnr = bufnr("%")
7595
7596 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7597 if exists("s:netrwmarkfilelist_{curbufnr}")
7598
7599 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007600" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007601 " construct suffix pattern
7602 if fname =~ '\.'
7603 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7604 else
7605 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7606 endif
7607 " determine if its in the hiding list or not
7608 let inhidelist= 0
7609 if g:netrw_list_hide != ""
7610 let itemnum = 0
7611 let hidelist= split(g:netrw_list_hide,',')
7612 for hidepat in hidelist
7613 if sfxpat == hidepat
7614 let inhidelist= 1
7615 break
7616 endif
7617 let itemnum= itemnum + 1
7618 endfor
7619 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007620" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007621 if inhidelist
7622 " remove sfxpat from list
7623 call remove(hidelist,itemnum)
7624 let g:netrw_list_hide= join(hidelist,",")
7625 elseif g:netrw_list_hide != ""
7626 " append sfxpat to non-empty list
7627 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7628 else
7629 " set hiding list to sfxpat
7630 let g:netrw_list_hide= sfxpat
7631 endif
7632 endfor
7633
7634 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007635 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007636" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7637 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007638 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007639 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007640 endif
7641
7642" call Dret("s:NetrwMarkHideSfx")
7643endfun
7644
7645" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007646" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007647" Uses the local marked-file list.
7648fun! s:NetrwMarkFileVimCmd(islocal)
7649" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007650 let svpos = winsaveview()
7651" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007652 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007653 let curbufnr = bufnr("%")
7654
Bram Moolenaarff034192013-04-24 18:51:19 +02007655 " sanity check
7656 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007657 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007658" call Dret("s:NetrwMarkFileVimCmd")
7659 return
7660 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007661" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007662
Bram Moolenaar15146672011-10-20 22:22:38 +02007663 if exists("s:netrwmarkfilelist_{curbufnr}")
7664 " get the command
7665 call inputsave()
7666 let cmd= input("Enter vim command: ","","file")
7667 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007668" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007669 if cmd == ""
7670" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7671 return
7672 endif
7673
7674 " apply command to marked files. Substitute: filename -> %
7675 " If no %, then append a space and the filename to the command
7676 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007677" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007678 if a:islocal
7679 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007680 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007681" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007682 exe cmd
7683 exe "sil! keepalt wq!"
7684 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007685" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007686 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007687 endif
7688 endfor
7689
7690 " unmark marked file list
7691 call s:NetrwUnmarkList(curbufnr,curdir)
7692
7693 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007694 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007695" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7696 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007697 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007698 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007699 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007700
Bram Moolenaar15146672011-10-20 22:22:38 +02007701" call Dret("s:NetrwMarkFileVimCmd")
7702endfun
7703
7704" ---------------------------------------------------------------------
7705" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7706" as the marked file(s) (toggles suffix presence)
7707" Uses the local marked file list.
7708fun! s:NetrwMarkHideSfx(islocal)
7709" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007710 let svpos = winsaveview()
7711" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007712 let curbufnr = bufnr("%")
7713
7714 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7715 if exists("s:netrwmarkfilelist_{curbufnr}")
7716
7717 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007718" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007719 " construct suffix pattern
7720 if fname =~ '\.'
7721 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7722 else
7723 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7724 endif
7725 " determine if its in the hiding list or not
7726 let inhidelist= 0
7727 if g:netrw_list_hide != ""
7728 let itemnum = 0
7729 let hidelist= split(g:netrw_list_hide,',')
7730 for hidepat in hidelist
7731 if sfxpat == hidepat
7732 let inhidelist= 1
7733 break
7734 endif
7735 let itemnum= itemnum + 1
7736 endfor
7737 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007738" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007739 if inhidelist
7740 " remove sfxpat from list
7741 call remove(hidelist,itemnum)
7742 let g:netrw_list_hide= join(hidelist,",")
7743 elseif g:netrw_list_hide != ""
7744 " append sfxpat to non-empty list
7745 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7746 else
7747 " set hiding list to sfxpat
7748 let g:netrw_list_hide= sfxpat
7749 endif
7750 endfor
7751
7752 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007753 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007754" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7755 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007756 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007757 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007758 endif
7759
7760" call Dret("s:NetrwMarkHideSfx")
7761endfun
7762
7763" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007764" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7765" Uses the global markfilelist
7766fun! s:NetrwMarkFileGrep(islocal)
7767" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007768 let svpos = winsaveview()
7769" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007770 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007771 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007772
7773 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007774" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007775 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007776" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007777 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007778 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007779" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007780 let netrwmarkfilelist= "*"
7781 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007782
Bram Moolenaarff034192013-04-24 18:51:19 +02007783 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007784" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007785 call inputsave()
7786 let pat= input("Enter pattern: ","")
7787 call inputrestore()
7788 let patbang = ""
7789 if pat =~ '^!'
7790 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007791 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007792 endif
7793 if pat =~ '^\i'
7794 let pat = escape(pat,'/')
7795 let pat = '/'.pat.'/'
7796 else
7797 let nonisi = pat[0]
7798 endif
7799
7800 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007801" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007802 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007803 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007804 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007805 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007806" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7807 return
7808 endtry
7809 echo "(use :cn, :cp to navigate, :Rex to return)"
7810
7811 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007812" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7813 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007814
7815 if exists("nonisi")
7816 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007817" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007818 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007819 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007820 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007821 endif
7822
7823" call Dret("s:NetrwMarkFileGrep")
7824endfun
7825
7826" ---------------------------------------------------------------------
7827" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7828" uses the global marked file list
7829" s:netrwmfloc= 0: target directory is remote
7830" = 1: target directory is local
7831fun! s:NetrwMarkFileMove(islocal)
7832" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007833 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007834 let curbufnr = bufnr("%")
7835
7836 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007837 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007838 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007839" call Dret("s:NetrwMarkFileMove")
7840 return
7841 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007842" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007843
Bram Moolenaar446cb832008-06-24 21:56:24 +00007844 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007845 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007846" call Dret("s:NetrwMarkFileCopy 0")
7847 return 0
7848 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007849" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007850
7851 if a:islocal && s:netrwmftgt_islocal
7852 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853" call Decho("move from local to local",'~'.expand("<slnum>"))
7854" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007855 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007856 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7857" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7858 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007859 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007860 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007861" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007862 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007863 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007864" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007865 if g:netrw_localmovecmd =~ '\s'
7866 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7867 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7868 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007869" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007870 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007871 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007872" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007873 endif
7874 else
7875 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007876" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007877 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007878 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007879 if g:netrw_keepdir
7880 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7881 let fname= b:netrw_curdir."/".fname
7882 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007883 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7884 let fname= substitute(fname,'/','\\','g')
7885 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007886" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007887 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007888 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007889 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007890 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 +01007891 else
7892 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7893 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007894 break
7895 endif
7896 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007897
7898 elseif a:islocal && !s:netrwmftgt_islocal
7899 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007900" call Decho("move from local to remote",'~'.expand("<slnum>"))
7901" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007902 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007903 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007904" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007905 for fname in mflist
7906 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7907 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7908 endfor
7909 unlet mflist
7910
7911 elseif !a:islocal && s:netrwmftgt_islocal
7912 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007913" call Decho("move from remote to local",'~'.expand("<slnum>"))
7914" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007915 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007916 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007917" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007918 for fname in mflist
7919 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7920 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7921 endfor
7922 unlet mflist
7923
7924 elseif !a:islocal && !s:netrwmftgt_islocal
7925 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007926" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7927" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007928 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007929 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007930" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007931 for fname in mflist
7932 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7933 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7934 endfor
7935 unlet mflist
7936 endif
7937
7938 " -------
7939 " cleanup
7940 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007941" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007942
7943 " remove markings from local buffer
7944 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7945
7946 " refresh buffers
7947 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007948" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007949 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007950 endif
7951 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007952" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007953 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007954 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007955 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007956" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007957 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007958 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007959
Bram Moolenaar446cb832008-06-24 21:56:24 +00007960" call Dret("s:NetrwMarkFileMove")
7961endfun
7962
7963" ---------------------------------------------------------------------
7964" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7965" using the hardcopy command. Local marked-file list only.
7966fun! s:NetrwMarkFilePrint(islocal)
7967" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7968 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007969
7970 " sanity check
7971 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007972 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007973" call Dret("s:NetrwMarkFilePrint")
7974 return
7975 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007976" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7977 let curdir= s:NetrwGetCurdir(a:islocal)
7978
Bram Moolenaar446cb832008-06-24 21:56:24 +00007979 if exists("s:netrwmarkfilelist_{curbufnr}")
7980 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007981 call s:NetrwUnmarkList(curbufnr,curdir)
7982 for fname in netrwmarkfilelist
7983 if a:islocal
7984 if g:netrw_keepdir
7985 let fname= s:ComposePath(curdir,fname)
7986 endif
7987 else
7988 let fname= curdir.fname
7989 endif
7990 1split
7991 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007992" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007993 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007994" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007995 hardcopy
7996 q
7997 endfor
7998 2match none
7999 endif
8000" call Dret("s:NetrwMarkFilePrint")
8001endfun
8002
8003" ---------------------------------------------------------------------
8004" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
8005" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02008006" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00008007fun! s:NetrwMarkFileRegexp(islocal)
8008" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
8009
8010 " get the regular expression
8011 call inputsave()
8012 let regexp= input("Enter regexp: ","","file")
8013 call inputrestore()
8014
8015 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008016 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008017" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008019" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008020 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008021 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008022 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008023 else
8024 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008025 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008026 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008027" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008028
8029 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008030 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02008031 if fname =~ '^'.fnameescape(curdir)
8032" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8033 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8034 else
8035" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8036 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8037 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008038 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008039
8040 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008041" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008042
8043 " convert displayed listing into a filelist
8044 let eikeep = &ei
8045 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008046 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008047 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008048" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008049 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008050 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008051 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008052 sil NetrwKeepj norm! "ap
8053 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008054 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008055 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008056 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008057 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008058 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008059 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008060 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008061 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008062 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008063 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008064 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8065 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008066 call histdel("/",-1)
8067 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008068 endif
8069 " convert regexp into the more usual glob-style format
8070 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008071" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008072 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008073 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008074 let filelist= getline(1,line("$"))
8075 q!
8076 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008077 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008078 endfor
8079 unlet filelist
8080 let @a = areg
8081 let &ei = eikeep
8082 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008083 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008084
8085" call Dret("s:NetrwMarkFileRegexp")
8086endfun
8087
8088" ---------------------------------------------------------------------
8089" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8090" Uses the local marked file list.
8091fun! s:NetrwMarkFileSource(islocal)
8092" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8093 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008094
8095 " sanity check
8096 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008097 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008098" call Dret("s:NetrwMarkFileSource")
8099 return
8100 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008101" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8102 let curdir= s:NetrwGetCurdir(a:islocal)
8103
Bram Moolenaar446cb832008-06-24 21:56:24 +00008104 if exists("s:netrwmarkfilelist_{curbufnr}")
8105 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008106 call s:NetrwUnmarkList(curbufnr,curdir)
8107 for fname in netrwmarkfilelist
8108 if a:islocal
8109 if g:netrw_keepdir
8110 let fname= s:ComposePath(curdir,fname)
8111 endif
8112 else
8113 let fname= curdir.fname
8114 endif
8115 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008116" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008117 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008118 endfor
8119 2match none
8120 endif
8121" call Dret("s:NetrwMarkFileSource")
8122endfun
8123
8124" ---------------------------------------------------------------------
8125" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8126" Uses the global markfilelist
8127fun! s:NetrwMarkFileTag(islocal)
8128" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008129 let svpos = winsaveview()
8130" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008131 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008132 let curbufnr = bufnr("%")
8133
Bram Moolenaarff034192013-04-24 18:51:19 +02008134 " sanity check
8135 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008136 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008137" call Dret("s:NetrwMarkFileTag")
8138 return
8139 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008140" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008141
Bram Moolenaar446cb832008-06-24 21:56:24 +00008142 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008143" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8144 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008145 call s:NetrwUnmarkAll()
8146
8147 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008148
8149" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8150 call system(g:netrw_ctags." ".netrwmarkfilelist)
8151 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008152 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8153 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008154
Bram Moolenaar446cb832008-06-24 21:56:24 +00008155 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008156 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008157 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008158 let curdir= b:netrw_curdir
8159 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008160 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008161 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008162" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008163 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008164 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008165 wq!
8166 endif
8167 2match none
8168 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008169" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8170 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008171 endif
8172
8173" call Dret("s:NetrwMarkFileTag")
8174endfun
8175
8176" ---------------------------------------------------------------------
8177" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008178" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008179" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008180" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008181" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008182fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008183" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8184 let svpos = winsaveview()
8185" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008186 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008187 let hadtgt = exists("s:netrwmftgt")
8188 if !exists("w:netrw_bannercnt")
8189 let w:netrw_bannercnt= b:netrw_bannercnt
8190 endif
8191
8192 " set up target
8193 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008194" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008195 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8196 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008197" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008198 unlet s:netrwmftgt s:netrwmftgt_islocal
8199 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008200 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008201 endif
8202 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008203" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8204 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008205" call Dret("s:NetrwMarkFileTgt : removed target")
8206 return
8207 else
8208 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008209" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008210 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008211
8212 else
8213 " get word under cursor.
8214 " * If directory, use it for the target.
8215 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008216" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008217 let curword= s:NetrwGetWord()
8218 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008219 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008220 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008221" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008222 elseif !a:islocal && tgtdir =~ '/$'
8223 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008224" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008225 else
8226 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008227" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008228 endif
8229 endif
8230 if a:islocal
8231 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8232 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008233" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008234 endif
8235 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008236 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008237 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8238 endif
8239 let s:netrwmftgt_islocal= a:islocal
8240
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008241 " need to do refresh so that the banner will be updated
8242 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008243 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008244" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008245 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008246 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008247" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008248 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008249 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8250 else
8251 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8252 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008253" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8254 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008255 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008256 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008257 endif
8258
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008259" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8260" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008261" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8262endfun
8263
8264" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008265" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8266fun! s:NetrwGetCurdir(islocal)
8267" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8268
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008269 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008270 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8271" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8272 elseif !exists("b:netrw_curdir")
8273 let b:netrw_curdir= getcwd()
8274" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8275 endif
8276
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008277" 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 +01008278 if b:netrw_curdir !~ '\<\a\{3,}://'
8279 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008280" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008281 if g:netrw_keepdir == 0
8282 call s:NetrwLcd(curdir)
8283 endif
8284 endif
8285
8286" call Dret("s:NetrwGetCurdir <".curdir.">")
8287 return b:netrw_curdir
8288endfun
8289
8290" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008291" s:NetrwOpenFile: query user for a filename and open it {{{2
8292fun! s:NetrwOpenFile(islocal)
8293" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008294 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008295 call inputsave()
8296 let fname= input("Enter filename: ")
8297 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008298" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8299
8300 " determine if Lexplore is in use
8301 if exists("t:netrw_lexbufnr")
8302 " check if t:netrw_lexbufnr refers to a netrw window
8303" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8304 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8305 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8306" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8307 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8308 exe "NetrwKeepj e ".fnameescape(fname)
8309 let @@= ykeep
8310" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8311 endif
8312 endif
8313
8314 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008315 if fname !~ '[/\\]'
8316 if exists("b:netrw_curdir")
8317 if exists("g:netrw_quiet")
8318 let netrw_quiet_keep = g:netrw_quiet
8319 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008320 let g:netrw_quiet = 1
8321 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008322 let s:rexposn_{bufnr("%")}= winsaveview()
8323" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008324 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008325 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008326 else
8327 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8328 endif
8329 if exists("netrw_quiet_keep")
8330 let g:netrw_quiet= netrw_quiet_keep
8331 else
8332 unlet g:netrw_quiet
8333 endif
8334 endif
8335 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008336 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008337 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008338 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008339" call Dret("s:NetrwOpenFile")
8340endfun
8341
8342" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008343" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8344" For the mapping to this function be made via
8345" netrwPlugin, you'll need to have had
8346" g:netrw_usetab set to non-zero.
8347fun! netrw#Shrink()
8348" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8349 let curwin = winnr()
8350 let wiwkeep = &wiw
8351 set wiw=1
8352
8353 if &ft == "netrw"
8354 if winwidth(0) > g:netrw_wiw
8355 let t:netrw_winwidth= winwidth(0)
8356 exe "vert resize ".g:netrw_wiw
8357 wincmd l
8358 if winnr() == curwin
8359 wincmd h
8360 endif
8361" call Decho("vert resize 0",'~'.expand("<slnum>"))
8362 else
8363 exe "vert resize ".t:netrw_winwidth
8364" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8365 endif
8366
8367 elseif exists("t:netrw_lexbufnr")
8368 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8369 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8370 let t:netrw_winwidth= winwidth(0)
8371 exe "vert resize ".g:netrw_wiw
8372 wincmd l
8373 if winnr() == curwin
8374 wincmd h
8375 endif
8376" call Decho("vert resize 0",'~'.expand("<slnum>"))
8377 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8378 exe "vert resize ".t:netrw_winwidth
8379" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8380 else
8381 call netrw#Lexplore(0,0)
8382 endif
8383
8384 else
8385 call netrw#Lexplore(0,0)
8386 endif
8387 let wiw= wiwkeep
8388
8389" call Dret("netrw#Shrink")
8390endfun
8391
8392" ---------------------------------------------------------------------
8393" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8394fun! s:NetSortSequence(islocal)
8395" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8396
8397 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008398 let svpos= winsaveview()
8399" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008400 call inputsave()
8401 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8402 call inputrestore()
8403
8404 " refresh the listing
8405 let g:netrw_sort_sequence= newsortseq
8406 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008407" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8408 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008409 let @@= ykeep
8410
8411" call Dret("NetSortSequence")
8412endfun
8413
8414" ---------------------------------------------------------------------
8415" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8416" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008417" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008418fun! s:NetrwUnmarkList(curbufnr,curdir)
8419" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8420
8421 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008422 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008423 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8424 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8425 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8426 call remove(s:netrwmarkfilelist,idx) " remove from global list
8427 endfor
8428 if s:netrwmarkfilelist == []
8429 unlet s:netrwmarkfilelist
8430 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008431
Bram Moolenaar446cb832008-06-24 21:56:24 +00008432 " getting rid of the local marked-file lists is easy
8433 unlet s:netrwmarkfilelist_{a:curbufnr}
8434 endif
8435 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8436 unlet s:netrwmarkfilemtch_{a:curbufnr}
8437 endif
8438 2match none
8439" call Dret("s:NetrwUnmarkList")
8440endfun
8441
8442" ---------------------------------------------------------------------
8443" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8444fun! s:NetrwUnmarkAll()
8445" call Dfunc("s:NetrwUnmarkAll()")
8446 if exists("s:netrwmarkfilelist")
8447 unlet s:netrwmarkfilelist
8448 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008449 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008450 2match none
8451" call Dret("s:NetrwUnmarkAll")
8452endfun
8453
8454" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008455" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008456fun! s:NetrwUnmarkAll2()
8457" call Dfunc("s:NetrwUnmarkAll2()")
8458 redir => netrwmarkfilelist_let
8459 let
8460 redir END
8461 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008462 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008463 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8464 for flist in netrwmarkfilelist_list
8465 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8466 unlet s:netrwmarkfilelist_{curbufnr}
8467 unlet s:netrwmarkfilemtch_{curbufnr}
8468 endfor
8469" call Dret("s:NetrwUnmarkAll2")
8470endfun
8471
8472" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008473" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8474"
8475" Marked files are in two types of lists:
8476" s:netrwmarkfilelist -- holds complete paths to all marked files
8477" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8478"
8479" Marked files suitable for use with 2match are in:
8480" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008481fun! s:NetrwUnMarkFile(islocal)
8482" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008483 let svpos = winsaveview()
8484" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008485 let curbufnr = bufnr("%")
8486
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008487 " unmark marked file list
8488 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8489 if exists("s:netrwmarkfilelist")
8490" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008491 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008492 endif
8493
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008494 let ibuf= 1
8495 while ibuf < bufnr("$")
8496 if exists("s:netrwmarkfilelist_".ibuf)
8497 unlet s:netrwmarkfilelist_{ibuf}
8498 unlet s:netrwmarkfilemtch_{ibuf}
8499 endif
8500 let ibuf = ibuf + 1
8501 endwhile
8502 2match none
8503
Bram Moolenaar446cb832008-06-24 21:56:24 +00008504" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008505"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8506call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008507" call Dret("s:NetrwUnMarkFile")
8508endfun
8509
8510" ---------------------------------------------------------------------
8511" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8512fun! s:NetrwMenu(domenu)
8513
8514 if !exists("g:NetrwMenuPriority")
8515 let g:NetrwMenuPriority= 80
8516 endif
8517
Bram Moolenaaradc21822011-04-01 18:03:16 +02008518 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008519" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8520
8521 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008522" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008523 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008524 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8528 if g:netrw_dirhistmax > 0
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8533 else
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8535 endif
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8550 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 +01008551 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 +02008552 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8553 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8555 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8556 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8558 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8559 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8560 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8561 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8562 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8563 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8564 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8565 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8566 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8567 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8568 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8569 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8570 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8571 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8572 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8573 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8574 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8575 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8576 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8577 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8578 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8579 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8580 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8581 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>'
8582 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>'
8583 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>'
8584 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8585 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>'
8586 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>'
8587 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 +01008588 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 +02008589 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8590 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008591 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008592 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8593 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008594
8595 elseif !a:domenu
8596 let s:netrwcnt = 0
8597 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008598 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008599 exe curwin."wincmd w"
8600
8601 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008602" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008603 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008604" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008605 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008606 endif
8607 endif
8608" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008609 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008610 endif
8611
8612endfun
8613
8614" ---------------------------------------------------------------------
8615" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8616" Used by the O maps (as <SID>NetrwObtain())
8617fun! s:NetrwObtain(islocal)
8618" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8619
Bram Moolenaar97d62492012-11-15 21:28:22 +01008620 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008621 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008622 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008623 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008624 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8625 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008626 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008627 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008628 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008629
8630" call Dret("NetrwObtain")
8631endfun
8632
8633" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008634" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8635" If there's only one window, then the window will first be split.
8636" Returns:
8637" choice = 0 : didn't have to choose
8638" choice = 1 : saved modified file in window first
8639" choice = 2 : didn't save modified file, opened window
8640" choice = 3 : cancel open
8641fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008642" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643
Bram Moolenaar97d62492012-11-15 21:28:22 +01008644 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008646 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008647" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008648
8649 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008650 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008651 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008652" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8653" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8654 let curword = s:NetrwGetWord()
8655 let choice = 0
8656 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8657" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008658 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008659" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008660 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008661" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008662" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008663" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008664
Bram Moolenaar8d043172014-01-23 14:24:41 +01008665 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008666 if lastwinnr == 1
8667 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008668" 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 +02008669 " g:netrw_preview=0: preview window shown in a horizontally split window
8670 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008671 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008672 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008673 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008674" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008675 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008676 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008677 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008678 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008679" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008680 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008681 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008682 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008683" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008684
8685 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008686" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008687 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008688" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008689 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008690" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008691 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008692" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008693 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008694" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008695" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008696" call Decho("COMBAK#12: mod=".&mod)
8697
8698 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8699 " whoops -- user trying to open file in the Lexplore window.
8700 " Use Lexplore's opening-file window instead.
8701" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8702" exe g:netrw_chgwin."wincmd w"
8703 wincmd p
8704 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8705 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008706
8707 " prevwinnr: the window number of the "prev" window
8708 " prevbufnr: the buffer number of the buffer in the "prev" window
8709 " bnrcnt : the qty of windows open on the "prev" buffer
8710 let prevwinnr = winnr()
8711 let prevbufnr = bufnr("%")
8712 let prevbufname = bufname("%")
8713 let prevmod = &mod
8714 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008715" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008716 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008717" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008718" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008719
8720 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008721 " and it doesn't appear in any other extant window, then ask the
8722 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008723 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008724" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008725 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008726" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008727 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008728" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008729
8730 if bnrcnt == 1 && &hidden == 0
8731 " only one copy of the modified buffer in a window, and
8732 " hidden not set, so overwriting will lose the modified file. Ask first...
8733 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008734" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008735 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008736" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008737
8738 if choice == 1
8739 " Yes -- write file & then browse
8740 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008741 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008742 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008743 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008744 exe origwin."wincmd w"
8745 let &ei = eikeep
8746 let @@ = ykeep
8747" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008748 return choice
8749 endif
8750
8751 elseif choice == 2
8752 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008753" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008754 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008755
8756 else
8757 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008758" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008759 exe origwin."wincmd w"
8760 let &ei= eikeep
8761 let @@ = ykeep
8762" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008763 return choice
8764 endif
8765 endif
8766 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008767 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008768 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008769" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770
8771 " restore b:netrw_curdir (window split/enew may have lost it)
8772 let b:netrw_curdir= curdir
8773 if a:islocal < 2
8774 if a:islocal
8775 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8776 else
8777 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8778 endif
8779 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008780 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008781" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008782 return choice
8783endfun
8784
8785" ---------------------------------------------------------------------
8786" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8787" Always assumed to be local -> remote
8788" call s:NetrwUpload(filename, target)
8789" call s:NetrwUpload(filename, target, fromdirectory)
8790fun! s:NetrwUpload(fname,tgt,...)
8791" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8792
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008793 if a:tgt =~ '^\a\{3,}://'
8794 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008795 else
8796 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8797 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008798" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008799
8800 if a:0 > 0
8801 let fromdir= a:1
8802 else
8803 let fromdir= getcwd()
8804 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008805" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008806
8807 if type(a:fname) == 1
8808 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008809" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008810 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008811" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8812 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8813" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008814 if a:tgt =~ '/$'
8815 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008816" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008817 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008818 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008819" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008820 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008821" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008822 endif
8823 q!
8824
8825 elseif type(a:fname) == 3
8826 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008827" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008828 let curdir= getcwd()
8829 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008830 if s:NetrwLcd(fromdir)
8831" call Dret("s:NetrwUpload : lcd failure")
8832 return
8833 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008834 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008835 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008836 if exists("g:netrw_port") && g:netrw_port != ""
8837 let useport= " ".g:netrw_scpport." ".g:netrw_port
8838 else
8839 let useport= ""
8840 endif
8841 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8842 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008843 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 +02008844 if s:NetrwLcd(curdir)
8845" call Dret("s:NetrwUpload : lcd failure")
8846 return
8847 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008848
8849 elseif a:tgt =~ '^ftp:'
8850 call s:NetrwMethod(a:tgt)
8851
8852 if b:netrw_method == 2
8853 " handle uploading a list of files via ftp+.netrc
8854 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008855 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008856" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008857
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008858 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008859" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008860
8861 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008862 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008863" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008864 endif
8865
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008866 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008867" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008868
Bram Moolenaaradc21822011-04-01 18:03:16 +02008869 if tgtdir == ""
8870 let tgtdir= '/'
8871 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008872 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008873" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008874
8875 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008876 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8877" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008878 endfor
8879
8880 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008881 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 +00008882 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008883" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8884 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008885 endif
8886 " 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 +01008887 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008888 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008889 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8890 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8891 else
8892 bw!|q
8893 endif
8894
8895 elseif b:netrw_method == 3
8896 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8897 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008898 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008899 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008900 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008901
8902 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008903 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008904" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008905 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008906 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008907" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008908 endif
8909
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008910 if exists("g:netrw_uid") && g:netrw_uid != ""
8911 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008912 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008913" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008914 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008915 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008916 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008917" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008918 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008919 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008920" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008921 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008922 endif
8923
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008924 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008925" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008926
8927 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008928 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008929" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008930 endif
8931
8932 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008933 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008934" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008935 endif
8936
8937 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008938 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008939" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008940 endfor
8941
8942 " perform ftp:
8943 " -i : turns off interactive prompting from ftp
8944 " -n unix : DON'T use <.netrc>, even though it exists
8945 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008946 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008947 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008948 " 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 +01008949 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008950 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008951 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8952 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008953 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008954 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8955 let &debug = debugkeep
8956 let mod = 1
8957 else
8958 bw!|q
8959 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008960 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008961" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008962 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008963 endif
8964 else
8965 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8966 endif
8967 endif
8968
8969" call Dret("s:NetrwUpload")
8970endfun
8971
8972" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008973" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008974fun! s:NetrwPreview(path) range
8975" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008976" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8977" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008978 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008979 NetrwKeepj call s:NetrwOptionsSave("s:")
8980 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8981 NetrwKeepj call s:NetrwOptionsSafe(1)
8982 else
8983 NetrwKeepj call s:NetrwOptionsSafe(0)
8984 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008985 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008986" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008987 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008988" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8989 if g:netrw_preview
8990 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008991 let pvhkeep = &pvh
8992 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8993 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008994" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8995 else
8996 " horizontal split
8997 let pvhkeep = &pvh
8998 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8999 let &pvh = winheight(0) - winsz
9000" 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 +02009001 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009002 " g:netrw_preview g:netrw_alto
9003 " 1 : vert 1: top -- preview window is vertically split off and on the left
9004 " 1 : vert 0: bot -- preview window is vertically split off and on the right
9005 " 0 : 1: top -- preview window is horizontally split off and on the top
9006 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
9007 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009008 " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowseCheck() check via
Bram Moolenaar85850f32019-07-19 22:05:51 +02009009 " the BufEnter event set up in netrwPlugin.vim
9010" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
9011 let eikeep = &ei
9012 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009013 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009014 let &ei= eikeep
9015" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009016 if exists("pvhkeep")
9017 let &pvh= pvhkeep
9018 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009019 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009020 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009021 endif
9022 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009023 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 +00009024 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009025 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009026 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009027" call Dret("NetrwPreview")
9028endfun
9029
9030" ---------------------------------------------------------------------
9031" s:NetrwRefresh: {{{2
9032fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009033" 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 +00009034 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009035 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009036" call Decho("setl ma noro",'~'.expand("<slnum>"))
9037" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009038 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009039 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9040 if !exists("w:netrw_treetop")
9041 if exists("b:netrw_curdir")
9042 let w:netrw_treetop= b:netrw_curdir
9043 else
9044 let w:netrw_treetop= getcwd()
9045 endif
9046 endif
9047 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9048 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009049
9050 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009051 let screenposn = winsaveview()
9052" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009053
9054" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9055" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9056 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009057 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009058 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009059 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009060 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009061 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009062
9063 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009064" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9065 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009066
9067 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009068 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9069 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9070" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9071 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9072 else
9073" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9074 2match none
9075 endif
9076 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009077
Bram Moolenaar97d62492012-11-15 21:28:22 +01009078" restore
9079 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009080" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009081endfun
9082
9083" ---------------------------------------------------------------------
9084" s:NetrwRefreshDir: refreshes a directory by name {{{2
9085" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009086" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009087fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009088" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009089 if g:netrw_fastbrowse == 0
9090 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009091" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009092 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009093" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009094
9095 if tgtwin > 0
9096 " tgtwin is being displayed, so refresh it
9097 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009098" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009099 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009100 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009101 exe curwin."wincmd w"
9102
9103 elseif bufnr(a:dirname) > 0
9104 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009105" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9106 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009107 endif
9108
9109 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009110" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009111 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009112 endif
9113" call Dret("s:NetrwRefreshDir")
9114endfun
9115
9116" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009117" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9118" window number to do its editing in.
9119" Supports [count]C where the count, if present, is used to specify
9120" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009121fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009122" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009123 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009124" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009125 if a:1 == "" " :NetrwC win#
9126 let g:netrw_chgwin= winnr()
9127 else " :NetrwC
9128 let g:netrw_chgwin= a:1
9129 endif
9130 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009131 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009132 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009133 let g:netrw_chgwin= winnr()
9134 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009135 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009136" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009137endfun
9138
9139" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009140" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9141" What this function does is to compute a priority for the patterns
9142" in the g:netrw_sort_sequence. It applies a substitute to any
9143" "files" that satisfy each pattern, putting the priority / in
9144" front. An "*" pattern handles the default priority.
9145fun! s:NetrwSetSort()
9146" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009147 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009148 if w:netrw_liststyle == s:LONGLIST
9149 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9150 else
9151 let seqlist = g:netrw_sort_sequence
9152 endif
9153 " sanity check -- insure that * appears somewhere
9154 if seqlist == ""
9155 let seqlist= '*'
9156 elseif seqlist !~ '\*'
9157 let seqlist= seqlist.',*'
9158 endif
9159 let priority = 1
9160 while seqlist != ""
9161 if seqlist =~ ','
9162 let seq = substitute(seqlist,',.*$','','e')
9163 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9164 else
9165 let seq = seqlist
9166 let seqlist = ""
9167 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009168 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009169 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009170 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009171 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009172 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009173 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009174 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009175" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009176
9177 " sanity check
9178 if w:netrw_bannercnt > line("$")
9179 " apparently no files were left after a Hiding pattern was used
9180" call Dret("SetSort : no files left after hiding")
9181 return
9182 endif
9183 if seq == '*'
9184 let starpriority= spriority
9185 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009186 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009187 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009188 " sometimes multiple sorting patterns will match the same file or directory.
9189 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009190 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9191 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009192 endif
9193 let priority = priority + 1
9194 endwhile
9195 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009196 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9197 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009198 endif
9199
9200 " Following line associated with priority -- items that satisfy a priority
9201 " pattern get prefixed by ###/ which permits easy sorting by priority.
9202 " Sometimes files can satisfy multiple priority patterns -- only the latest
9203 " priority pattern needs to be retained. So, at this point, these excess
9204 " priority prefixes need to be removed, but not directories that happen to
9205 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009206 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9207 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009208 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009209
9210" call Dret("SetSort")
9211endfun
9212
Bram Moolenaarff034192013-04-24 18:51:19 +02009213" ---------------------------------------------------------------------
9214" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9215" Implements [count]Tb (bookhist<b>)
9216" [count]Th (bookhist<h>)
9217" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009218fun! s:NetrwSetTgt(islocal,bookhist,choice)
9219" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009220
9221 if a:bookhist == 'b'
9222 " supports choosing a bookmark as a target using a qb-generated list
9223 let choice= a:choice - 1
9224 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009225 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009226 else
9227 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9228 endif
9229
9230 elseif a:bookhist == 'h'
9231 " supports choosing a history stack entry as a target using a qb-generated list
9232 let choice= (a:choice % g:netrw_dirhistmax) + 1
9233 if exists("g:netrw_dirhist_".choice)
9234 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009235 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009236 else
9237 echomsg "Sorry, history#".a:choice." not available!"
9238 endif
9239 endif
9240
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009241 " refresh the display
9242 if !exists("b:netrw_curdir")
9243 let b:netrw_curdir= getcwd()
9244 endif
9245 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9246
Bram Moolenaarff034192013-04-24 18:51:19 +02009247" call Dret("s:NetrwSetTgt")
9248endfun
9249
Bram Moolenaar446cb832008-06-24 21:56:24 +00009250" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009251" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009252fun! s:NetrwSortStyle(islocal)
9253" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009254 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009255 let svpos= winsaveview()
9256" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009257
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009258 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 +01009259 NetrwKeepj norm! 0
9260 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009261" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9262 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009263
9264" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9265endfun
9266
9267" ---------------------------------------------------------------------
9268" s:NetrwSplit: mode {{{2
9269" =0 : net and o
9270" =1 : net and t
9271" =2 : net and v
9272" =3 : local and o
9273" =4 : local and t
9274" =5 : local and v
9275fun! s:NetrwSplit(mode)
9276" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9277
Bram Moolenaar97d62492012-11-15 21:28:22 +01009278 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009279 call s:SaveWinVars()
9280
9281 if a:mode == 0
9282 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009283 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009284 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009285" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009286 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009287 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009288 NetrwKeepj call s:RestoreWinVars()
9289 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009290 unlet s:didsplit
9291
9292 elseif a:mode == 1
9293 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009294 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009295" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009296 tabnew
9297 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009298 NetrwKeepj call s:RestoreWinVars()
9299 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009300 unlet s:didsplit
9301
9302 elseif a:mode == 2
9303 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009304 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009305 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009306" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009307 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009308 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009309 NetrwKeepj call s:RestoreWinVars()
9310 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009311 unlet s:didsplit
9312
9313 elseif a:mode == 3
9314 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009315 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009316 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009317" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009318 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009319 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009320 NetrwKeepj call s:RestoreWinVars()
9321 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009322 unlet s:didsplit
9323
9324 elseif a:mode == 4
9325 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009326 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009327 let eikeep = &ei
9328 let netrw_winnr = winnr()
9329 let netrw_line = line(".")
9330 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009331 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009332 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009333 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009334 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9335 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009336 let &ei = eikeep
9337 let netrw_curdir = s:NetrwTreeDir(0)
9338" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009339 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009340 let b:netrw_curdir = netrw_curdir
9341 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009342 NetrwKeepj call s:RestoreWinVars()
9343 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009344 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009345 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009346 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9347 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009348 let &ei= eikeep
9349 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009350 unlet s:didsplit
9351
9352 elseif a:mode == 5
9353 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009354 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009355 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009356" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009357 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009358 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009359 NetrwKeepj call s:RestoreWinVars()
9360 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009361 unlet s:didsplit
9362
9363 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009364 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009365 endif
9366
Bram Moolenaar97d62492012-11-15 21:28:22 +01009367 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009368" call Dret("s:NetrwSplit")
9369endfun
9370
9371" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009372" s:NetrwTgtMenu: {{{2
9373fun! s:NetrwTgtMenu()
9374 if !exists("s:netrw_menucnt")
9375 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009376 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009377" call Dfunc("s:NetrwTgtMenu()")
9378
9379 " the following test assures that gvim is running, has menus available, and has menus enabled.
9380 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9381 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009382" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009383 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9384 endif
9385 if !exists("s:netrw_initbookhist")
9386 call s:NetrwBookHistRead()
9387 endif
9388
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009389 " try to cull duplicate entries
9390 let tgtdict={}
9391
Bram Moolenaarff034192013-04-24 18:51:19 +02009392 " target bookmarked places
9393 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009394" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009395 let cnt= 1
9396 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009397 if has_key(tgtdict,bmd)
9398 let cnt= cnt + 1
9399 continue
9400 endif
9401 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009402 let ebmd= escape(bmd,g:netrw_menu_escape)
9403 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009404" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009405 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 +02009406 let cnt= cnt + 1
9407 endfor
9408 endif
9409
9410 " target directory browsing history
9411 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009412" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009413 let histcnt = 1
9414 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009415 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009416 if exists("g:netrw_dirhist_{histcnt}")
9417 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009418 if has_key(tgtdict,histentry)
9419 let histcnt = histcnt + 1
9420 continue
9421 endif
9422 let tgtdict[histentry] = histcnt
9423 let ehistentry = escape(histentry,g:netrw_menu_escape)
9424" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009425 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 +02009426 endif
9427 let histcnt = histcnt + 1
9428 endwhile
9429 endif
9430 endif
9431" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009432endfun
9433
9434" ---------------------------------------------------------------------
9435" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9436" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009437fun! s:NetrwTreeDir(islocal)
9438" 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 Moolenaar1d59aa12020-09-19 18:50:13 +02009439" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009440" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9441" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9442" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009443" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009444
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009445 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009446 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009447" call Decho('s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early')
Bram Moolenaar8d043172014-01-23 14:24:41 +01009448 let treedir= s:treedir
9449 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009450 unlet s:prevwinopen
9451" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009452 return treedir
9453 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009454 if exists("s:prevwinopen")
9455 unlet s:prevwinopen
9456 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009457" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009458
Bram Moolenaar8d043172014-01-23 14:24:41 +01009459 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9460 let b:netrw_curdir= getcwd()
9461 endif
9462 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009463" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009464" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009465
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009466 let s:treecurpos= winsaveview()
9467" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009468" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009469
9470 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009471" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9472" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009473" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009474
9475 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009476 let curline= substitute(getline('.'),"\t -->.*$",'','')
9477 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009478" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009479 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009480" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9481 elseif curline =~ '@$'
9482" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009483 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009484" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009485 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009486" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009487 let treedir= ""
9488 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009489" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009490
9491 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009492" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9493" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009494" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009495 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009496" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009497 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009498" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9499 sil! NetrwKeepj %d _
9500" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009501 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009502" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009503" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009504 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009505" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009506
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009507" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009508" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009509" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009510
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009511 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9512" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9513" let newdir = w:netrw_treetop.'/'.potentialdir
9514" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9515" let treedir = s:NetrwTreePath(newdir)
9516" let w:netrw_treetop = newdir
9517" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9518" else
9519" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009520 if a:islocal && curline =~ '@$'
9521 if isdirectory(s:NetrwFile(potentialdir))
9522 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9523 let w:netrw_treetop = treedir
9524 endif
9525 else
9526 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9527 let treedir = s:NetrwTreePath(w:netrw_treetop)
9528 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009529 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009530" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009531
9532 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009533 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009534" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009535" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009536
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009537" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009538 return treedir
9539endfun
9540
9541" ---------------------------------------------------------------------
9542" s:NetrwTreeDisplay: recursive tree display {{{2
9543fun! s:NetrwTreeDisplay(dir,depth)
9544" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9545
9546 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009547 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009548
9549 " install ../ and shortdir
9550 if a:depth == ""
9551 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009552" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009553 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009554 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009555 if a:dir == w:netrw_treetop
9556 let shortdir= a:dir
9557 else
9558 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9559 endif
9560 call setline(line("$")+1,a:depth.shortdir)
9561 else
9562 let shortdir= substitute(a:dir,'^.*/','','e')
9563 call setline(line("$")+1,a:depth.shortdir.'/')
9564 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009565" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009566 " append a / to dir if its missing one
9567 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009568
9569 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009570 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009571" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009572
Bram Moolenaar85850f32019-07-19 22:05:51 +02009573 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9574 if g:netrw_hide == 1
9575 " hide given patterns
9576 let listhide= split(g:netrw_list_hide,',')
9577" call Decho("listhide=".string(listhide))
9578 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009579 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009580 endfor
9581
9582 elseif g:netrw_hide == 2
9583 " show given patterns (only)
9584 let listhide= split(g:netrw_list_hide,',')
9585" call Decho("listhide=".string(listhide))
9586 let entries=[]
9587 for entry in w:netrw_treedict[dir]
9588 for pat in listhide
9589 if entry =~ pat
9590 call add(entries,entry)
9591 break
9592 endif
9593 endfor
9594 endfor
9595 let w:netrw_treedict[dir]= entries
9596 endif
9597 if depth != ""
9598 " always remove "." and ".." entries when there's depth
9599 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9600 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9601 endif
9602
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009603" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009604 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009605 if dir =~ '/$'
9606 let direntry= substitute(dir.entry,'[@/]$','','e')
9607 else
9608 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9609 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009610" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009611 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009612" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009613 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009614 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009615" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9616 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9617 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9618" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009619 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009620 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009621" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009622 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009623 endif
9624 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009625" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009626
Bram Moolenaar446cb832008-06-24 21:56:24 +00009627" call Dret("NetrwTreeDisplay")
9628endfun
9629
9630" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009631" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9632fun! s:NetrwRefreshTreeDict(dir)
9633" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009634 if !exists("w:netrw_treedict")
9635" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9636 return
9637 endif
9638
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009639 for entry in w:netrw_treedict[a:dir]
9640 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9641" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9642
9643 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9644" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9645 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009646 let liststar = s:NetrwGlob(direntry,'*',1)
9647 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009648 let w:netrw_treedict[direntry] = liststar + listdotstar
9649" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9650
9651 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9652" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9653 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009654 let liststar = s:NetrwGlob(direntry.'/','*',1)
9655 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009656 let w:netrw_treedict[direntry]= liststar + listdotstar
9657" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9658
9659 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9660" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9661 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009662 let liststar = s:NetrwGlob(direntry.'/','*',1)
9663 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009664" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9665
9666 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009667" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009668 endif
9669 endfor
9670" call Dret("s:NetrwRefreshTreeDict")
9671endfun
9672
9673" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009674" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009675" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009676fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009677 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009678" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009679" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9680" 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>"))
9681" 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 +00009682
9683 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009684 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009685" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009686 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009687 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009688" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009689 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009690" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009691 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009692 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009693" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009694 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009695 if exists("w:netrw_treetop")
9696 let s:netrw_treetop= w:netrw_treetop
9697 else
9698 let w:netrw_treetop= getcwd()
9699 let s:netrw_treetop= w:netrw_treetop
9700 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009701
Bram Moolenaar446cb832008-06-24 21:56:24 +00009702 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009703 " insure that we have a treedict, albeit empty
9704" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009705 let w:netrw_treedict= {}
9706 endif
9707
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009708 " update the dictionary for the current directory
9709" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009710" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009711 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009712 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009713" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009714 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009715
9716 " if past banner, record word
9717 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9718 let fname= expand("<cword>")
9719 else
9720 let fname= ""
9721 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009722" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9723" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009724
9725 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009726" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009727 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009728" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009729
9730 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9731 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009732" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009733 1d
9734 endwhile
9735
Bram Moolenaar13600302014-05-22 18:26:40 +02009736 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009737
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009738" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009739 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009740 endif
9741endfun
9742
9743" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009744" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009745" Normally, treetop is w:netrw_treetop, but a
9746" user of the function ( netrw#SetTreetop() )
9747" wipes that out prior to calling this function
9748fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009749" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9750 if line(".") < w:netrw_bannercnt + 2
9751 let treedir= a:treetop
9752 if treedir !~ '/$'
9753 let treedir= treedir.'/'
9754 endif
9755" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9756 return treedir
9757 endif
9758
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009759 let svpos = winsaveview()
9760" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009761 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009762" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009763 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009764" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9765 let curline= getline('.')
9766" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9767 if curline =~ '/$'
9768" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9769 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9770" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9771 elseif curline =~ '@\s\+-->'
9772" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9773 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9774 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9775" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009776 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009777" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009778 let treedir= ""
9779 endif
9780 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009781" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9782" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009783 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9784 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9785 let treedir= dirname.treedir
9786 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009787" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009788 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009789" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009790 if a:treetop =~ '/$'
9791 let treedir= a:treetop.treedir
9792 else
9793 let treedir= a:treetop.'/'.treedir
9794 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009795" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009796 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009797" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009798" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9799 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009800" call Dret("s:NetrwTreePath <".treedir.">")
9801 return treedir
9802endfun
9803
9804" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009805" s:NetrwWideListing: {{{2
9806fun! s:NetrwWideListing()
9807
9808 if w:netrw_liststyle == s:WIDELIST
9809" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9810 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009811 " cpf: characters per filename
9812 " fpl: filenames per line
9813 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009814 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009815 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009816" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009817 let b:netrw_cpf= 0
9818 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009819 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009820 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9821 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009822 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009823 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009824" call Dret("NetrwWideListing")
9825 return
9826 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009827 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009828 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009829" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009830
9831 " determine qty files per line (fpl)
9832 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9833 if w:netrw_fpl <= 0
9834 let w:netrw_fpl= 1
9835 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009836" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009837
9838 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009839 " fpc: files per column of wide listing
9840 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009841 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009842 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9843 let newcolstart = w:netrw_bannercnt + fpc
9844 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009845" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009846 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009847" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009848 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009849 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009850 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009851 while line("$") >= newcolstart
9852 if newcolend > line("$") | let newcolend= line("$") | endif
9853 let newcolqty= newcolend - newcolstart
9854 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009855 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009856 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009857 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009858 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009859 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009860 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009861 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009862 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009863 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009864 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009865" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009866 if @* != keepregstar | sil! let @* = keepregstar | endif
9867 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009868 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009869 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9870 NetrwKeepj call histdel("/",-1)
9871 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9872 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009873" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009874 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009875 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009876" 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 +00009877" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009878 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009879 else
9880 if hasmapto("w","n")
9881 sil! nunmap <buffer> w
9882 endif
9883 if hasmapto("b","n")
9884 sil! nunmap <buffer> b
9885 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009886 endif
9887
9888endfun
9889
9890" ---------------------------------------------------------------------
9891" s:PerformListing: {{{2
9892fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009893" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9894" 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 +02009895" 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>"))
9896 sil! NetrwKeepj %d _
9897" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009898
Bram Moolenaar15146672011-10-20 22:22:38 +02009899 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009900" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009901 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009902
Bram Moolenaar85850f32019-07-19 22:05:51 +02009903 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009904 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009905" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009906
9907" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009908" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009909" endif " Decho
9910
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009911" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009912 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9913 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009914" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9915 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009916 endif
9917
9918 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009919 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009920
9921 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009922 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009923" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009924 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009925 if exists("g:netrw_pchk")
9926 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9927 " failure detections.
9928 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009929 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009930 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9931 endif
9932 if exists("g:netrw_pchk")
9933 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9934 else
9935 let curdir= b:netrw_curdir
9936 endif
9937 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9938 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9939 else
9940 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009941 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009942 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009943 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009944 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009945" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009946 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009947 let w:netrw_bannercnt= 1
9948 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009949" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9950" 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 +00009951
Bram Moolenaar85850f32019-07-19 22:05:51 +02009952 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009953 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009954 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009955 let sortby= sortby." reversed"
9956 endif
9957
9958 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009959 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009960" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009961 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009962" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009963 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009964 NetrwKeepj put ='\" Sorted by '.sortby
9965 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009966 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9967 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009968" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009969 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009970 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009971 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9972 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009973 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009974" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009975" 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 +00009976 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009977
Bram Moolenaar85850f32019-07-19 22:05:51 +02009978 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009979 if g:netrw_banner
9980 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009981" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009982 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009983 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009984 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009985 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009986 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009987 endif
9988 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009989 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009990" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009991 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009992 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009993 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009994
9995 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009996 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009997" call Decho("--handle hiding/showing in banner (g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009998 if g:netrw_list_hide != "" && g:netrw_hide
9999 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010000 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +010010001 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010002 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +010010003 endif
10004 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010005 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010006 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010007
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010008" 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 +010010009 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010010" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010011 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010012" 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 +010010013 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +010010014 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +010010015" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010016" 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 +000010017 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018
10019 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +010010020 if g:netrw_banner
10021 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010022 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010023" 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 +010010024" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010025" 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 +010010026 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010027
Bram Moolenaar446cb832008-06-24 21:56:24 +000010028 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010029" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010030 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010031 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010033 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010034 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010035" 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 +010010036" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10037 return
10038 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010039 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010040
10041 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010042 if !exists("w:netrw_bannercnt")
10043 let w:netrw_bannercnt= 0
10044 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010045" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10046" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10047" 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 +010010048
Bram Moolenaar5c736222010-01-06 20:54:52 +010010049 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010050" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010051" 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 +000010052 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010053 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010054 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010055 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010056" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010057
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010058 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010059 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010060" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010061 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010062
Bram Moolenaar5c736222010-01-06 20:54:52 +010010063 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010064" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010065 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010066 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010067 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010068 else
10069 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010070 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010071 endif
10072 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010073
Bram Moolenaar446cb832008-06-24 21:56:24 +000010074 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010075" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010076 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10077 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010078
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010079 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010080 " exten: sort by extension
10081 " The histdel(...,-1) calls remove the last search from the search history
10082" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010083 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10084 NetrwKeepj call histdel("/",-1)
10085 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10086 NetrwKeepj call histdel("/",-1)
10087 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10088 NetrwKeepj call histdel("/",-1)
10089 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10090" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010091 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010092 " normal direction sorting
10093 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10094 else
10095 " reverse direction sorting
10096 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10097 endif
10098 endif
10099 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10100 NetrwKeepj call histdel("/",-1)
10101
Bram Moolenaar446cb832008-06-24 21:56:24 +000010102 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010103 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010104" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010105 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010106" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010107 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010108 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010109" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010110 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010111 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010112" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010113 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10114 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010115 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010116 endif
10117
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010118 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010119" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010120 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010121 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010122 call histdel("/",-1)
10123 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010124 endif
10125 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010126" 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 +000010127
10128 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010129" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10130" 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 +010010131 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010132" 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 +010010133 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010134" 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 +000010135
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010136 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010137 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010138" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010139 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010140 endif
10141
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010142 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010143 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010144" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10145 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010146 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010147" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10148 else
10149" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10150" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10151" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10152" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010153 endif
10154
10155 " record previous current directory
10156 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010157" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010158
10159 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010160" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10161" 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 +010010162 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010163" 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 +020010164 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010165" 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 +000010166
10167 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010168" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010169 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010170" 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 +010010171 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010172" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010173 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10174 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010175" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010176" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010177
Bram Moolenaar8d043172014-01-23 14:24:41 +010010178 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010179" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10180" 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 +010010181" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10182 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010183 unlet s:treecurpos
10184 endif
10185
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010186" 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>"))
10187" 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 +000010188" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10189endfun
10190
10191" ---------------------------------------------------------------------
10192" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010193fun! s:SetupNetrwStatusLine(statline)
10194" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10195
10196 if !exists("s:netrw_setup_statline")
10197 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010198" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010199
10200 if !exists("s:netrw_users_stl")
10201 let s:netrw_users_stl= &stl
10202 endif
10203 if !exists("s:netrw_users_ls")
10204 let s:netrw_users_ls= &laststatus
10205 endif
10206
10207 " set up User9 highlighting as needed
10208 let keepa= @a
10209 redir @a
10210 try
10211 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010212 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010213 if &bg == "dark"
10214 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10215 else
10216 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10217 endif
10218 endtry
10219 redir END
10220 let @a= keepa
10221 endif
10222
10223 " set up status line (may use User9 highlighting)
10224 " insure that windows have a statusline
10225 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010226 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010227 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010228" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010229 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010230
10231" call Dret("SetupNetrwStatusLine : stl=".&stl)
10232endfun
10233
Bram Moolenaar85850f32019-07-19 22:05:51 +020010234" =========================================
10235" Remote Directory Browsing Support: {{{1
10236" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010237
10238" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010239" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10240" This function assumes that a long listing will be received. Size, time,
10241" and reverse sorts will be requested of the server but not otherwise
10242" enforced here.
10243fun! s:NetrwRemoteFtpCmd(path,listcmd)
10244" 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 +010010245" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010246 " sanity check: {{{3
10247 if !exists("w:netrw_method")
10248 if exists("b:netrw_method")
10249 let w:netrw_method= b:netrw_method
10250 else
10251 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10252" call Dret("NetrwRemoteFtpCmd")
10253 return
10254 endif
10255 endif
10256
10257 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10258 let ffkeep= &ff
10259 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010260" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010261
10262 " clear off any older non-banner lines " {{{3
10263 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010264" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10265 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010266
10267 ".........................................
10268 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10269 " ftp + <.netrc>: Method #2
10270 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010271 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010272 endif
10273 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010274 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010275" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010276 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010277 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010278" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010279 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010280" 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>"))
10281 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 +010010282 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010283" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10284 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 +010010285 endif
10286
10287 ".........................................
10288 elseif w:netrw_method == 3 " {{{3
10289 " ftp + machine,id,passwd,filename: Method #3
10290 setl ff=unix
10291 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010292 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010293 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010294 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010295 endif
10296
10297 " handle userid and password
10298 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010299" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010300 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10301 call NetUserPass("ftp:".host)
10302 endif
10303 if exists("g:netrw_uid") && g:netrw_uid != ""
10304 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010305 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010306 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010307 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010308 endif
10309 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010310 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010311 endif
10312 endif
10313
10314 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010315 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010316 endif
10317 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010318 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010319" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010320 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010321 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010322
10323 " perform ftp:
10324 " -i : turns off interactive prompting from ftp
10325 " -n unix : DON'T use <.netrc>, even though it exists
10326 " -n win32: quit being obnoxious about password
10327 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010328" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010329 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010330" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010331" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10332" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010333 endif
10334
10335 ".........................................
10336 elseif w:netrw_method == 9 " {{{3
10337 " sftp username@machine: Method #9
10338 " s:netrw_sftp_cmd
10339 setl ff=unix
10340
10341 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010342 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010343" call Dret("NetrwRemoteFtpCmd")
10344 return
10345
10346 ".........................................
10347 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010348 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010349 endif
10350
10351 " cleanup for Windows " {{{3
10352 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010353 sil! NetrwKeepj %s/\r$//e
10354 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010355 endif
10356 if a:listcmd == "dir"
10357 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010358 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10359 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10360 NetrwKeepj call histdel("/",-1)
10361 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010362 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 +010010363 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10364 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010365 endif
10366 endif
10367
10368 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10369 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010370 exe 'NetrwKeepj '.w:netrw_bannercnt
10371 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010372 endif
10373 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010374 exe 'NetrwKeepj '.w:netrw_bannercnt
10375 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010376 endif
10377
10378 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010379 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010380" call Dret("NetrwRemoteFtpCmd")
10381endfun
10382
10383" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010384" s:NetrwRemoteListing: {{{2
10385fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010386" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010387
Bram Moolenaara6878372014-03-22 21:02:50 +010010388 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10389 let w:netrw_bannercnt= s:bannercnt
10390 endif
10391 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010392 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010393 endif
10394
Bram Moolenaar446cb832008-06-24 21:56:24 +000010395 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010396
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 " sanity check:
10398 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010399" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010400 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010401" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010402 if !exists("g:netrw_quiet")
10403 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10404 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010405 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010406" call Dret("s:NetrwRemoteListing -1")
10407 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010408 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010409
Bram Moolenaar8d043172014-01-23 14:24:41 +010010410 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010411" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010412 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010413 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010414 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 +000010415 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010416 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 +000010417 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010418 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010419
Bram Moolenaar85850f32019-07-19 22:05:51 +020010420 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010421" call Dret("s:NetrwRemoteListing -1")
10422 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010423 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010424" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010425
Bram Moolenaar446cb832008-06-24 21:56:24 +000010426 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010427" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010428 let w:netrw_method= b:netrw_method
10429 endif
10430
Bram Moolenaar13600302014-05-22 18:26:40 +020010431 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010432 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010433" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010434 let s:method = "ftp"
10435 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010436 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010437 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010438 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010439 let listcmd= g:netrw_ftp_sizelist_cmd
10440 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010441" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010442 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010443" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010444
Bram Moolenaara6878372014-03-22 21:02:50 +010010445 " report on missing file or directory messages
10446 if search('[Nn]o such file or directory\|Failed to change directory')
10447 let mesg= getline(".")
10448 if exists("w:netrw_bannercnt")
10449 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010450 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010451 setl noma
10452 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010453 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010454 call netrw#ErrorMsg(s:WARNING,mesg,96)
10455" call Dret("s:NetrwRemoteListing : -1")
10456 return -1
10457 endif
10458
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010459 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 +000010460 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010461" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010462 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010463
10464 " cleanup
10465 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010466 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10467 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010468 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010469 sil! NetrwKeepj %s/\r$//e
10470 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010471
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010472 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010473 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010474 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010475 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010476" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010477 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010478" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010479 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010480 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010481 exe "sil! NetrwKeepj ".line1
10482 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010483
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010484" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010485 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010486" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010487 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10488 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010490" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010491 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10492 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10493 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10494 NetrwKeepj call histdel("/",-1)
10495 NetrwKeepj call histdel("/",-1)
10496 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497 endif
10498 endif
10499
Bram Moolenaar13600302014-05-22 18:26:40 +020010500 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010501 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010502" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010503 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010504" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010505 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010506" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10507 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010508 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010509 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10510 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10511 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10512 NetrwKeepj call histdel("/",-1)
10513 NetrwKeepj call histdel("/",-1)
10514 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010515 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010516 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10517 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010518 endif
10519 else
10520 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010521" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010522 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010524" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10525 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10526" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010527 endif
10528 endif
10529
10530 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010531 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010532" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010533 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10534 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010535 endif
10536 endif
10537
10538 if w:netrw_liststyle == s:LONGLIST
10539 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010540" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010541
10542 if s:method == "ftp"
10543 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010544 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010545 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010546 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010547 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010548 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010549 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010550 sil! NetrwKeepj 1
10551 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010552 let line2= line(".")
10553 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010554 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010555 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010556 endif
10557 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010558 exe "sil! NetrwKeepj ".line1
10559 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010560 endif
10561
10562 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010563" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010564 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 +000010565 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010566" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010567 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010568 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010569 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10570 NetrwKeepj call histdel("/",-1)
10571 NetrwKeepj call histdel("/",-1)
10572 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573 endif
10574 endif
10575
10576" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010577" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010579
10580" call Dret("s:NetrwRemoteListing 0")
10581 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010582endfun
10583
Bram Moolenaar446cb832008-06-24 21:56:24 +000010584" ---------------------------------------------------------------------
10585" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10586fun! s:NetrwRemoteRm(usrhost,path) range
10587" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010588" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010589 let svpos= winsaveview()
10590" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010591
10592 let all= 0
10593 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10594 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010595" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596 for fname in s:netrwmarkfilelist_{bufnr("%")}
10597 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010598 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010599 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010600 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601 let all= 1
10602 endif
10603 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010604 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010605
10606 else
10607 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010608" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010609
10610 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010611 let keepsol = &l:sol
10612 setl nosol
10613 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010614
10615 " remove multiple files and directories
10616 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010617 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010618 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010619 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010620 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010621 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010622 let all= 1
10623 endif
10624 let ctr= ctr + 1
10625 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010626 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010627 endif
10628
10629 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010630" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010631 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010632" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10633 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010634
10635" call Dret("s:NetrwRemoteRm")
10636endfun
10637
10638" ---------------------------------------------------------------------
10639" s:NetrwRemoteRmFile: {{{2
10640fun! s:NetrwRemoteRmFile(path,rmfile,all)
10641" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10642
10643 let all= a:all
10644 let ok = ""
10645
10646 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10647 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010648" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010649 if !all
10650 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010651" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010652 call inputsave()
10653 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10654 call inputrestore()
10655 echohl NONE
10656 if ok == ""
10657 let ok="no"
10658 endif
10659 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010660 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010661 let all= 1
10662 endif
10663 endif
10664
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010665 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010666" 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 +000010667 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010669 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010670 if path =~ '^\a\{3,}://'
10671 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010672 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010673 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010674 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10675 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010676" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010677 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010678" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010679 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010680 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010681 let ok="q"
10682 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010683 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010684" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10685" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10686" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010687 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010688 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010689 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010690 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010691 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010692" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010693 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010694 if v:shell_error != 0
10695 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010696 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 +010010697 else
10698 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10699 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010700 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010701 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010702 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010703" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010704 endif
10705 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010706 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010707" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010708 endif
10709
10710 else
10711 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010712" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010713 if !all
10714 call inputsave()
10715 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10716 call inputrestore()
10717 if ok == ""
10718 let ok="no"
10719 endif
10720 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010721 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010722 let all= 1
10723 endif
10724 endif
10725
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010726 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010727 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010728 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010729 else
10730 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010731 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10732" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010733 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010734" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010735
10736 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010737" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10738 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10739" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010740 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010741" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010742
10743 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010744 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010745 endif
10746 endif
10747 endif
10748
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010749 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010750" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010751 endif
10752 endif
10753
10754" call Dret("s:NetrwRemoteRmFile ".ok)
10755 return ok
10756endfun
10757
10758" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010759" s:NetrwRemoteRename: rename a remote file or directory {{{2
10760fun! s:NetrwRemoteRename(usrhost,path) range
10761" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10762
10763 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010764 let svpos = winsaveview()
10765" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010766 let ctr = a:firstline
10767 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10768
10769 " rename files given by the markfilelist
10770 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10771 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010772" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010773 if exists("subfrom")
10774 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010775" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010776 else
10777 call inputsave()
10778 let newname= input("Moving ".oldname." to : ",oldname)
10779 call inputrestore()
10780 if newname =~ '^s/'
10781 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10782 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10783 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010784" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010785 endif
10786 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010787
Bram Moolenaar446cb832008-06-24 21:56:24 +000010788 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010789 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010790 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010791 let oldname= s:ShellEscape(a:path.oldname)
10792 let newname= s:ShellEscape(a:path.newname)
10793" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010794 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010795 endif
10796
10797 endfor
10798 call s:NetrwUnMarkFile(1)
10799
10800 else
10801
10802 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010803 let keepsol= &l:sol
10804 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010805 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010806 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010807
10808 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010809" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010810
10811 call inputsave()
10812 let newname= input("Moving ".oldname." to : ",oldname)
10813 call inputrestore()
10814
10815 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10816 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10817 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010818 let oldname= s:ShellEscape(a:path.oldname)
10819 let newname= s:ShellEscape(a:path.newname)
10820" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010821 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010822 endif
10823
10824 let ctr= ctr + 1
10825 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010826 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010827 endif
10828
10829 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010830 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010831" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10832 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010833
10834" call Dret("NetrwRemoteRename")
10835endfun
10836
Bram Moolenaar85850f32019-07-19 22:05:51 +020010837" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010838" Local Directory Browsing Support: {{{1
10839" ==========================================
10840
10841" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010842" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010843" Should accept: file://localhost/etc/fstab
10844" file:///etc/fstab
10845" file:///c:/WINDOWS/clock.avi
10846" file:///c|/WINDOWS/clock.avi
10847" file://localhost/c:/WINDOWS/clock.avi
10848" file://localhost/c|/WINDOWS/clock.avi
10849" file://c:/foo.txt
10850" file:///c:/foo.txt
10851" 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 +020010852fun! netrw#FileUrlEdit(fname)
10853" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010854 let fname = a:fname
10855 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010856" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010857 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010858" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010859 endif
10860 if (has("win32") || has("win95") || has("win64") || has("win16"))
10861 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010862" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010863 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010864" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010865 endif
10866 endif
10867 let fname2396 = netrw#RFC2396(fname)
10868 let fname2396e= fnameescape(fname2396)
10869 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10870 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010871" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010872 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010873" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010874 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10875 endif
10876 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010877
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010878" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10879" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010880 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010881 exe 'NetrwKeepj keepalt edit '.plainfname
10882 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10883
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010884" 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 +020010885" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010886 exe "sil doau BufReadPost ".fname2396e
10887endfun
10888
10889" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010890" netrw#LocalBrowseCheck: {{{2
10891fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010892 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010893 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10894 "
10895 " unfortunate interaction -- split window debugging can't be used here, must use
10896 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10897 " another call to LocalBrowseCheck() when attempts to write
10898 " to the DBG buffer are made.
10899 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010900 " The &ft == "netrw" test was installed because the BufEnter event
10901 " would hit when re-entering netrw windows, creating unexpected
10902 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010903" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010904" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010905" 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 Moolenaar71badf92023-04-22 22:40:14 +010010906 " getting E930: Cannot use :redir inside execute
10907"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010908" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10909" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010910
Bram Moolenaar97d62492012-11-15 21:28:22 +010010911 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010912 if isdirectory(s:NetrwFile(a:dirname))
10913" 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 +010010914
Bram Moolenaar97d62492012-11-15 21:28:22 +010010915 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010916" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10917" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010918 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010919
Bram Moolenaar446cb832008-06-24 21:56:24 +000010920 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010921" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010922 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010923
Bram Moolenaar5c736222010-01-06 20:54:52 +010010924 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010925" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010926 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010927 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010928 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010929" 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 +010010930" call Dret("netrw#LocalBrowseCheck")
10931 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010932 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010933
Bram Moolenaar85850f32019-07-19 22:05:51 +020010934 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010935 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10936 " AND IF the listing style is not a tree listing
10937 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010938" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010939 let ibuf = 1
10940 let buflast = bufnr("$")
10941 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010942 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10943 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010944 endif
10945 let ibuf= ibuf + 1
10946 endwhile
10947 endif
10948 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010949" 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>"))
10950" 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 +000010951 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010952" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010953endfun
10954
10955" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010956" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010957" performed any shell command. The idea is to cause all local-browsing
10958" buffers to be refreshed after a user has executed some shell command,
10959" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010960fun! s:LocalBrowseRefresh()
10961" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010962" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10963" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010964
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 " determine which buffers currently reside in a tab
10966 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010967" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010968 return
10969 endif
10970 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010971" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010972 return
10973 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010974 if !empty(getcmdwintype())
10975 " cannot move away from cmdline window, see :h E11
10976 return
10977 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010978 if exists("s:netrw_events") && s:netrw_events == 1
10979 " s:LocalFastBrowser gets called (indirectly) from a
10980 let s:netrw_events= 2
10981" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10982 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010983 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010984 let itab = 1
10985 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010986 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010987 while itab <= tabpagenr("$")
10988 let buftablist = buftablist + tabpagebuflist()
10989 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010990 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010991 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010992" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10993" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010994 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10995 " | refresh any netrw window
10996 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010997 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010998 let ibl = 0
10999 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011000" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011001 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
11002 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020011003 " (ibuf not shown in a current window AND
11004 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011005" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
11006 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011007 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011008" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011009 continue
11010 elseif index(tabpagebuflist(),ibuf) != -1
11011 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011012" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011013 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011014 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010011015 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
11016 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
11017 let g:netrw_quickhelp= g:netrw_quickhelp - 1
11018 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011019" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011020 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
11021 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11022 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011023 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011024 endif
11025 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011026" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011027 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011028" call Decho("restore window: win_gotoid(".curwinid.")")
11029 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011030 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011031
Bram Moolenaara6878372014-03-22 21:02:50 +010011032" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011033endfun
11034
11035" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011036" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11037"
11038" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011039" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011040" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11041" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011042" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011043"
11044" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11045" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011046" (re-using a buffer may not be as accurate)
11047"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011048" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011049" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11050" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11051" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11052" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011053fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011054" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11055" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11056" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11057" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011058
11059 " initialize browselist, a list of buffer numbers that the local browser has used
11060 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011061" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011062 let s:netrw_browselist= []
11063 endif
11064
11065 " append current buffer to fastbrowse list
11066 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011067" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011068 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011069" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011070 endif
11071
11072 " enable autocmd events to handle refreshing/removing local browser buffers
11073 " If local browse buffer is currently showing: refresh it
11074 " If local browse buffer is currently hidden : wipe it
11075 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11076 " =1 : medium speed, re-use directory listing for remote only
11077 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011078 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11079 let s:netrw_events= 1
11080 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011081 au!
11082 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011083" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011084 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011085 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011086" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011087 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011088 endif
11089 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011090
11091 " user must have changed fastbrowse to its fast setting, so remove
11092 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011093 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011094" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011095 unlet s:netrw_events
11096 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011097 au!
11098 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011099 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011100 endif
11101
Bram Moolenaar85850f32019-07-19 22:05:51 +020011102" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011103endfun
11104
11105" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011106" s:LocalListing: does the job of "ls" for local directories {{{2
11107fun! s:LocalListing()
11108" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011109" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11110" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11111" 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 +010011112
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011113" 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
11114" 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
11115" 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 +010011116
11117 " get the list of files contained in the current directory
11118 let dirname = b:netrw_curdir
11119 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011120 let filelist = s:NetrwGlob(dirname,"*",0)
11121 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011122" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011123
11124 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011125" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011126 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11127 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011128" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011129 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011130" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011131 endif
11132
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011133" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011134" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011135" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011136
11137 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11138 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11139 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11141" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011142 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011143" 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 +010011144
11145 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011146" call Decho(" ",'~'.expand("<slnum>"))
11147" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011148
11149 if getftype(filename) == "link"
11150 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011151" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011152 let pfile= filename."@"
11153
11154 elseif getftype(filename) == "socket"
11155 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011156" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011157 let pfile= filename."="
11158
11159 elseif getftype(filename) == "fifo"
11160 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011161" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011162 let pfile= filename."|"
11163
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011164 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011165 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011166" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011167 let pfile= filename."/"
11168
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011169 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011170 if (has("win32") || has("win95") || has("win64") || has("win16"))
11171 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11172 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011173" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011174 let pfile= filename."*"
11175 else
11176 " normal file
11177 let pfile= filename
11178 endif
11179 elseif executable(filename)
11180 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011181" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011182 let pfile= filename."*"
11183 else
11184 " normal file
11185 let pfile= filename
11186 endif
11187
11188 else
11189 " normal file
11190 let pfile= filename
11191 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011192" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011193
11194 if pfile =~ '//$'
11195 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011196" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011197 endif
11198 let pfile= strpart(pfile,dirnamelen)
11199 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011200" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11201" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011202
11203 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011204 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11205 let sz = getfsize(filename)
11206 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11207 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011208
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011209 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011210 let sz= s:NetrwHumanReadable(sz)
11211 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011212 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011213 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011214" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011215 endif
11216
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011217 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011218 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011219 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011220" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011221" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011222 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011223 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011224" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011225 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011226 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011227
11228 elseif g:netrw_sort_by =~ "^s"
11229 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011230" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011231" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011232 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011233 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011234" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011235 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011236 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011237
11238 else
11239 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011240" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011241" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011242 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011243 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011244" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011245 endfor
11246
11247 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011248 sil! NetrwKeepj g/^$/d
11249 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011250 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011251" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011252 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11253
11254" call Dret("s:LocalListing")
11255endfun
11256
11257" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011258" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11259fun! s:NetrwLocalExecute(cmd)
11260" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11261 let ykeep= @@
11262 " sanity check
11263 if !executable(a:cmd)
11264 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11265 let @@= ykeep
11266" call Dret("s:NetrwLocalExecute")
11267 return
11268 endif
11269
11270 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011271" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011272 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011273" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011274
11275 " strip any ansi escape sequences off
11276 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11277
11278 " show user the result(s)
11279 echomsg result
11280 let @@= ykeep
11281
11282" call Dret("s:NetrwLocalExecute")
11283endfun
11284
11285" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011286" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011287fun! s:NetrwLocalRename(path) range
11288" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11289
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011290 if !exists("w:netrw_bannercnt")
11291 let w:netrw_bannercnt= b:netrw_bannercnt
11292 endif
11293
Bram Moolenaar97d62492012-11-15 21:28:22 +010011294 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011295 let ykeep = @@
11296 let ctr = a:firstline
11297 let svpos = winsaveview()
11298 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011299" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011300
11301 " rename files given by the markfilelist
11302 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11303 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011304" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011305 if exists("subfrom")
11306 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011307" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011308 else
11309 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011310 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011311 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011312 if newname =~ ''
11313 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11314 let newname = substitute(newname,'^.*','','')
11315 elseif newname =~ ''
11316 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11317 let newname = substitute(newname,'[^/]*','','')
11318 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011319 if newname =~ '^s/'
11320 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11321 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011322" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011323 let newname = substitute(oldname,subfrom,subto,'')
11324 endif
11325 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011326 if !all && filereadable(newname)
11327 call inputsave()
11328 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11329 call inputrestore()
11330 if response == "all"
11331 let all= 1
11332 elseif response != "y" && response != "yes"
11333 " refresh the directory
11334" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11335 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11336" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11337 NetrwKeepj call winrestview(svpos)
11338 let @@= ykeep
11339" call Dret("NetrwLocalRename")
11340 return
11341 endif
11342 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011343 call rename(oldname,newname)
11344 endfor
11345 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011346
Bram Moolenaar97d62492012-11-15 21:28:22 +010011347 else
11348
11349 " attempt to rename files/directories
11350 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011351 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011352
11353 " sanity checks
11354 if line(".") < w:netrw_bannercnt
11355 let ctr= ctr + 1
11356 continue
11357 endif
11358 let curword= s:NetrwGetWord()
11359 if curword == "./" || curword == "../"
11360 let ctr= ctr + 1
11361 continue
11362 endif
11363
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011364 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011365 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011366" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011367
11368 call inputsave()
11369 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11370 call inputrestore()
11371
11372 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011373" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011374
11375 let ctr= ctr + 1
11376 endwhile
11377 endif
11378
11379 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011380" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011381 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011382" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11383 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011384 let @@= ykeep
11385
11386" call Dret("NetrwLocalRename")
11387endfun
11388
11389" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011390" s:NetrwLocalRm: {{{2
11391fun! s:NetrwLocalRm(path) range
11392" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011393" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011394
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011395 if !exists("w:netrw_bannercnt")
11396 let w:netrw_bannercnt= b:netrw_bannercnt
11397 endif
11398
Bram Moolenaar446cb832008-06-24 21:56:24 +000011399 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011400 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011401 let ret = 0
11402 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011403 let svpos = winsaveview()
11404" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011405
11406 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11407 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011408" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011409 for fname in s:netrwmarkfilelist_{bufnr("%")}
11410 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011411 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011412 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011413 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011414 let all= 1
11415 endif
11416 endfor
11417 call s:NetrwUnMarkFile(1)
11418
11419 else
11420 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011421" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011422
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011423 let keepsol= &l:sol
11424 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011425 let ctr = a:firstline
11426 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011427 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011428
11429 " sanity checks
11430 if line(".") < w:netrw_bannercnt
11431 let ctr= ctr + 1
11432 continue
11433 endif
11434 let curword= s:NetrwGetWord()
11435 if curword == "./" || curword == "../"
11436 let ctr= ctr + 1
11437 continue
11438 endif
11439 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011440 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011441 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011442 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011443 let all= 1
11444 endif
11445 let ctr= ctr + 1
11446 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011447 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011448 endif
11449
11450 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011451" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011452 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011453 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011454" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11455 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011456 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011457 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011458
11459" call Dret("s:NetrwLocalRm")
11460endfun
11461
11462" ---------------------------------------------------------------------
11463" s:NetrwLocalRmFile: remove file fname given the path {{{2
11464" Give confirmation prompt unless all==1
11465fun! s:NetrwLocalRmFile(path,fname,all)
11466" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011467
Bram Moolenaar446cb832008-06-24 21:56:24 +000011468 let all= a:all
11469 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011470 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011471 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11472" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011473
11474 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11475 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011476" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011477 if !all
11478 echohl Statement
11479 call inputsave()
11480 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11481 call inputrestore()
11482 echohl NONE
11483 if ok == ""
11484 let ok="no"
11485 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011486" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011487 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011488" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011489 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011490 let all= 1
11491 endif
11492 endif
11493
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011494 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011495 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011496" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011497 endif
11498
11499 else
11500 " attempt to remove directory
11501 if !all
11502 echohl Statement
11503 call inputsave()
11504 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11505 call inputrestore()
11506 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11507 if ok == ""
11508 let ok="no"
11509 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011510 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011511 let all= 1
11512 endif
11513 endif
11514 let rmfile= substitute(rmfile,'[\/]$','','e')
11515
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011516 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar71badf92023-04-22 22:40:14 +010011517 if delete(rmfile,"d")
11518 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011519 endif
11520 endif
11521 endif
11522
11523" call Dret("s:NetrwLocalRmFile ".ok)
11524 return ok
11525endfun
11526
Bram Moolenaar85850f32019-07-19 22:05:51 +020011527" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011528" Support Functions: {{{1
11529
Bram Moolenaar488c6512005-08-11 20:09:58 +000011530" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011531" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11532" 0: marked file list of current buffer
11533" 1: marked file target
11534fun! netrw#Access(ilist)
11535 if a:ilist == 0
11536 if exists("s:netrwmarkfilelist_".bufnr('%'))
11537 return s:netrwmarkfilelist_{bufnr('%')}
11538 else
11539 return "no-list-buf#".bufnr('%')
11540 endif
11541 elseif a:ilist == 1
11542 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011543 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011544endfun
11545
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011546" ---------------------------------------------------------------------
11547" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11548fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011549 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011550endfun
11551
Bram Moolenaara6878372014-03-22 21:02:50 +010011552" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011553" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11554" I expect this function to be used in
11555" :PChkAssert netrw#Expose("netrwmarkfilelist")
11556" for example.
11557fun! netrw#Expose(varname)
11558" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011559 if exists("s:".a:varname)
11560 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011561" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011562 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011563" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011564 if type(retval) == 3
11565 let retval = copy(retval)
11566 let i = 0
11567 while i < len(retval)
11568 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11569 let i = i + 1
11570 endwhile
11571 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011572" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011573 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011574 else
11575" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011576 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011577 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011578" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011579 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011580 endif
11581
11582" call Dret("netrw#Expose ".string(retval))
11583 return retval
11584endfun
11585
11586" ---------------------------------------------------------------------
11587" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11588fun! netrw#Modify(varname,newvalue)
11589" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11590 exe "let s:".a:varname."= ".string(a:newvalue)
11591" call Dret("netrw#Modify")
11592endfun
11593
11594" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011595" netrw#RFC2396: converts %xx into characters {{{2
11596fun! netrw#RFC2396(fname)
11597" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011598 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011599" call Dret("netrw#RFC2396 ".fname)
11600 return fname
11601endfun
11602
11603" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011604" netrw#UserMaps: supports user-specified maps {{{2
11605" see :help function()
11606"
11607" g:Netrw_UserMaps is a List with members such as:
11608" [[keymap sequence, function reference],...]
11609"
11610" The referenced function may return a string,
11611" refresh : refresh the display
11612" -other- : this string will be executed
11613" or it may return a List of strings.
11614"
11615" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011616" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011617" Related functions:
11618" netrw#Expose(varname) -- see s:varname variables
11619" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11620" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11621fun! netrw#UserMaps(islocal)
11622" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11623" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11624
11625 " set up usermaplist
11626 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11627" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11628 for umap in g:Netrw_UserMaps
11629" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11630" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11631 " if umap[0] is a string and umap[1] is a string holding a function name
11632 if type(umap[0]) == 1 && type(umap[1]) == 1
11633" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11634 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11635 else
11636 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11637 endif
11638 endfor
11639 endif
11640" call Dret("netrw#UserMaps")
11641endfun
11642
11643" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011644" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11645fun! netrw#WinPath(path)
11646" call Dfunc("netrw#WinPath(path<".a:path.">)")
11647 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11648 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011649 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011650 " remove trailing slash (Win95)
11651 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11652 " remove escaped spaces
11653 let path = substitute(path, '\ ', ' ', 'g')
11654 " convert slashes to backslashes
11655 let path = substitute(path, '/', '\', 'g')
11656 else
11657 let path= a:path
11658 endif
11659" call Dret("netrw#WinPath <".path.">")
11660 return path
11661endfun
11662
11663" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011664" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11665" cb : bl2mf=0 add marked files to buffer list
11666" cB : bl2mf=1 use bufferlist to mark files
11667" (mnemonic: cb = copy (marked files) to buffer list)
11668fun! s:NetrwBadd(islocal,bl2mf)
11669" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11670 if a:bl2mf
11671 " cB: add buffer list to marked files
11672 redir => bufl
11673 ls
11674 redir END
11675 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11676 for fname in bufl
11677 call s:NetrwMarkFile(a:islocal,fname)
11678 endfor
11679 else
11680 " cb: add marked files to buffer list
11681 for fname in s:netrwmarkfilelist_{bufnr("%")}
11682" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11683 exe "badd ".fnameescape(fname)
11684 endfor
11685 let curbufnr = bufnr("%")
11686 let curdir = s:NetrwGetCurdir(a:islocal)
11687 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11688 endif
11689" call Dret("s:NetrwBadd")
11690endfun
11691
11692" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011693" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11694fun! s:ComposePath(base,subdir)
11695" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11696
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011697 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011698" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011699 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011700 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011701 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011702 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011703 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011704 endif
11705
Bram Moolenaar85850f32019-07-19 22:05:51 +020011706 " COMBAK: test on windows with changing to root directory: :e C:/
11707 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011708" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011709 let ret= a:subdir
11710
Bram Moolenaar85850f32019-07-19 22:05:51 +020011711 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011712" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011713 if a:base =~ '[/\\]$'
11714 let ret= a:base.a:subdir
11715 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011716 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011717 endif
11718
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011719 elseif a:base =~ '^\a\{3,}://'
11720" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011721 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11722 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11723 if a:subdir == '../'
11724 if curpath =~ '[^/]/[^/]\+/$'
11725 let curpath= substitute(curpath,'[^/]\+/$','','')
11726 else
11727 let curpath=""
11728 endif
11729 let ret= urlbase.curpath
11730 else
11731 let ret= urlbase.curpath.a:subdir
11732 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011733" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11734" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11735" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011736
11737 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011738" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011739 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11740 if a:base =~ '^//'
11741 " keeping initial '//' for the benefit of network share listing support
11742 let ret= '/'.ret
11743 endif
11744 let ret= simplify(ret)
11745 endif
11746
11747" call Dret("s:ComposePath ".ret)
11748 return ret
11749endfun
11750
11751" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011752" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11753" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11754fun! s:DeleteBookmark(fname)
11755" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11756 call s:MergeBookmarks()
11757
11758 if exists("g:netrw_bookmarklist")
11759 let indx= index(g:netrw_bookmarklist,a:fname)
11760 if indx == -1
11761 let indx= 0
11762 while indx < len(g:netrw_bookmarklist)
11763 if g:netrw_bookmarklist[indx] =~ a:fname
11764 call remove(g:netrw_bookmarklist,indx)
11765 let indx= indx - 1
11766 endif
11767 let indx= indx + 1
11768 endwhile
11769 else
11770 " remove exact match
11771 call remove(g:netrw_bookmarklist,indx)
11772 endif
11773 endif
11774
11775" call Dret("s:DeleteBookmark")
11776endfun
11777
11778" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011779" s:FileReadable: o/s independent filereadable {{{2
11780fun! s:FileReadable(fname)
11781" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11782
11783 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011784 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011785 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011786 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011787 endif
11788
11789" call Dret("s:FileReadable ".ret)
11790 return ret
11791endfun
11792
11793" ---------------------------------------------------------------------
11794" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11795" Places correct suffix on end of temporary filename,
11796" using the suffix provided with fname
11797fun! s:GetTempfile(fname)
11798" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11799
11800 if !exists("b:netrw_tmpfile")
11801 " get a brand new temporary filename
11802 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011803" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011804
Bram Moolenaarc236c162008-07-13 17:41:49 +000011805 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011806" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011807
Bram Moolenaar9964e462007-05-05 17:54:07 +000011808 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011809 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11810" 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 +010011811 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011812" call Dret("s:GetTempfile getcwd<".getcwd().">")
11813 return ""
11814 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011815
Bram Moolenaar9964e462007-05-05 17:54:07 +000011816 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011817 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011818" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011819
Bram Moolenaar9964e462007-05-05 17:54:07 +000011820 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011821 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011822 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011823 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011824 if !exists("+shellslash") || !&ssl
11825 let tmpfile = substitute(tmpfile,'/','\','g')
11826 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011827 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011828 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011829 endif
11830 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011831" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011832 else
11833 " re-use temporary filename
11834 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011835" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011836 endif
11837
11838 " use fname's suffix for the temporary file
11839 if a:fname != ""
11840 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011841" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011842 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011843 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011844 elseif a:fname =~ '.txz$'
11845 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011846 else
11847 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11848 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011849" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011850 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011851" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011852 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011853" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011854 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11855 endif
11856 endif
11857
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011858" 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 +000011859" call Dret("s:GetTempfile <".tmpfile.">")
11860 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011861endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011862
11863" ---------------------------------------------------------------------
11864" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011865" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011866fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011867" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011868 if s:user == ""
11869 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11870 else
11871 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11872 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011873 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011874 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011875 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011876 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011877 else
11878 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11879 endif
11880" call Dret("s:MakeSshCmd <".sshcmd.">")
11881 return sshcmd
11882endfun
11883
11884" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011885" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11886fun! s:MakeBookmark(fname)
11887" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11888
11889 if !exists("g:netrw_bookmarklist")
11890 let g:netrw_bookmarklist= []
11891 endif
11892
11893 if index(g:netrw_bookmarklist,a:fname) == -1
11894 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011895 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011896 call add(g:netrw_bookmarklist,a:fname.'/')
11897 elseif a:fname !~ '/'
11898 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11899 else
11900 call add(g:netrw_bookmarklist,a:fname)
11901 endif
11902 call sort(g:netrw_bookmarklist)
11903 endif
11904
11905" call Dret("s:MakeBookmark")
11906endfun
11907
11908" ---------------------------------------------------------------------
11909" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11910fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011911" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011912 " get bookmarks from .netrwbook file
11913 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011914 if filereadable(s:NetrwFile(savefile))
11915" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011916 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011917" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011918 NetrwKeepj call delete(savefile)
11919 endif
11920" call Dret("s:MergeBookmarks")
11921endfun
11922
11923" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011924" s:NetrwBMShow: {{{2
11925fun! s:NetrwBMShow()
11926" call Dfunc("s:NetrwBMShow()")
11927 redir => bmshowraw
11928 menu
11929 redir END
11930 let bmshowlist = split(bmshowraw,'\n')
11931 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011932 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011933 if bmshowfuncs != []
11934 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011935 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011936 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011937 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011938 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011939 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011940" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11941endfun
11942
11943" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011944" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011945fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011946 if !exists("w:netrw_liststyle")
11947 let w:netrw_liststyle= g:netrw_liststyle
11948 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011949" 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 +020011950
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011951" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11952
Bram Moolenaaradc21822011-04-01 18:03:16 +020011953 if &ft != "netrw"
11954 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11955 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011956" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011957
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011958 elseif g:netrw_cursor == 8
11959 if w:netrw_liststyle == s:WIDELIST
11960 setl cursorline
11961 setl cursorcolumn
11962 else
11963 setl cursorline
11964 endif
11965 elseif g:netrw_cursor == 7
11966 setl cursorline
11967 elseif g:netrw_cursor == 6
11968 if w:netrw_liststyle == s:WIDELIST
11969 setl cursorline
11970 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011971 elseif g:netrw_cursor == 4
11972 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011973" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011974 setl cursorline
11975 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011976
11977 elseif g:netrw_cursor == 3
11978 " thin-long-tree: cursorline, user's cursorcolumn
11979 " wide : cursorline, cursorcolumn
11980 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011981" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011982 setl cursorline
11983 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011984 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011985" 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 +020011986 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011987 endif
11988
11989 elseif g:netrw_cursor == 2
11990 " thin-long-tree: cursorline, user's cursorcolumn
11991 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011992" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011993 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011994
11995 elseif g:netrw_cursor == 1
11996 " thin-long-tree: user's cursorline, user's cursorcolumn
11997 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011998 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011999" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010012000 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020012001 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012002" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012003 endif
12004
12005 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020012006 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012007" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012008 let &l:cursorline = s:netrw_usercul
12009 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012010 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020012011
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012012" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020012013" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012014endfun
12015
12016" ---------------------------------------------------------------------
12017" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
12018fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012019" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012020 if exists("s:netrw_usercul")
12021 let &l:cursorline = s:netrw_usercul
12022 endif
12023 if exists("s:netrw_usercuc")
12024 let &l:cursorcolumn = s:netrw_usercuc
12025 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012026" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012027" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12028endfun
12029
12030" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012031" s:NetrwDelete: Deletes a file. {{{2
12032" Uses Steve Hall's idea to insure that Windows paths stay
12033" acceptable. No effect on Unix paths.
12034" Examples of use: let result= s:NetrwDelete(path)
12035fun! s:NetrwDelete(path)
12036" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12037
Bram Moolenaar5c736222010-01-06 20:54:52 +010012038 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012039 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
12040 if exists("+shellslash")
12041 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012042 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012043 let result = delete(path)
12044 let &shellslash = sskeep
12045 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012046" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012047 let result= delete(path)
12048 endif
12049 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012050" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012051 let result= delete(path)
12052 endif
12053 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012054 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012055 endif
12056
12057" call Dret("s:NetrwDelete ".result)
12058 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012059endfun
12060
12061" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012062" s:NetrwBufRemover: removes a buffer that: {{{2s
12063" has buffer-id > 1
12064" is unlisted
12065" is unnamed
12066" does not appear in any window
12067fun! s:NetrwBufRemover(bufid)
12068" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12069" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12070" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12071" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12072" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12073
yasuda4dbb2662023-10-04 20:50:35 +020012074 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012075" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012076 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012077 endif
12078
12079" call Dret("s:NetrwBufRemover")
12080endfun
12081
12082" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012083" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012084fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012085" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012086" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012087
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012088 " Clean out the last buffer:
12089 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12090 " If so, delete it.
12091 call s:NetrwBufRemover(bufnr("$"))
12092
Bram Moolenaar446cb832008-06-24 21:56:24 +000012093 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012094" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012095 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12096 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12097 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12098 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12099 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12100 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12101 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12102 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12103 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12104 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12105 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12106 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12107 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12108 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12109 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12110 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12111
Bram Moolenaar85850f32019-07-19 22:05:51 +020012112 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012113" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012114 " when tree listing uses file TreeListing... a new buffer is made.
12115 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012116 " COMBAK: this causes a problem, see P43
12117" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012118 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012119 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012120 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012121" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012122 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012123
Bram Moolenaar446cb832008-06-24 21:56:24 +000012124 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012125" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012126 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12127 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12128 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12129 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12130 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12131 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12132 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12133 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12134 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12135 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12136 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12137 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12138 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12139 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12140 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12141 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12142
Bram Moolenaar5c736222010-01-06 20:54:52 +010012143 if a:0 > 0
12144 let b:netrw_curdir= a:1
12145 if b:netrw_curdir =~ '/$'
12146 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012147 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012148 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012149 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012150 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12151 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012152 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012153 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012154 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012155 endif
12156 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012157 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12158 let &l:bexpr = "netrw#BalloonHelp()"
12159 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012160
Bram Moolenaar8d043172014-01-23 14:24:41 +010012161" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012162endfun
12163
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012164" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012165" s:NetrwExe: executes a string using "!" {{{2
12166fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012167" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012168 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012169" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012170 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12171 set shell& shellcmdflag& shellxquote& shellxescape&
12172 set shellquote& shellpipe& shellredir& shellslash&
12173 exe a:cmd
12174 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12175 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012176" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012177 exe a:cmd
12178 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012179 if v:shell_error
12180 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12181 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012182" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012183endfun
12184
12185" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012186" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12187fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012188 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012189" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012190 let curbuf = bufnr("%")
12191 let curwin = winnr()
12192 let iwin = 1
12193 while iwin <= winnr("$")
12194 exe iwin."wincmd w"
12195 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12196 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12197 let winvars= w:
12198 break
12199 endif
12200 let iwin= iwin + 1
12201 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012202 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012203 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012204" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012205 for k in keys(winvars)
12206 let w:{k}= winvars[k]
12207 endfor
12208 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012209" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012210 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012211endfun
12212
Bram Moolenaara6878372014-03-22 21:02:50 +010012213" ---------------------------------------------------------------------
12214" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012215" Returns: 0=success
12216" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012217fun! s:NetrwLcd(newdir)
12218" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012219" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012220
Bram Moolenaar85850f32019-07-19 22:05:51 +020012221 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012222 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012223 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012224 catch /^Vim\%((\a\+)\)\=:E344/
12225 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12226 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012227 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012228 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12229 " forward slashes by earlier code; so check for both.
12230 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
12231 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12232 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012233 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012234 endif
12235 endif
12236 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012237 let err472= 1
12238 endtry
12239
12240 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012241 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12242 if exists("w:netrw_prvdir")
12243 let a:newdir= w:netrw_prvdir
12244 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012245 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012246" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012247 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012248" 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 +010012249 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012250 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012251" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12252 return -1
12253 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012254
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012255" call Decho("getcwd <".getcwd().">")
12256" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012257" call Dret("s:NetrwLcd 0")
12258 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012259endfun
12260
Bram Moolenaar9964e462007-05-05 17:54:07 +000012261" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012262" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12263" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12264fun! s:NetrwSaveWordPosn()
12265" call Dfunc("NetrwSaveWordPosn()")
12266 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12267" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12268endfun
12269
12270" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012271" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12272" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12273fun! s:NetrwHumanReadable(sz)
12274" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12275
12276 if g:netrw_sizestyle == 'h'
12277 if a:sz >= 1000000000
12278 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12279 elseif a:sz >= 10000000
12280 let sz = printf("%d",a:sz/1000000)."m"
12281 elseif a:sz >= 1000000
12282 let sz = printf("%.1f",a:sz/1000000.0)."m"
12283 elseif a:sz >= 10000
12284 let sz = printf("%d",a:sz/1000)."k"
12285 elseif a:sz >= 1000
12286 let sz = printf("%.1f",a:sz/1000.0)."k"
12287 else
12288 let sz= a:sz
12289 endif
12290
12291 elseif g:netrw_sizestyle == 'H'
12292 if a:sz >= 1073741824
12293 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12294 elseif a:sz >= 10485760
12295 let sz = printf("%d",a:sz/1048576)."M"
12296 elseif a:sz >= 1048576
12297 let sz = printf("%.1f",a:sz/1048576.0)."M"
12298 elseif a:sz >= 10240
12299 let sz = printf("%d",a:sz/1024)."K"
12300 elseif a:sz >= 1024
12301 let sz = printf("%.1f",a:sz/1024.0)."K"
12302 else
12303 let sz= a:sz
12304 endif
12305
12306 else
12307 let sz= a:sz
12308 endif
12309
12310" call Dret("s:NetrwHumanReadable ".sz)
12311 return sz
12312endfun
12313
12314" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012315" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12316" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12317fun! s:NetrwRestoreWordPosn()
12318" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012319 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012320" call Dret("NetrwRestoreWordPosn")
12321endfun
12322
12323" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012324" s:RestoreBufVars: {{{2
12325fun! s:RestoreBufVars()
12326" call Dfunc("s:RestoreBufVars()")
12327
12328 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12329 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12330 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12331 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12332 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12333 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12334
12335" call Dret("s:RestoreBufVars")
12336endfun
12337
12338" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012339" s:RemotePathAnalysis: {{{2
12340fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012341" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012342
Bram Moolenaara6878372014-03-22 21:02:50 +010012343 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012344 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012345 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012346 let s:user = substitute(a:dirname,dirpat,'\3','')
12347 let s:machine = substitute(a:dirname,dirpat,'\4','')
12348 let s:port = substitute(a:dirname,dirpat,'\5','')
12349 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012350 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012351 if s:machine =~ '@'
12352 let dirpat = '^\(.*\)@\(.\{-}\)$'
12353 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12354 let s:machine = substitute(s:machine,dirpat,'\2','')
12355 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012356
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012357" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12358" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12359" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12360" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12361" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12362" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012363
12364" call Dret("s:RemotePathAnalysis")
12365endfun
12366
12367" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012368" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12369" Returns status
12370" Runs system() on
12371" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012372" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012373fun! s:RemoteSystem(cmd)
12374" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12375 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012376 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 +000012377 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012378 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012379 else
12380 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12381 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12382 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012383 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012384 else
12385 let cmd= cmd.' '
12386 endif
12387 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012388" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012389 let ret= system(cmd)
12390 endif
12391" call Dret("s:RemoteSystem ".ret)
12392 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012393endfun
12394
12395" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012396" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012397fun! s:RestoreWinVars()
12398" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012399 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012400 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12401 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12402 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12403 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12404 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12405 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12406 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12407 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12408 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12409 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12410 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12411 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012412 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12413 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012414 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12415 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12416 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12417" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012418endfun
12419
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012420" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012421" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12422"
12423" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12424" is true) and a command, :Rexplore, which call this function.
12425"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012426" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012427"
12428" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012429fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012430 if exists("s:netrwdrag")
12431 return
12432 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012433" 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 +010012434" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12435" 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 +010012436
12437 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012438 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012439" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012440 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012441 unlet w:netrw_rexfile
12442" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012443 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012444" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012445" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12446" 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 +020012447 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012448
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012449 " ---------------------------
12450 " :Rex issued while in a file
12451 " ---------------------------
12452
Bram Moolenaara6878372014-03-22 21:02:50 +010012453 " record current file so :Rex can return to it from netrw
12454 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012455" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012456
12457 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012458" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012459 return
12460 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012461" 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 +020012462 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012463 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012464 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012465 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012466 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012467 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012468 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012469 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012470 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012471" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12472 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012473" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12474 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012475 if exists("s:rexposn_".bufnr('%'))
12476 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012477 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012478 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012479" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012480 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012481
Bram Moolenaar85850f32019-07-19 22:05:51 +020012482 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12483 if exists("s:explore_match")
12484 exe "2match netrwMarkFile /".s:explore_match."/"
12485 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012486 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012487
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012488" 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 +010012489" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012490endfun
12491
12492" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012493" s:SaveBufVars: save selected b: variables to s: variables {{{2
12494" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012495fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012496" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012497
12498 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12499 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12500 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12501 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12502 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12503 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12504
12505" call Dret("s:SaveBufVars")
12506endfun
12507
12508" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012509" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12510fun! s:SavePosn(posndict)
12511" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12512
Bram Moolenaar85850f32019-07-19 22:05:51 +020012513 if !exists("a:posndict[bufnr('%')]")
12514 let a:posndict[bufnr("%")]= []
12515 endif
12516" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12517 call add(a:posndict[bufnr("%")],winsaveview())
12518" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012519
12520" call Dret("s:SavePosn posndict")
12521 return a:posndict
12522endfun
12523
12524" ---------------------------------------------------------------------
12525" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12526fun! s:RestorePosn(posndict)
12527" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012528 if exists("a:posndict")
12529 if has_key(a:posndict,bufnr("%"))
12530" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12531 let posnlen= len(a:posndict[bufnr("%")])
12532 if posnlen > 0
12533 let posnlen= posnlen - 1
12534" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12535 call winrestview(a:posndict[bufnr("%")][posnlen])
12536 call remove(a:posndict[bufnr("%")],posnlen)
12537" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12538 endif
12539 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012540 endif
12541" call Dret("s:RestorePosn")
12542endfun
12543
12544" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012545" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012546fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012547" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012548 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12549 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12550 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12551 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12552 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12553 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12554 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12555 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12556 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12557 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12558 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12559 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12560 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12561 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12562 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12563 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12564 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12565 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12566" call Dret("s:SaveWinVars")
12567endfun
12568
12569" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012570" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012571" To allow separate windows to have their own activities, such as
12572" Explore **/pattern, several variables have been made window-oriented.
12573" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012574" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012575" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012576fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012577" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012578 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12579 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12580 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12581 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12582 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12583 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12584 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12585 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12586 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12587 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12588" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012589endfun
12590
12591" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012592" s:SetRexDir: set directory for :Rexplore {{{2
12593fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012594" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012595 let w:netrw_rexdir = a:dirname
12596 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012597 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012598" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12599" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012600" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012601" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012602" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012603endfun
12604
12605" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012606" s:ShowLink: used to modify thin and tree listings to show links {{{2
12607fun! s:ShowLink()
12608" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012609" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12610" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012611 if exists("b:netrw_curdir")
12612 norm! $?\a
12613 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12614 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012615" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12616" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12617" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12618 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012619 let dirlen = strlen(b:netrw_curdir)
12620 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012621" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012622 endif
12623 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012624" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12625" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012626 setl noro ma
12627 call setline(".",modline)
12628 setl ro noma nomod
12629 endif
12630" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12631endfun
12632
12633" ---------------------------------------------------------------------
12634" s:ShowStyle: {{{2
12635fun! s:ShowStyle()
12636 if !exists("w:netrw_liststyle")
12637 let liststyle= g:netrw_liststyle
12638 else
12639 let liststyle= w:netrw_liststyle
12640 endif
12641 if liststyle == s:THINLIST
12642 return s:THINLIST.":thin"
12643 elseif liststyle == s:LONGLIST
12644 return s:LONGLIST.":long"
12645 elseif liststyle == s:WIDELIST
12646 return s:WIDELIST.":wide"
12647 elseif liststyle == s:TREELIST
12648 return s:TREELIST.":tree"
12649 else
12650 return 'n/a'
12651 endif
12652endfun
12653
12654" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012655" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12656" Solution from Nicolai Weibull, vim docs (:help strlen()),
12657" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012658fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012659" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12660
12661 if v:version >= 703 && exists("*strdisplaywidth")
12662 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012663
Bram Moolenaar8d043172014-01-23 14:24:41 +010012664 elseif type(g:Align_xstrlen) == 1
12665 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12666 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012667
Bram Moolenaar8d043172014-01-23 14:24:41 +010012668 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012669 " number of codepoints (Latin a + combining circumflex is two codepoints)
12670 " (comment from TM, solution from NW)
12671 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012672
Bram Moolenaar8d043172014-01-23 14:24:41 +010012673 elseif g:Align_xstrlen == 2
12674 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012675 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12676 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012677 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012678
Bram Moolenaar8d043172014-01-23 14:24:41 +010012679 elseif g:Align_xstrlen == 3
12680 " virtual length (counting, for instance, tabs as anything between 1 and
12681 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012682 " preceded by lam, one otherwise, etc.)
12683 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012684 let modkeep= &l:mod
12685 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012686 call setline(line("."),a:x)
12687 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012688 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012689 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012690 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012691
Bram Moolenaar446cb832008-06-24 21:56:24 +000012692 else
12693 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012694 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012695 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012696" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012697 return ret
12698endfun
12699
12700" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012701" s:ShellEscape: shellescape(), or special windows handling {{{2
12702fun! s:ShellEscape(s, ...)
12703 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12704 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12705 endif
12706 let f = a:0 > 0 ? a:1 : 0
12707 return shellescape(a:s, f)
12708endfun
12709
12710" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012711" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012712fun! s:TreeListMove(dir)
12713" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012714 let curline = getline('.')
12715 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12716 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12717 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12718 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12719 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12720 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12721" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12722" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12723" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12724" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12725" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12726 " COMBAK : need to handle when on a directory
12727 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012728 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012729 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012730 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012731 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012732" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012733 elseif a:dir == '[]' && nxtline != ''
12734 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012735" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012736 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12737 if nl != 0
12738 NetrwKeepj norm! k
12739 else
12740 NetrwKeepj norm! G
12741 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012742" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012743 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012744 endif
12745
12746" call Dret("s:TreeListMove")
12747endfun
12748
12749" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012750" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12751" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12752" can't be called except via emenu. But due to locale, that menu line may not be called
12753" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12754fun! s:UpdateBuffersMenu()
12755" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012756 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012757 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012758 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012759 catch /^Vim\%((\a\+)\)\=:E/
12760 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012761 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012762 endtry
12763 endif
12764" call Dret("s:UpdateBuffersMenu")
12765endfun
12766
12767" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012768" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012769" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012770fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012771" call Dfunc("s:UseBufWinVars()")
12772 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012773 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12774 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12775 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12776 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12777 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12778 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12779 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12780 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12781 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 +000012782" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012783endfun
12784
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012785" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012786" s:UserMaps: supports user-defined UserMaps {{{2
12787" * calls a user-supplied funcref(islocal,curdir)
12788" * interprets result
12789" See netrw#UserMaps()
12790fun! s:UserMaps(islocal,funcname)
12791" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12792
12793 if !exists("b:netrw_curdir")
12794 let b:netrw_curdir= getcwd()
12795 endif
12796 let Funcref = function(a:funcname)
12797 let result = Funcref(a:islocal)
12798
12799 if type(result) == 1
12800 " if result from user's funcref is a string...
12801" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12802 if result == "refresh"
12803" call Decho("refreshing display",'~'.expand("<slnum>"))
12804 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12805 elseif result != ""
12806" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12807 exe result
12808 endif
12809
12810 elseif type(result) == 3
12811 " if result from user's funcref is a List...
12812" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12813 for action in result
12814 if action == "refresh"
12815" call Decho("refreshing display",'~'.expand("<slnum>"))
12816 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12817 elseif action != ""
12818" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12819 exe action
12820 endif
12821 endfor
12822 endif
12823
12824" call Dret("s:UserMaps")
12825endfun
12826
Bram Moolenaar85850f32019-07-19 22:05:51 +020012827" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012828" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012829" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012830let &cpo= s:keepcpo
12831unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012832
Bram Moolenaar85850f32019-07-19 22:05:51 +020012833" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012834" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012835" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012836" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012837" doing autoload/netrw.vim version v172g ~57
12838" varname<g:netrw_dirhistcnt> value=0 ~1
12839" varname<s:THINLIST> value=0 ~1
12840" varname<s:LONGLIST> value=1 ~1
12841" varname<s:WIDELIST> value=2 ~1
12842" varname<s:TREELIST> value=3 ~1
12843" varname<s:MAXLIST> value=4 ~1
12844" varname<g:netrw_use_errorwindow> value=2 ~1
12845" varname<g:netrw_http_xcmd> value=-q -O ~1
12846" varname<g:netrw_http_put_cmd> value=curl -T ~1
12847" varname<g:netrw_keepj> value=keepj ~1
12848" varname<g:netrw_rcp_cmd> value=rcp ~1
12849" varname<g:netrw_rsync_cmd> value=rsync ~1
12850" varname<g:netrw_rsync_sep> value=/ ~1
12851" varname<g:netrw_scp_cmd> value=scp -q ~1
12852" varname<g:netrw_sftp_cmd> value=sftp ~1
12853" varname<g:netrw_ssh_cmd> value=ssh ~1
12854" varname<g:netrw_alto> value=0 ~1
12855" varname<g:netrw_altv> value=1 ~1
12856" varname<g:netrw_banner> value=1 ~1
12857" varname<g:netrw_browse_split> value=0 ~1
12858" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12859" varname<g:netrw_chgwin> value=-1 ~1
12860" varname<g:netrw_clipboard> value=1 ~1
12861" varname<g:netrw_compress> value=gzip ~1
12862" varname<g:netrw_ctags> value=ctags ~1
12863" varname<g:netrw_cursor> value=2 ~1
12864" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12865" varname<g:netrw_cygdrive> value=/cygdrive ~1
12866" varname<s:didstarstar> value=0 ~1
12867" varname<g:netrw_dirhistcnt> value=0 ~1
12868" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12869" varname<g:netrw_dirhistmax> value=10 ~1
12870" varname<g:netrw_errorlvl> value=0 ~1
12871" varname<g:netrw_fastbrowse> value=1 ~1
12872" varname<g:netrw_ftp_browse_reject> value=^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$ ~1
12873" varname<g:netrw_ftpmode> value=binary ~1
12874" varname<g:netrw_hide> value=1 ~1
12875" varname<g:netrw_keepdir> value=1 ~1
12876" varname<g:netrw_list_hide> value= ~1
12877" varname<g:netrw_localmkdir> value=mkdir ~1
12878" varname<g:netrw_remote_mkdir> value=mkdir ~1
12879" varname<g:netrw_liststyle> value=0 ~1
12880" varname<g:netrw_markfileesc> value=*./[\~ ~1
12881" varname<g:netrw_maxfilenamelen> value=32 ~1
12882" varname<g:netrw_menu> value=1 ~1
12883" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12884" varname<g:netrw_mousemaps> value=1 ~1
12885" varname<g:netrw_retmap> value=0 ~1
12886" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12887" varname<g:netrw_preview> value=0 ~1