blob: b91dab4e715c49dbb48bdb5486fd24ab640a7547 [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 Brabandtf9ca1392024-02-19 20:37:11 +010011" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010013" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000014" Permission is hereby granted to use and distribute this code,
15" with or without modifications, provided that this copyright
16" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000017" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000018" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000019" expressed or implied. By using this plugin, you agree that
20" in no event will the copyright holder be liable for any damages
21" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010022"
23" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
24" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
25"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020026"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000027"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000028" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000029" (James 1:22 RSV)
30" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000031" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000032if &cp || exists("g:loaded_netrw")
33 finish
34endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020035
36" Check that vim has patches that netrw requires.
37" Patches needed for v7.4: 1557, and 213.
38" (netrw will benefit from vim's having patch#656, too)
39let s:needspatches=[1557,213]
40if exists("s:needspatches")
41 for ptch in s:needspatches
42 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
43 if !exists("s:needpatch{ptch}")
44 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
45 endif
46 let s:needpatch{ptch}= 1
47 finish
48 endif
49 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020050endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020051
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010052let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000053if !exists("s:NOTE")
54 let s:NOTE = 0
55 let s:WARNING = 1
56 let s:ERROR = 2
57endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000058
Bram Moolenaar1afcace2005-11-25 19:54:28 +000059let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010060setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020061"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010062"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010063"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000064
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000065" ======================
66" Netrw Variables: {{{1
67" ======================
68
Bram Moolenaar071d4272004-06-13 20:20:40 +000069" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020070" netrw#ErrorMsg: {{{2
71" 0=note = s:NOTE
72" 1=warning = s:WARNING
73" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010074" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
75" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
76" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010077" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020078fun! netrw#ErrorMsg(level,msg,errnum)
79" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
80
81 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020082" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020083 return
84 endif
85
86 if a:level == 1
87 let level= "**warning** (netrw) "
88 elseif a:level == 2
89 let level= "**error** (netrw) "
90 else
91 let level= "**note** (netrw) "
92 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010093" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020094
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020095 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
96 " use popup window
97 if type(a:msg) == 3
98 let msg = [level]+a:msg
99 else
100 let msg= level.a:msg
101 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200102 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200103 let s:popuperr_text= ""
104 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200105 " (default) netrw creates a one-line window to show error/warning
106 " messages (reliably displayed)
107
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100108 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200109 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100110" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200111
112 " getting messages out reliably is just plain difficult!
113 " This attempt splits the current window, creating a one line window.
114 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100115" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200116 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100117" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200118 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100119 if type(a:msg) == 3
120 for msg in a:msg
121 NetrwKeepj call setline(line("$")+1,level.msg)
122 endfor
123 else
124 NetrwKeepj call setline(line("$")+1,level.a:msg)
125 endif
126 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200127 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100128" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200129 bo 1split
130 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200131 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200132 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100133 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100134" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200135 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100136 if type(a:msg) == 3
137 for msg in a:msg
138 NetrwKeepj call setline(line("$")+1,level.msg)
139 endfor
140 else
141 NetrwKeepj call setline(line("$"),level.a:msg)
142 endif
143 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200144 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100145" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200146 if &fo !~ '[ta]'
147 syn clear
148 syn match netrwMesgNote "^\*\*note\*\*"
149 syn match netrwMesgWarning "^\*\*warning\*\*"
150 syn match netrwMesgError "^\*\*error\*\*"
151 hi link netrwMesgWarning WarningMsg
152 hi link netrwMesgError Error
153 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100154" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200155 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200156
157 else
158 " (optional) netrw will show messages using echomsg. Even if the
159 " message doesn't appear, at least it'll be recallable via :messages
160" redraw!
161 if a:level == s:WARNING
162 echohl WarningMsg
163 elseif a:level == s:ERROR
164 echohl Error
165 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100166
167 if type(a:msg) == 3
168 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100169 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100170 endfor
171 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100172 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100173 endif
174
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100175" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200176 echohl None
177 endif
178
179" call Dret("netrw#ErrorMsg")
180endfun
181
182" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100183" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100184" Loosely, varname = value.
185fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100186" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100187 if !exists(a:varname)
188 if type(a:value) == 0
189 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200190 elseif type(a:value) == 1 && a:value =~ '^[{[]'
191 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100192 elseif type(a:value) == 1
193 exe "let ".a:varname."="."'".a:value."'"
194 else
195 exe "let ".a:varname."=".a:value
196 endif
197 endif
198endfun
199
200" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000201" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200202call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000203if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100204 call s:NetrwInit("s:THINLIST",0)
205 call s:NetrwInit("s:LONGLIST",1)
206 call s:NetrwInit("s:WIDELIST",2)
207 call s:NetrwInit("s:TREELIST",3)
208 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000209endif
210
211" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200212" Default option values: {{{2
213let g:netrw_localcopycmdopt = ""
214let g:netrw_localcopydircmdopt = ""
215let g:netrw_localmkdiropt = ""
216let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200217
218" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000219" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200220if (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")
221 call s:NetrwInit("g:netrw_use_errorwindow",2)
222else
223 call s:NetrwInit("g:netrw_use_errorwindow",1)
224endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200225
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000226if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100227 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000228 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100229 elseif executable("curl")
230 let g:netrw_dav_cmd = "curl"
231 else
232 let g:netrw_dav_cmd = ""
233 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000234endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000235if !exists("g:netrw_fetch_cmd")
236 if executable("fetch")
237 let g:netrw_fetch_cmd = "fetch -o"
238 else
239 let g:netrw_fetch_cmd = ""
240 endif
241endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100242if !exists("g:netrw_file_cmd")
243 if executable("elinks")
244 call s:NetrwInit("g:netrw_file_cmd","elinks")
245 elseif executable("links")
246 call s:NetrwInit("g:netrw_file_cmd","links")
247 endif
248endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000249if !exists("g:netrw_ftp_cmd")
250 let g:netrw_ftp_cmd = "ftp"
251endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200252let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200253if !exists("g:netrw_ftp_options")
254 let g:netrw_ftp_options= "-i -n"
255endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000256if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100257 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100258 let g:netrw_http_cmd = "wget"
259 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100260 elseif executable("curl")
261 let g:netrw_http_cmd = "curl"
262 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200263 elseif executable("elinks")
264 let g:netrw_http_cmd = "elinks"
265 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000266 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100267 let g:netrw_http_cmd = "fetch"
268 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200269 elseif executable("links")
270 let g:netrw_http_cmd = "links"
271 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000272 else
273 let g:netrw_http_cmd = ""
274 endif
275endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100276call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100277call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100278call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
279call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200280call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200281if !exists("g:netrw_scp_cmd")
282 if executable("scp")
283 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
284 elseif executable("pscp")
285 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable('c:\private.ppk')
286 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
287 else
288 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
289 endif
290 else
291 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
292 endif
293endif
294
Bram Moolenaar5c736222010-01-06 20:54:52 +0100295call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
296call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000297
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000298if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000299 \ && exists("g:netrw_use_nt_rcp")
300 \ && g:netrw_use_nt_rcp
301 \ && executable( $SystemRoot .'/system32/rcp.exe')
302 let s:netrw_has_nt_rcp = 1
303 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000304else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000305 let s:netrw_has_nt_rcp = 0
306 let s:netrw_rcpmode = ''
307endif
308
309" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000310" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000311" Cygwin Detection ------- {{{3
312if !exists("g:netrw_cygwin")
313 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100314 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000315 let g:netrw_cygwin= 1
316 else
317 let g:netrw_cygwin= 0
318 endif
319 else
320 let g:netrw_cygwin= 0
321 endif
322endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000323" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100324call s:NetrwInit("g:netrw_alto" , &sb)
325call s:NetrwInit("g:netrw_altv" , &spr)
326call s:NetrwInit("g:netrw_banner" , 1)
327call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200328call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100329call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200330call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100331call s:NetrwInit("g:netrw_compress" , "gzip")
332call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200333if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
334 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
335 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000336endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200337call s:NetrwInit("g:netrw_cursor" , 2)
338let s:netrw_usercul = &cursorline
339let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200340"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100341call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000342" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200343call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200344call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200345call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100346call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200347call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100348call s:NetrwInit("g:netrw_fastbrowse" , 1)
349call 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 +0000350if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000351 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
352 let g:netrw_ftp_list_cmd = "ls -lF"
353 let g:netrw_ftp_timelist_cmd = "ls -tlF"
354 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000355 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000356 let g:netrw_ftp_list_cmd = "dir"
357 let g:netrw_ftp_timelist_cmd = "dir"
358 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000359 endif
360endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100361call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000362" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100363call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000364if !exists("g:netrw_ignorenetrc")
365 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
366 let g:netrw_ignorenetrc= 1
367 else
368 let g:netrw_ignorenetrc= 0
369 endif
370endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100371call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000372if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000373 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000374 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200375 " provide a pscp-based listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000376 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
377 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100378 if exists("g:netrw_list_cmd_options")
379 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
380 else
381 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
382 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000383 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200384 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100385 if exists("g:netrw_list_cmd_options")
386 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
387 else
388 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
389 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000390 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100391" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000392 let g:netrw_list_cmd= ""
393 endif
394endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100395call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000396" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200397if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200398 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200399 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
400endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100401if !exists("g:netrw_localcmdshell")
402 let g:netrw_localcmdshell= ""
403endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000404if !exists("g:netrw_localcopycmd")
405 if has("win32") || has("win95") || has("win64") || has("win16")
406 if g:netrw_cygwin
407 let g:netrw_localcopycmd= "cp"
408 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000409 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200410 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000411 endif
412 elseif has("unix") || has("macunix")
413 let g:netrw_localcopycmd= "cp"
414 else
415 let g:netrw_localcopycmd= ""
416 endif
417endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100418if !exists("g:netrw_localcopydircmd")
419 if has("win32") || has("win95") || has("win64") || has("win16")
420 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200421 let g:netrw_localcopydircmd = "cp"
422 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100423 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000424 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200425 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100426 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200427 elseif has("unix")
428 let g:netrw_localcopydircmd = "cp"
429 let g:netrw_localcopydircmdopt= " -R"
430 elseif has("macunix")
431 let g:netrw_localcopydircmd = "cp"
432 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100433 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200434 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100435 endif
436endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200437if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100438 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200439 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
440endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200441if has("win32") || has("win95") || has("win64") || has("win16")
442 if g:netrw_cygwin
443 call s:NetrwInit("g:netrw_localmkdir","mkdir")
444 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000445 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200446 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200447 endif
448else
449 call s:NetrwInit("g:netrw_localmkdir","mkdir")
450endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200451call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200452if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200453 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200454 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
455endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000456if !exists("g:netrw_localmovecmd")
457 if has("win32") || has("win95") || has("win64") || has("win16")
458 if g:netrw_cygwin
459 let g:netrw_localmovecmd= "mv"
460 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000461 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200462 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000463 endif
464 elseif has("unix") || has("macunix")
465 let g:netrw_localmovecmd= "mv"
466 else
467 let g:netrw_localmovecmd= ""
468 endif
469endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100470" following serves as an example for how to insert a version&patch specific test
471"if v:version < 704 || (v:version == 704 && !has("patch1107"))
472"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100473call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
474" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000475if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000476 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000477endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000478if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000479 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
480endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000481" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100482call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
483call s:NetrwInit("g:netrw_maxfilenamelen", 32)
484call s:NetrwInit("g:netrw_menu" , 1)
485call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200486call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100487call s:NetrwInit("g:netrw_retmap" , 0)
488if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
489 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
490elseif has("win32") || has("win95") || has("win64") || has("win16")
491 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
492else
493 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000494endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100495call s:NetrwInit("g:netrw_preview" , 0)
496call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100497call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100498call s:NetrwInit("g:netrw_sshport" , "-p")
499call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
500call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
501call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100502call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
503" Default values - q-s ---------- {{{3
504call s:NetrwInit("g:netrw_quickhelp",0)
505let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100506 \ "(create new) %:file d:directory",
507 \ "(windows split&open) o:horz v:vert p:preview",
508 \ "i:style qf:file info O:obtain r:reverse",
509 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
510 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
511 \ "(history) qb:list u:go up U:go down",
512 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100513" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
514call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100515if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
516 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
517else
518 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
519endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100520call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
521call s:NetrwInit("g:netrw_sort_options" , "")
522call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000523if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100524 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200525 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100526 else
527 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000528 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000529endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100530call s:NetrwInit("g:netrw_special_syntax" , 0)
531call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200532call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100533call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100534call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000535" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100536call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200537if !exists("g:netrw_xstrlen")
538 if exists("g:Align_xstrlen")
539 let g:netrw_xstrlen= g:Align_xstrlen
540 elseif exists("g:drawit_xstrlen")
541 let g:netrw_xstrlen= g:drawit_xstrlen
542 elseif &enc == "latin1" || !has("multi_byte")
543 let g:netrw_xstrlen= 0
544 else
545 let g:netrw_xstrlen= 1
546 endif
547endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100548call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100549call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200550call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100551call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200552if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000553" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000554" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100555call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200556if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarff034192013-04-24 18:51:19 +0200557 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200558else
Bram Moolenaarff034192013-04-24 18:51:19 +0200559 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200560endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200561call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100562call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
563call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100564if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100565 let s:treedepthstring= "│ "
566else
567 let s:treedepthstring= "| "
568endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200569call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000570
571" BufEnter event ignored by decho when following variable is true
572" Has a side effect that doau BufReadPost doesn't work, so
573" files read by network transfer aren't appropriately highlighted.
574"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575
Bram Moolenaaradc21822011-04-01 18:03:16 +0200576" ======================
577" Netrw Initialization: {{{1
578" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200579if 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 +0100580" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100581 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200582" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100583 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100584 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
585 au VimEnter * let s:initbeval= &beval
586"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100587" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
588" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
589" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
590" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
591" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
592" 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 +0200593endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200594au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200595
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200596if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100597 com! -nargs=* NetrwKeepj keepj <args>
598else
599 let g:netrw_keepj= ""
600 com! -nargs=* NetrwKeepj <args>
601endif
602
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000603" ==============================
604" Netrw Utility Functions: {{{1
605" ==============================
606
Bram Moolenaaradc21822011-04-01 18:03:16 +0200607" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100608" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100609if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100610" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100611 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100612 if &ft != "netrw"
613 return ""
614 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200615 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
616 " popup error window is still showing
617 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
618 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
619 " text under mouse hasn't changed; only close window when it changes
620 call popup_close(s:popuperr_id)
621 unlet s:popuperr_text
622 else
623 let s:popuperr_text= v:beval_text
624 endif
625 let mesg= ""
626 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 +0100627 let mesg= ""
628 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
629 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
630 elseif getline(v:beval_lnum) =~ '^"\s*/'
631 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
632 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100633 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100634 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
635 let mesg = "S: edit sorting sequence"
636 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
637 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
638 elseif v:beval_text == "Quick" || v:beval_text == "Help"
639 let mesg = "Help: press <F1>"
640 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
641 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
642 else
643 let mesg= ""
644 endif
645 return mesg
646 endfun
647"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100648" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
649" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
650" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
651" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
652" 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 +0200653endif
654
Bram Moolenaar071d4272004-06-13 20:20:40 +0000655" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200656" netrw#Explore: launch the local browser in the directory of the current file {{{2
657" indx: == -1: Nexplore
658" == -2: Pexplore
659" == +: this is overloaded:
660" * If Nexplore/Pexplore is in use, then this refers to the
661" indx'th item in the w:netrw_explore_list[] of items which
662" matched the */pattern **/pattern *//pattern **//pattern
663" * If Hexplore or Vexplore, then this will override
664" g:netrw_winsize to specify the qty of rows or columns the
665" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100666" 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 +0200667" dosplit==1: the window will be split before running the local browser
668" style == 0: Explore style == 1: Explore!
669" == 2: Hexplore style == 3: Hexplore!
670" == 4: Vexplore style == 5: Vexplore!
671" == 6: Texplore
672fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100673" 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 +0100674" 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 +0200675 if !exists("b:netrw_curdir")
676 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100677" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200678 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100679
680 " record current file for Rexplore's benefit
681 if &ft != "netrw"
682 let w:netrw_rexfile= expand("%:p")
683 endif
684
685 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200686 let curdir = simplify(b:netrw_curdir)
687 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200688 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
689 let curdir= substitute(curdir,'\','/','g')
690 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100691" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100692
693 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
694 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
695 " try Explore again.
696 if a:0 > 0
697" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100698 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
699 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
700 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
701 \ '~'.expand("<slnum>"))
702 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
703" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100704 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
705" call Dret("netrw#Explore : returning from retry")
706 return
707" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100708" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100709 endif
710 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200711
712 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200713 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100714" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100715 sil! let keepregstar = @*
716 sil! let keepregplus = @+
717 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200718 sil! let keepregslash= @/
719
Bram Moolenaar8d043172014-01-23 14:24:41 +0100720 " if dosplit
721 " -or- file has been modified AND file not hidden when abandoned
722 " -or- Texplore used
723 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100724" 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 +0200725 call s:SaveWinVars()
726 let winsz= g:netrw_winsize
727 if a:indx > 0
728 let winsz= a:indx
729 endif
730
731 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100732" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200733 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200734 if winsz == 0|let winsz= ""|endif
735 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100736" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200737
738 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100739" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200740 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200741 if winsz == 0|let winsz= ""|endif
742 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100743" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200744
745 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100746" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200747 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200748 if winsz == 0|let winsz= ""|endif
749 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100750" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200751
752 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100753" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200754 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200755 if winsz == 0|let winsz= ""|endif
756 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100757" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200758
759 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100760" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200761 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200762 if winsz == 0|let winsz= ""|endif
763 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100764" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200765
766 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100767" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200768 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200769 if winsz == 0|let winsz= ""|endif
770 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100771" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200772
773 elseif a:style == 6 " Texplore
774 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100775" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200776 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100777" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 call s:RestoreBufVars()
779 endif
780 call s:RestoreWinVars()
781" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100782" 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 +0200783 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100784 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200785
786 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100787" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200788 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100789" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200790 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100791" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200792 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100793" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200794 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
795 if dirname !~ '/$'
796 let dirname= dirname."/"
797 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100798" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200799 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100800" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200801 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100802" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200803 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100804" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200805 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100806" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200807 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100808" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200809 let dirname= a:1
810 endif
811 else
812 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100813" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200814 call s:NetrwClearExplore()
815" call Dret("netrw#Explore : cleared list")
816 return
817 endif
818
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100819" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200820 if dirname =~ '\.\./\=$'
821 let dirname= simplify(fnamemodify(dirname,':p:h'))
822 elseif dirname =~ '\.\.' || dirname == '.'
823 let dirname= simplify(fnamemodify(dirname,':p'))
824 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100825" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200826
827 if dirname =~ '^\*//'
828 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100829" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200830 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
831 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100832" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200833 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
834
835 elseif dirname =~ '^\*\*//'
836 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100837" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200838 let pattern= substitute(dirname,'^\*\*//','','')
839 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100840" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200841
842 elseif dirname =~ '/\*\*/'
843 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100844" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200845 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
846 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
847 let b:netrw_curdir = prefixdir
848 else
849 let b:netrw_curdir= getcwd().'/'.prefixdir
850 endif
851 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
852 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100853" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
854" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200855
856 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200857 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200858 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100859" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200860
861 elseif dirname=~ '^\*\*/'
862 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
863 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100864" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200865
866 else
867 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100868" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200869 endif
870
871 if starpat == 0 && a:indx >= 0
872 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100873" 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 +0200874 if dirname == ""
875 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100876" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200877 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200878 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200879 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200880 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200881 if dirname == ""
882 let dirname= getcwd()
883 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100884 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100885 " depending on whether backslashes have been converted to forward slashes by earlier code).
886 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200887 let dirname= b:netrw_curdir."/".dirname
888 endif
889 elseif dirname !~ '^/'
890 let dirname= b:netrw_curdir."/".dirname
891 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100892" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200893 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100894" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
895" 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 +0200896 endif
897 if exists("w:netrw_bannercnt")
898 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
899 " If one wants to return the same place in the netrw window, use :Rex instead.
900 exe w:netrw_bannercnt
901 endif
902
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100903" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200904 " ---------------------------------------------------------------------
905 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
906" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100907" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200908" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100909" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200910" endif
911 " ---------------------------------------------------------------------
912
913 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
914 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
915 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
916 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
917 elseif a:indx <= 0
918 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100919" 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 +0200920 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100921" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200922 let s:didstarstar= 1
923 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
924 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
925 endif
926
927 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100928" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200929 if !exists("w:netrw_explore_indx")
930 let w:netrw_explore_indx= 0
931 endif
932
933 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100934" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200935
936 if indx == -1
937 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100938" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200939 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100940 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 +0200941 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100942" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100943 if @* != keepregstar | sil! let @* = keepregstar | endif
944 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100945 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200946 sil! let @/ = keepregslash
947" call Dret("netrw#Explore")
948 return
949 endif
950 let indx= w:netrw_explore_indx
951 if indx < 0 | let indx= 0 | endif
952 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
953 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100954" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200955 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
956 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100957" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200958 endwhile
959 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100960" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200961
962 elseif indx == -2
963 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100964" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200965 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100966 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 +0200967 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100968" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100969 if @* != keepregstar | sil! let @* = keepregstar | endif
970 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100971 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200972 sil! let @/ = keepregslash
973" call Dret("netrw#Explore")
974 return
975 endif
976 let indx= w:netrw_explore_indx
977 if indx < 0 | let indx= 0 | endif
978 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
979 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100980" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200981 while indx >= 0 && curfile == w:netrw_explore_list[indx]
982 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100983" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200984 endwhile
985 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100986" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200987
988 else
989 " Explore -- initialize
990 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100991" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100992 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200993 let w:netrw_explore_indx= 0
994 if !exists("b:netrw_curdir")
995 let b:netrw_curdir= getcwd()
996 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100997" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200998
999 " switch on starpat to build the w:netrw_explore_list of files
1000 if starpat == 1
1001 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001002" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
1003" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001004 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001005 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001006 catch /^Vim\%((\a\+)\)\=:E480/
1007 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1008" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1009 return
1010 endtry
1011 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1012 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1013
1014 elseif starpat == 2
1015 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001016" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1017" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001018 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001019 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001020 catch /^Vim\%((\a\+)\)\=:E480/
1021 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1022 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001023 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001024" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001025 if @* != keepregstar | sil! let @* = keepregstar | endif
1026 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001027 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001028 sil! let @/ = keepregslash
1029" call Dret("netrw#Explore : no files matched pattern")
1030 return
1031 endtry
1032 let s:netrw_curdir = b:netrw_curdir
1033 let w:netrw_explore_list = getqflist()
1034 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1035 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1036
1037 elseif starpat == 3
1038 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001039" 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 +02001040 let filepat= substitute(dirname,'^\*/','','')
1041 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001042" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1043" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001044 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1045 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1046
1047 elseif starpat == 4
1048 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001049" 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 +02001050 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1051 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1052 endif " switch on starpat to build w:netrw_explore_list
1053
1054 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001055" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1056" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001057
1058 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001059 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001060 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001061" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001062 if @* != keepregstar | sil! let @* = keepregstar | endif
1063 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001064 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001065 sil! let @/ = keepregslash
1066" call Dret("netrw#Explore : no files matched")
1067 return
1068 endif
1069 endif " if indx ... endif
1070
1071 " NetrwStatusLine support - for exploring support
1072 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001073" 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 +02001074
1075 " wrap the indx around, but issue a note
1076 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001077" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001078 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1079 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001080 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001081 endif
1082
1083 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001084" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001085 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001086" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001087
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001088" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001089 call netrw#LocalBrowseCheck(newdir)
1090 if !exists("w:netrw_liststyle")
1091 let w:netrw_liststyle= g:netrw_liststyle
1092 endif
1093 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001094 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001095 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001096 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001097 endif
1098 let w:netrw_explore_mtchcnt = indx + 1
1099 let w:netrw_explore_bufnr = bufnr("%")
1100 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001101 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001102" 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 +02001103
1104 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001105" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001106 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001107 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 +02001108 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001109 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001110" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001111 if @* != keepregstar | sil! let @* = keepregstar | endif
1112 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001113 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001114 sil! let @/ = keepregslash
1115" call Dret("netrw#Explore : missing +path_extra")
1116 return
1117 endif
1118
1119 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001120" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001121 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1122 sil! unlet w:netrw_treedict
1123 sil! unlet w:netrw_treetop
1124 endif
1125 let newdir= dirname
1126 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001127 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001128 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001129 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001130 endif
1131 endif
1132
1133 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001134" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1135" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001136 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001137" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001138 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001139 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001140" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001141 let s:explore_prvdir = b:netrw_curdir
1142 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001143 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001144 if b:netrw_curdir !~ '/$'
1145 let dirlen= dirlen + 1
1146 endif
1147 let prvfname= ""
1148 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001149" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001150 if fname =~ '^'.b:netrw_curdir
1151 if s:explore_match == ""
1152 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1153 else
1154 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1155 endif
1156 elseif fname !~ '^/' && fname != prvfname
1157 if s:explore_match == ""
1158 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1159 else
1160 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1161 endif
1162 endif
1163 let prvfname= fname
1164 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001165" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001166 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1167 exe "2match netrwMarkFile /".s:explore_match."/"
1168 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001169 endif
1170 echo "<s-up>==Pexplore <s-down>==Nexplore"
1171 else
1172 2match none
1173 if exists("s:explore_match") | unlet s:explore_match | endif
1174 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001175" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001176 endif
1177
Bram Moolenaara6878372014-03-22 21:02:50 +01001178 " since Explore may be used to initialize netrw's browser,
1179 " there's no danger of a late FocusGained event on initialization.
1180 " Consequently, set s:netrw_events to 2.
1181 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001182 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001183" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001184 if @* != keepregstar | sil! let @* = keepregstar | endif
1185 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001186 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001187 sil! let @/ = keepregslash
1188" call Dret("netrw#Explore : @/<".@/.">")
1189endfun
1190
1191" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001192" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001193" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1194" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1195" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1196" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1197" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001198fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001199" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001200 let curwin= winnr()
1201
Bram Moolenaara6878372014-03-22 21:02:50 +01001202 if a:0 > 0 && a:1 != ""
1203 " if a netrw window is already on the left-side of the tab
1204 " and a directory has been specified, explore with that
1205 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001206" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001208" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001209 exe "1wincmd w"
1210 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001211" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001212 exe "Explore ".fnameescape(a1)
1213 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001214 let s:lexplore_win= curwin
1215 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001216 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001217" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001218 unlet t:netrw_lexposn
1219 endif
1220" call Dret("netrw#Lexplore")
1221 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001222 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001223 exe curwin."wincmd w"
1224 else
1225 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001226" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001227 endif
1228
Bram Moolenaar8d043172014-01-23 14:24:41 +01001229 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001230 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001231 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001232" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001233 else
1234 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001235" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001236 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001237" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001238
1239 if lexwinnr > 0
1240 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001241" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001242 exe lexwinnr."wincmd w"
1243 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001244 let t:netrw_lexposn = winsaveview()
1245" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001246" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001247 close
1248 if lexwinnr < curwin
1249 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001250 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001251 if lexwinnr != curwin
1252 exe curwin."wincmd w"
1253 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001254 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001255" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001256
1257 else
1258 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001259" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001260 exe "1wincmd w"
1261 let keep_altv = g:netrw_altv
1262 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001263 if a:count != 0
1264 let netrw_winsize = g:netrw_winsize
1265 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001266 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001267 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001268" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001269 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 +02001270" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001271 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001272" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001273 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001274 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001275 elseif curfile =~ '^\a\{3,}://'
1276" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001277 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001278 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001279" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001280 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001281 endif
1282 if a:count != 0
1283 let g:netrw_winsize = netrw_winsize
1284 endif
1285 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001286 let g:netrw_altv = keep_altv
1287 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001288 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1289 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001290 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001291 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001292" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1293" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001294 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001295" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001296" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1297 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001298 unlet t:netrw_lexposn
1299 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001300 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001301
1302 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001303 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001304 if a:rightside
1305 let g:netrw_chgwin= 1
1306 else
1307 let g:netrw_chgwin= 2
1308 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001309" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001310 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001311
Bram Moolenaar8d043172014-01-23 14:24:41 +01001312" call Dret("netrw#Lexplore")
1313endfun
1314
1315" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001316" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001317" supports :NetrwClean -- remove netrw from first directory on runtimepath
1318" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001319fun! netrw#Clean(sys)
1320" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001321
1322 if a:sys
1323 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1324 else
1325 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1326 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001327" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001328 let diddel= 0
1329 let diddir= ""
1330
1331 if choice == 1
1332 for dir in split(&rtp,',')
1333 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001334" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001335 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1336 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1337 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1338 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1339 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1340 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 +00001341 let diddir= dir
1342 let diddel= diddel + 1
1343 if !a:sys|break|endif
1344 endif
1345 endfor
1346 endif
1347
1348 echohl WarningMsg
1349 if diddel == 0
1350 echomsg "netrw is either not installed or not removable"
1351 elseif diddel == 1
1352 echomsg "removed one copy of netrw from <".diddir.">"
1353 else
1354 echomsg "removed ".diddel." copies of netrw"
1355 endif
1356 echohl None
1357
Bram Moolenaara6878372014-03-22 21:02:50 +01001358" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001359endfun
1360
Bram Moolenaar5c736222010-01-06 20:54:52 +01001361" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001362" netrw#MakeTgt: make a target out of the directory name provided {{{2
1363fun! netrw#MakeTgt(dname)
1364" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1365 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001366 let svpos = winsaveview()
1367" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001368 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1369" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001370 if s:netrwmftgt_islocal
1371 let netrwmftgt= simplify(a:dname)
1372 else
1373 let netrwmftgt= a:dname
1374 endif
1375 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1376 " re-selected target, so just clear it
1377 unlet s:netrwmftgt s:netrwmftgt_islocal
1378 else
1379 let s:netrwmftgt= netrwmftgt
1380 endif
1381 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001382 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001383 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001384" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1385 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001386" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001387endfun
1388
Bram Moolenaara6878372014-03-22 21:02:50 +01001389" ---------------------------------------------------------------------
1390" netrw#Obtain: {{{2
1391" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001392" islocal=0 obtain from remote source
1393" =1 obtain from local source
1394" fname : a filename or a list of filenames
1395" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001396fun! netrw#Obtain(islocal,fname,...)
1397" 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 +02001398 " NetrwStatusLine support - for obtaining support
1399
1400 if type(a:fname) == 1
1401 let fnamelist= [ a:fname ]
1402 elseif type(a:fname) == 3
1403 let fnamelist= a:fname
1404 else
1405 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 +01001406" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001407 return
1408 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001409" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001410 if a:0 > 0
1411 let tgtdir= a:1
1412 else
1413 let tgtdir= getcwd()
1414 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001415" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001416
1417 if exists("b:netrw_islocal") && b:netrw_islocal
1418 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001419" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001420 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1421 let topath= s:ComposePath(tgtdir,"")
1422 if (has("win32") || has("win95") || has("win64") || has("win16"))
1423 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001424" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001425 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001426" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001427 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001428 if v:shell_error != 0
1429 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 +01001430" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001431 return
1432 endif
1433 endfor
1434 else
1435 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001436" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1437 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1438" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001439 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001440 if v:shell_error != 0
1441 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 +01001442" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001443 return
1444 endif
1445 endif
1446 elseif !exists("b:netrw_curdir")
1447 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1448 else
1449 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1450 endif
1451
1452 else
1453 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001454" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001455 if type(a:fname) == 1
1456 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1457 endif
1458 call s:NetrwMethod(b:netrw_curdir)
1459
1460 if b:netrw_method == 4
1461 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001462" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001463 if exists("g:netrw_port") && g:netrw_port != ""
1464 let useport= " ".g:netrw_scpport." ".g:netrw_port
1465 else
1466 let useport= ""
1467 endif
1468 if b:netrw_fname =~ '/'
1469 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1470 else
1471 let path= ""
1472 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001473 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001474 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 +02001475
1476 elseif b:netrw_method == 2
1477 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001478" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001479 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001480 let tmpbufnr= bufnr("%")
1481 setl ff=unix
1482 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001483 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001484" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001485 endif
1486
1487 if exists("b:netrw_fname") && b:netrw_fname != ""
1488 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001489" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001490 endif
1491
1492 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001493 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001494" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001495 endif
1496 for fname in fnamelist
1497 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001498" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001499 endfor
1500 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001501 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 +02001502 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001503 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001504 endif
1505 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1506 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1507 let debugkeep= &debug
1508 setl debug=msg
1509 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1510 let &debug= debugkeep
1511 endif
1512
1513 elseif b:netrw_method == 3
1514 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001515" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001516 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001517 let tmpbufnr= bufnr("%")
1518 setl ff=unix
1519
1520 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001521 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001522" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001523 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001524 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001525" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001526 endif
1527
1528 if exists("g:netrw_uid") && g:netrw_uid != ""
1529 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001530 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001531" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001532 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001533 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001534 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001535" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001536 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001537 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001538" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001539 endif
1540 endif
1541
1542 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001543 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001544" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001545 endif
1546
1547 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001548 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001549" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001550 endif
1551
1552 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001553 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001554" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001555 endif
1556
1557 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001558 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001559" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001560 endif
1561 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001562 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001563 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001564" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001565
1566 " perform ftp:
1567 " -i : turns off interactive prompting from ftp
1568 " -n unix : DON'T use <.netrc>, even though it exists
1569 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001570 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1571 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001572 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001573 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1574 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001575" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001576 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001577 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001578 endif
1579 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001580
1581 elseif b:netrw_method == 9
1582 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001583" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001584 if a:fname =~ '/'
1585 let localfile= substitute(a:fname,'^.*/','','')
1586 else
1587 let localfile= a:fname
1588 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001589 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 +02001590
Bram Moolenaarff034192013-04-24 18:51:19 +02001591 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001592 " probably a badly formed url; protocol not recognized
1593" call Dret("netrw#Obtain : unsupported method")
1594 return
1595
1596 else
1597 " protocol recognized but not supported for Obtain (yet?)
1598 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001599 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001600 endif
1601" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001602 return
1603 endif
1604
1605 " restore status line
1606 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001607 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001608 endif
1609
1610 endif
1611
1612 " cleanup
1613 if exists("tmpbufnr")
1614 if bufnr("%") != tmpbufnr
1615 exe tmpbufnr."bw!"
1616 else
1617 q!
1618 endif
1619 endif
1620
Bram Moolenaara6878372014-03-22 21:02:50 +01001621" call Dret("netrw#Obtain")
1622endfun
1623
1624" ---------------------------------------------------------------------
1625" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1626fun! netrw#Nread(mode,fname)
1627" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001628 let svpos= winsaveview()
1629" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001630 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001631" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1632 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001633
1634 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1635 if exists("w:netrw_bannercnt")
1636 " start with cursor just after the banner
1637 exe w:netrw_bannercnt
1638 endif
1639 endif
1640" call Dret("netrw#Nread")
1641endfun
1642
1643" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001644" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1645" Options get restored by s:NetrwOptionsRestore()
1646"
1647" Option handling:
1648" * save user's options (s:NetrwOptionsSave)
1649" * set netrw-safe options (s:NetrwOptionsSafe)
1650" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1651" * restore user's options (s:netrwOPtionsRestore)
1652" - restore a user option when != safe option (s:NetrwRestoreSetting)
1653" vt: (variable type) normally its either "w:" or "s:"
1654fun! s:NetrwOptionsSave(vt)
1655" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1656" 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 +02001657" 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>"))
1658" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001659
1660 if !exists("{a:vt}netrw_optionsave")
1661 let {a:vt}netrw_optionsave= 1
1662 else
1663" call Dret("s:NetrwOptionsSave : options already saved")
1664 return
1665 endif
1666" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1667
1668 " Save current settings and current directory
1669" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1670 let s:yykeep = @@
1671 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1672 let {a:vt}netrw_aikeep = &l:ai
1673 let {a:vt}netrw_awkeep = &l:aw
1674 let {a:vt}netrw_bhkeep = &l:bh
1675 let {a:vt}netrw_blkeep = &l:bl
1676 let {a:vt}netrw_btkeep = &l:bt
1677 let {a:vt}netrw_bombkeep = &l:bomb
1678 let {a:vt}netrw_cedit = &cedit
1679 let {a:vt}netrw_cikeep = &l:ci
1680 let {a:vt}netrw_cinkeep = &l:cin
1681 let {a:vt}netrw_cinokeep = &l:cino
1682 let {a:vt}netrw_comkeep = &l:com
1683 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001684 let {a:vt}netrw_cuckeep = &l:cuc
1685 let {a:vt}netrw_culkeep = &l:cul
1686" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001687 let {a:vt}netrw_diffkeep = &l:diff
1688 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001689 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1690 let {a:vt}netrw_ffkeep = &l:ff
1691 endif
1692 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1693 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001694 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001695 let {a:vt}netrw_hidkeep = &l:hidden
1696 let {a:vt}netrw_imkeep = &l:im
1697 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001698 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001699 let {a:vt}netrw_lskeep = &l:ls
1700 let {a:vt}netrw_makeep = &l:ma
1701 let {a:vt}netrw_magickeep = &l:magic
1702 let {a:vt}netrw_modkeep = &l:mod
1703 let {a:vt}netrw_nukeep = &l:nu
1704 let {a:vt}netrw_rnukeep = &l:rnu
1705 let {a:vt}netrw_repkeep = &l:report
1706 let {a:vt}netrw_rokeep = &l:ro
1707 let {a:vt}netrw_selkeep = &l:sel
1708 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001709 if !g:netrw_use_noswf
1710 let {a:vt}netrw_swfkeep = &l:swf
1711 endif
1712 let {a:vt}netrw_tskeep = &l:ts
1713 let {a:vt}netrw_twkeep = &l:tw " textwidth
1714 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1715 let {a:vt}netrw_wrapkeep = &l:wrap
1716 let {a:vt}netrw_writekeep = &l:write
1717
1718 " save a few selected netrw-related variables
1719" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1720 if g:netrw_keepdir
1721 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001722" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001723 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001724 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001725 sil! let {a:vt}netrw_starkeep = @*
1726 sil! let {a:vt}netrw_pluskeep = @+
1727 endif
1728 sil! let {a:vt}netrw_slashkeep= @/
1729
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001730" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001731" 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>"))
1732" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1733endfun
1734
1735" ---------------------------------------------------------------------
1736" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1737" Use s:NetrwSaveOptions() to save user settings
1738" Use s:NetrwOptionsRestore() to restore user settings
1739fun! s:NetrwOptionsSafe(islocal)
1740" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1741" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1742" 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>"))
1743 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1744 call s:NetrwSetSafeSetting("&l:ai",0)
1745 call s:NetrwSetSafeSetting("&l:aw",0)
1746 call s:NetrwSetSafeSetting("&l:bl",0)
1747 call s:NetrwSetSafeSetting("&l:bomb",0)
1748 if a:islocal
1749 call s:NetrwSetSafeSetting("&l:bt","nofile")
1750 else
1751 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1752 endif
1753 call s:NetrwSetSafeSetting("&l:ci",0)
1754 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001755 if g:netrw_fastbrowse > a:islocal
1756 call s:NetrwSetSafeSetting("&l:bh","hide")
1757 else
1758 call s:NetrwSetSafeSetting("&l:bh","delete")
1759 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001760 call s:NetrwSetSafeSetting("&l:cino","")
1761 call s:NetrwSetSafeSetting("&l:com","")
1762 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1763 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1764 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001765 if &go =~ 'a' | set go-=a | endif
1766 if &go =~ 'A' | set go-=A | endif
1767 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001768 call s:NetrwSetSafeSetting("&l:hid",0)
1769 call s:NetrwSetSafeSetting("&l:im",0)
1770 setl isk+=@ isk+=* isk+=/
1771 call s:NetrwSetSafeSetting("&l:magic",1)
1772 if g:netrw_use_noswf
1773 call s:NetrwSetSafeSetting("swf",0)
1774 endif
1775 call s:NetrwSetSafeSetting("&l:report",10000)
1776 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1777 call s:NetrwSetSafeSetting("&l:spell",0)
1778 call s:NetrwSetSafeSetting("&l:tw",0)
1779 call s:NetrwSetSafeSetting("&l:wig","")
1780 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001781
1782 " set up cuc and cul based on g:netrw_cursor and listing style
1783 " COMBAK -- cuc cul related
1784 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001785
1786 " allow the user to override safe options
1787" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1788 if &ft == "netrw"
1789" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1790 keepalt NetrwKeepj doau FileType netrw
1791 endif
1792
1793" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1794" 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>"))
1795" call Dret("s:NetrwOptionsSafe")
1796endfun
1797
1798" ---------------------------------------------------------------------
1799" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1800fun! s:NetrwOptionsRestore(vt)
1801" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001802" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001803" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001804 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001805" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01001806 if filereadable(expand("%"))
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001807" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001808 filetype detect
1809" 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>"))
1810 else
1811 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001812 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001813" 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 +02001814" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001815 return
1816 endif
1817 unlet {a:vt}netrw_optionsave
1818
1819 if exists("+acd")
1820 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001821" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001822 let curdir = getcwd()
1823 let &l:acd = {a:vt}netrw_acdkeep
1824 unlet {a:vt}netrw_acdkeep
1825 if &l:acd
1826 call s:NetrwLcd(curdir)
1827 endif
1828 endif
1829 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001830" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001831 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1832 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1833 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1834 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1835 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001836" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001837 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1838 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1839 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1840 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1841 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001842" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001843 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1844 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1845 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1846 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1847 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001848 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001849" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1850 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1851 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001852 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001853 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1854" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1855 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1856 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1857" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1858 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1859" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1860 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1861 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001862 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001863 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1864 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1865" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1866 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1867 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1868 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1869 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1870" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001871 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001872 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1873 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1874 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001875 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001876" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001877 call s:NetrwRestoreSetting("s:yykeep","@@")
1878 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1879 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1880 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1881 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1882
Bram Moolenaara6878372014-03-22 21:02:50 +01001883 if exists("{a:vt}netrw_swfkeep")
1884 if &directory == ""
1885 " user hasn't specified a swapfile directory;
1886 " netrw will temporarily set the swapfile directory
1887 " to the current directory as returned by getcwd().
1888 let &l:directory= getcwd()
1889 sil! let &l:swf = {a:vt}netrw_swfkeep
1890 setl directory=
1891 unlet {a:vt}netrw_swfkeep
1892 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001893 if !g:netrw_use_noswf
1894 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1895 sil! let &l:swf= {a:vt}netrw_swfkeep
1896 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001897 unlet {a:vt}netrw_swfkeep
1898 endif
1899 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001900 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001901 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1902 if exists("{a:vt}netrw_dirkeep")
1903 call s:NetrwLcd(dirkeep)
1904 unlet {a:vt}netrw_dirkeep
1905 endif
1906 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001907 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001908" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001909 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1910 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001911 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001912 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001913
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001914" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1915" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1916" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1917" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1918" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001919 " Moved the filetype detect here from NetrwGetFile() because remote files
1920 " were having their filetype detect-generated settings overwritten by
1921 " NetrwOptionRestore.
1922 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001923" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1924 filetype detect
1925" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001926 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001927" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001928" 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 +02001929" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001930endfun
1931
1932" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001933" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1934" but only when the options' value and the safe setting differ
1935" Doing this means that netrw will not come up as having changed a
1936" setting last when it really didn't actually change it.
1937"
1938" Called from s:NetrwOptionsSafe
1939" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1940fun! s:NetrwSetSafeSetting(setting,safesetting)
1941" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001942
Bram Moolenaar85850f32019-07-19 22:05:51 +02001943 if a:setting =~ '^&'
1944" call Decho("fyi: a:setting starts with &")
1945 exe "let settingval= ".a:setting
1946" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001947
Bram Moolenaar85850f32019-07-19 22:05:51 +02001948 if settingval != a:safesetting
1949" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1950 if type(a:safesetting) == 0
1951 exe "let ".a:setting."=".a:safesetting
1952 elseif type(a:safesetting) == 1
1953 exe "let ".a:setting."= '".a:safesetting."'"
1954 else
1955 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1956 endif
1957 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001958 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001959
Bram Moolenaar85850f32019-07-19 22:05:51 +02001960" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001961endfun
1962
1963" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001964" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1965" but only if the setting value differs from the associated keepvar.
1966" Doing this means that netrw will not come up as having changed a
1967" setting last when it really didn't actually change it.
1968"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001969" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001970" keepvars are set up by s:NetrwOptionsSave
1971fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001972""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001973
Bram Moolenaar85850f32019-07-19 22:05:51 +02001974 " typically called from s:NetrwOptionsRestore
1975 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1976 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001977 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001978 if exists(a:keepvar)
1979 exe "let keepvarval= ".a:keepvar
1980 exe "let setting= ".a:setting
1981
1982"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1983"" call Decho("fyi: keepvarval=".keepvarval)
1984"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1985
1986 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001987"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001988 if type(a:setting) == 0
1989 exe "let ".a:setting."= ".keepvarval
1990 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001991 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001992 else
1993 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1994 endif
1995 endif
1996
1997 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001998 endif
1999
Bram Moolenaar85850f32019-07-19 22:05:51 +02002000"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02002001endfun
2002
2003" ---------------------------------------------------------------------
2004" NetrwStatusLine: {{{2
2005fun! NetrwStatusLine()
2006
2007" vvv NetrwStatusLine() debugging vvv
2008" let g:stlmsg=""
2009" if !exists("w:netrw_explore_bufnr")
2010" let g:stlmsg="!X<explore_bufnr>"
2011" elseif w:netrw_explore_bufnr != bufnr("%")
2012" let g:stlmsg="explore_bufnr!=".bufnr("%")
2013" endif
2014" if !exists("w:netrw_explore_line")
2015" let g:stlmsg=" !X<explore_line>"
2016" elseif w:netrw_explore_line != line(".")
2017" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2018" endif
2019" if !exists("w:netrw_explore_list")
2020" let g:stlmsg=" !X<explore_list>"
2021" endif
2022" ^^^ NetrwStatusLine() debugging ^^^
2023
2024 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")
2025 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002026 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002027 let &laststatus = s:netrw_users_ls
2028 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2029 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2030 return ""
2031 else
2032 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2033 endif
2034endfun
2035
Bram Moolenaar85850f32019-07-19 22:05:51 +02002036" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002037" Netrw Transfer Functions: {{{1
2038" ===============================
2039
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002041" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002042" mode: =0 read remote file and insert before current line
2043" =1 read remote file and insert after current line
2044" =2 replace with remote file
2045" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002046fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002047" 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 +00002048
Bram Moolenaar5c736222010-01-06 20:54:52 +01002049 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002050 call s:NetrwOptionsSave("w:")
2051 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002052 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002053 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2054 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2055 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002056" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002057
Bram Moolenaar5c736222010-01-06 20:54:52 +01002058 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002059 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002060 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002061 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002062 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002063 elseif a:mode == 2 " replace with remote file
2064 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002065 elseif a:mode == 3 " skip read of file (leave as temporary)
2066 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002067 else
2068 exe a:mode
2069 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002070 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002071 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002072" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002073
Bram Moolenaar5c736222010-01-06 20:54:52 +01002074 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002075 let tmpfile= s:GetTempfile("")
2076 if tmpfile == ""
2077" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002078 return
2079 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002080
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002081 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002082
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002083 " attempt to repeat with previous host-file-etc
2084 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002085" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002086 let choice = b:netrw_lastfile
2087 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002088
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002089 else
2090 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002091" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002092
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002093 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002094 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002095 echomsg 'NetRead Usage:'
2096 echomsg ':Nread machine:path uses rcp'
2097 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2098 echomsg ':Nread "machine id password path" uses ftp'
2099 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2100 echomsg ':Nread fetch://machine/path uses fetch'
2101 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2102 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002103 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002104 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002105 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2106 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2107 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2108 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002109 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002110 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002111
Bram Moolenaar9964e462007-05-05 17:54:07 +00002112 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002113 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002114" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002115 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002116 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002117 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002118 else
2119 " case "... ... ..."
2120 let choice = strpart(choice,1,strlen(choice)-1)
2121 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002122
Bram Moolenaar9964e462007-05-05 17:54:07 +00002123 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002124 let wholechoice = wholechoice . " " . choice
2125 let ichoice = ichoice + 1
2126 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002127 if !exists("g:netrw_quiet")
2128 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2129 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002130" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002131 return
2132 endif
2133 let choice= a:{ichoice}
2134 endwhile
2135 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2136 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002137 endif
2138 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002139
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002140" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002141 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002142
Bram Moolenaar5c736222010-01-06 20:54:52 +01002143 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002144 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002145 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002146" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002147 return
2148 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002149 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002150
Bram Moolenaar8d043172014-01-23 14:24:41 +01002151 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002152" 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 +02002153 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002154" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002155 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002156" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002157 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002158 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002159
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002160 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002161 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002162 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002163 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2164 echo "(netrw) Processing your read request..."
2165 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002166
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002167 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002168 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002169 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002170" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002171 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002172 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002173 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002174 " ER: the tmpfile is full path: rcp sees C:\... as host C
2175 if s:netrw_has_nt_rcp == 1
2176 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2177 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2178 else
2179 " Any way needed it machine contains a '.'
2180 let uid_machine = g:netrw_machine .'.'. $USERNAME
2181 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002182 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002183 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2184 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2185 else
2186 let uid_machine = g:netrw_machine
2187 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002188 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002189 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 +00002190 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002191 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002192
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002193 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002194 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002195 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002196" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002197 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002198 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002199 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002200 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002201 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002202" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002203 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002204 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002206 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002207 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002208" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002209 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002210 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 +00002211 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002212 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002213 endif
2214 " 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 +00002215 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002216 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002217 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002218 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002219 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002220 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002221 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002222 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002223 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2224 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002225 q!
2226 endif
2227 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002228 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002230
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002231 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002232 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002233 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2234 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002235" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002236 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002237 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002238 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002239 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002240 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002241 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002242" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002243 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002244 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002245" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002246 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002247
Bram Moolenaar97d62492012-11-15 21:28:22 +01002248 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002249 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002250 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002251" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002252 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002253 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002254 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002255" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002256 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002257 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002258" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002259 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002260 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002261
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002262 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002263 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002264" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002265 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002266 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002267 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002268" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002269 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002270 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002271" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002272
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002273 " perform ftp:
2274 " -i : turns off interactive prompting from ftp
2275 " -n unix : DON'T use <.netrc>, even though it exists
2276 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002277 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002278 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002279 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2280 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002281" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002282 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002283 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002284 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002285 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002286 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002287 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002288 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002289
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002290 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002291 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002292 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002293" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002294 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002295 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002296 else
2297 let useport= ""
2298 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002299 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2300 " This is workaround to avoid mis-handle windows local-path:
2301 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2302 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2303 else
2304 let tmpfile_get = tmpfile
2305 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002306 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 +00002307 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002308 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002309
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002310 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002311 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002312 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002313" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002314 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002315 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002316 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002317 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002318" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002319 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002320 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002321
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002322 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2323 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002324" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002325 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002326 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 +00002327 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002328 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 +00002329 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002330 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002331
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002332 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002333 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002334" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002335 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2336 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002337" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2338" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2339 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 +00002340 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002341" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002342 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002343 endif
2344 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002345" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002346 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002347
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002348 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002349 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002350 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002351" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002352
Bram Moolenaar5c736222010-01-06 20:54:52 +01002353 if !executable(g:netrw_dav_cmd)
2354 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2355" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2356 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002357 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002358 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002359 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 +01002360 else
2361 " Construct execution string (four lines) which will be passed through filter
2362 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2363 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002364 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002365 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002366 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002367 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002368 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002369 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002370 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002371 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002372 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002373 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2374 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002375
Bram Moolenaar5c736222010-01-06 20:54:52 +01002376 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002377 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002378 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002379 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002380 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002381 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002382 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002383
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002384 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002385 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002386 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002387" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002388 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 +00002389 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002390 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002391
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002392 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002393 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002394 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002395 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002396" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002397 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002398 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002399 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002400 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002401" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002402 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002403 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002404 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002405 let netrw_option= "http"
2406 else
2407 let netrw_option= "ftp"
2408 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002409" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002410
Bram Moolenaar446cb832008-06-24 21:56:24 +00002411 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002412 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 +00002413 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002414 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 +00002415 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002416
Bram Moolenaar446cb832008-06-24 21:56:24 +00002417 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002418 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002419" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002420 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002421
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002422 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002423 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002424 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002425" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2426 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 +00002427 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002428 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002429
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002430 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002431 " NetRead: (file) NetRead Method #10 {{{3
2432 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002433" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2434 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002435 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2436 let b:netrw_lastfile = choice
2437
2438 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002439 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002440 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002441 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002442 endif
2443 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002444
Bram Moolenaar5c736222010-01-06 20:54:52 +01002445 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002446 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002447" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002448 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002449 unlet b:netrw_fname
2450 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002451 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 +01002452" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002453 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002454 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002455 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002456
Bram Moolenaar9964e462007-05-05 17:54:07 +00002457" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002458endfun
2459
2460" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002461" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002462fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002463" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002464
Bram Moolenaar5c736222010-01-06 20:54:52 +01002465 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002466 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002467 call s:NetrwOptionsSave("w:")
2468 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002469
Bram Moolenaar5c736222010-01-06 20:54:52 +01002470 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002471 let tmpfile= s:GetTempfile("")
2472 if tmpfile == ""
2473" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002474 return
2475 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002476
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002477 if a:0 == 0
2478 let ichoice = 0
2479 else
2480 let ichoice = 1
2481 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002482
Bram Moolenaar9964e462007-05-05 17:54:07 +00002483 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002484" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002485 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002486 " For binary writes, always write entire file.
2487 " (line numbers don't really make sense for that).
2488 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002489" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002490 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002491 elseif g:netrw_cygwin
2492 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002493 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002494" 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 +01002495 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002496 else
2497 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002498" 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 +01002499 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002500 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002501
Bram Moolenaar9964e462007-05-05 17:54:07 +00002502 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002503 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002504 " on the temporary file's name. Deletion of the temporary file during
2505 " cleanup then causes an error message.
2506 0file!
2507 endif
2508
Bram Moolenaar5c736222010-01-06 20:54:52 +01002509 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002510 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002511
Bram Moolenaar9964e462007-05-05 17:54:07 +00002512 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002513 " attempt to repeat with previous host-file-etc
2514 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002515" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002516 let choice = b:netrw_lastfile
2517 let ichoice= ichoice + 1
2518 else
2519 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002520
Bram Moolenaar8d043172014-01-23 14:24:41 +01002521 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002522 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002523 echomsg 'NetWrite Usage:"'
2524 echomsg ':Nwrite machine:path uses rcp'
2525 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2526 echomsg ':Nwrite "machine id password path" uses ftp'
2527 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2528 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2529 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2530 echomsg ':Nwrite rcp://machine/path uses rcp'
2531 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2532 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2533 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002534 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002535 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002536
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002537 elseif match(choice,"^\"") != -1
2538 if match(choice,"\"$") != -1
2539 " case "..."
2540 let choice=strpart(choice,1,strlen(choice)-2)
2541 else
2542 " case "... ... ..."
2543 let choice = strpart(choice,1,strlen(choice)-1)
2544 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002545
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002546 while match(choice,"\"$") == -1
2547 let wholechoice= wholechoice . " " . choice
2548 let ichoice = ichoice + 1
2549 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002550 if !exists("g:netrw_quiet")
2551 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2552 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002553" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002554 return
2555 endif
2556 let choice= a:{ichoice}
2557 endwhile
2558 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2559 endif
2560 endif
2561 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002562 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002563" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002564
Bram Moolenaar9964e462007-05-05 17:54:07 +00002565 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002566 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002567 if !exists("b:netrw_method") || b:netrw_method < 0
2568" call Dfunc("netrw#NetWrite : unsupported method")
2569 return
2570 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002571
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002572 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002573 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002574 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002575 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2576 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002577" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002578 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002579
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002580 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002581 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002582 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002583" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002584 if s:netrw_has_nt_rcp == 1
2585 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2586 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2587 else
2588 let uid_machine = g:netrw_machine .'.'. $USERNAME
2589 endif
2590 else
2591 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2592 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2593 else
2594 let uid_machine = g:netrw_machine
2595 endif
2596 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002597 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 +00002598 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002599
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002600 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002601 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002602 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002603" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002604 let netrw_fname = b:netrw_fname
2605
2606 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2607 let bhkeep = &l:bh
2608 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002609 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002610 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002611
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002612" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002613 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002614 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002615" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002616 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002617 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002618" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002619 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002620 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002621" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002623 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 +00002624 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002625" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2626 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 endif
2628 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2629 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002630 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002631 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002632 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002633 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002635
2636 " remove enew buffer (quietly)
2637 let filtbuf= bufnr("%")
2638 exe curbuf."b!"
2639 let &l:bh = bhkeep
2640 exe filtbuf."bw!"
2641
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002643
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002644 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002645 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002646 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002647 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002648" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002649 let netrw_fname = b:netrw_fname
2650 let bhkeep = &l:bh
2651
2652 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2653 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002654 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002655 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002656 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002657
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002658 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002659 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002660" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002661 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002662 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002663" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002664 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002665 if exists("g:netrw_uid") && g:netrw_uid != ""
2666 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002667 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002668" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002669 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002670 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002671 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002672" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002673 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002674 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002675" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002676 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002677 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002678 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002679" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002680 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002681 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002682" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002683 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002684 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002685" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002686 " save choice/id/password for future use
2687 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002688
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002689 " perform ftp:
2690 " -i : turns off interactive prompting from ftp
2691 " -n unix : DON'T use <.netrc>, even though it exists
2692 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002693 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002694 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002695 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2696 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002697 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002698 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002699 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002700 let mod=1
2701 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002702
2703 " remove enew buffer (quietly)
2704 let filtbuf= bufnr("%")
2705 exe curbuf."b!"
2706 let &l:bh= bhkeep
2707 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002708
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002709 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002710 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002711 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002712" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002713 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002714 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002715 else
2716 let useport= ""
2717 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002718 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 +00002719 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002720
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002721 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002722 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002723 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002724" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002725 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2726 if executable(curl)
2727 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002728 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 +01002729 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002730 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002731 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002732
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002733 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002734 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002735 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002736" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002737
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002738 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002739 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2740 let bhkeep = &l:bh
2741
2742 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2743 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002744 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002745 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002746
Bram Moolenaarff034192013-04-24 18:51:19 +02002747 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002748 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002749 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002750 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002751 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002752 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002753 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002754 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002755 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002756 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002757
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002758 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002759 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002760 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002761
2762 " remove enew buffer (quietly)
2763 let filtbuf= bufnr("%")
2764 exe curbuf."b!"
2765 let &l:bh = bhkeep
2766 exe filtbuf."bw!"
2767
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002768 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002769
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002770 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002771 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002772 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002773" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002774 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 +00002775 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002776
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002777 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002778 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002779 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002780" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002781 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2783 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2784 else
2785 let uid_machine = g:netrw_machine
2786 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002787
2788 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2789 let bhkeep = &l:bh
2790 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002791 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002792 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002793
Bram Moolenaarff034192013-04-24 18:51:19 +02002794 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002795 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002796" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002797 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002798 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002799 let filtbuf= bufnr("%")
2800 exe curbuf."b!"
2801 let &l:bh = bhkeep
2802 exe filtbuf."bw!"
2803 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002804
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002805 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002806 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002807 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002808 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002809 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002811 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002812
Bram Moolenaar5c736222010-01-06 20:54:52 +01002813 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002814" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002815 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002816" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002817 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002818 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002819 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002820
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002821 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002822 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002823 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002824" 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 +02002825 elseif !exists("leavemod")
2826 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002827" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002828 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002829" 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 +00002830 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002831
Bram Moolenaar9964e462007-05-05 17:54:07 +00002832" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002833endfun
2834
2835" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002836" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002837" uses NetRead to get a copy of the file into a temporarily file,
2838" then sources that file,
2839" then removes that file.
2840fun! netrw#NetSource(...)
2841" call Dfunc("netrw#NetSource() a:0=".a:0)
2842 if a:0 > 0 && a:1 == '?'
2843 " give help
2844 echomsg 'NetSource Usage:'
2845 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2846 echomsg ':Nsource fetch://machine/path uses fetch'
2847 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002848 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002849 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2850 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2851 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2852 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2853 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002854 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002855 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002856 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002857 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002858" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002859 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002860" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002861 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002862" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002863 if delete(s:netrw_tmpfile)
2864 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2865 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002866 unlet s:netrw_tmpfile
2867 else
2868 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2869 endif
2870 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002871 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002872 endif
2873" call Dret("netrw#NetSource")
2874endfun
2875
Bram Moolenaar8d043172014-01-23 14:24:41 +01002876" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002877" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2878" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002879fun! netrw#SetTreetop(iscmd,...)
2880" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2881" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002882
Bram Moolenaar85850f32019-07-19 22:05:51 +02002883 " iscmd==0: netrw#SetTreetop called using gn mapping
2884 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2885" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002886 " clear out the current tree
2887 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002888" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002889 let inittreetop= w:netrw_treetop
2890 unlet w:netrw_treetop
2891 endif
2892 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002893" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002894 unlet w:netrw_treedict
2895 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002896" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002897
Bram Moolenaar85850f32019-07-19 22:05:51 +02002898 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002899 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002900" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002901 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002902 if isdirectory(s:NetrwFile(a:1))
2903" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002904 let treedir = a:1
2905 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002906 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002907 let treedir = b:netrw_curdir."/".a:1
2908 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002909" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002910 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002911 " normally the cursor is left in the message window.
2912 " However, here this results in the directory being listed in the message window, which is not wanted.
2913 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002914 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002915 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002916 let treedir = "."
2917 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002918 endif
2919 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002920" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002921
2922 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002923 let islocal= expand("%") !~ '^\a\{3,}://'
2924" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002925
2926 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002927 if islocal
2928 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2929 else
2930 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2931 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002932
Bram Moolenaara6878372014-03-22 21:02:50 +01002933" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002934endfun
2935
Bram Moolenaar9964e462007-05-05 17:54:07 +00002936" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002937" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002938" readcmd == %r : replace buffer with newly read file
2939" == 0r : read file at top of buffer
2940" == r : read file after current line
2941" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002942fun! s:NetrwGetFile(readcmd, tfile, method)
2943" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002944
2945 " readcmd=='t': simply do nothing
2946 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002947" 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 +01002948" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002949 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002950 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002951
Bram Moolenaar9964e462007-05-05 17:54:07 +00002952 " get name of remote filename (ie. url and all)
2953 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002954" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002955
Bram Moolenaar9964e462007-05-05 17:54:07 +00002956 if exists("*NetReadFixup")
2957 " for the use of NetReadFixup (not otherwise used internally)
2958 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002959 endif
2960
Bram Moolenaar9964e462007-05-05 17:54:07 +00002961 if a:readcmd[0] == '%'
2962 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002963" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002964
2965 " rename the current buffer to the temp file (ie. tfile)
2966 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002967 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002968 else
2969 let tfile= a:tfile
2970 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002971 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002972
2973 " edit temporary file (ie. read the temporary file in)
2974 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002975" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002976 call zip#Browse(tfile)
2977 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002978" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002979 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002980 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002981" call Decho("handling remote gzip-compressed tar file",'~'.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\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002984" call Decho("handling remote bz2-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\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002987" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002988 call tar#Browse(tfile)
2989 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002990" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002991 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002992 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002993" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002994 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002995 endif
2996
2997 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002998 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002999
Bram Moolenaar71badf92023-04-22 22:40:14 +01003000 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01003001 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003002 " Note that isk must not include a "/" for scripts.vim
3003 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01003004" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
3005" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003006" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003007" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3008 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003009 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003010 filetype detect
3011" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003012 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003013" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003014 let line1 = 1
3015 let line2 = line("$")
3016
Bram Moolenaar8d043172014-01-23 14:24:41 +01003017 elseif !&ma
3018 " 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 +01003019 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003020" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003021 return
3022
Bram Moolenaar9964e462007-05-05 17:54:07 +00003023 elseif s:FileReadable(a:tfile)
3024 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003025" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003026 let curline = line(".")
3027 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003028" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003029 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003030 let line1= curline + 1
3031 let line2= line("$") - lastline + 1
3032
3033 else
3034 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003035" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3036" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003037 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003038" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003039 return
3040 endif
3041
3042 " User-provided (ie. optional) fix-it-up command
3043 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003044" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003045 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003046" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003047" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003048 endif
3049
Bram Moolenaaradc21822011-04-01 18:03:16 +02003050 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003051 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003052 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003053 endif
3054
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003055" 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 +00003056
3057 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003058" redraw!
3059
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003060" 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 +00003061" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003062endfun
3063
Bram Moolenaar9964e462007-05-05 17:54:07 +00003064" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003065" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003066" Input:
3067" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3068" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003069" b:netrw_method= 1: rcp
3070" 2: ftp + <.netrc>
3071" 3: ftp + machine, id, password, and [path]filename
3072" 4: scp
3073" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003074" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003075" 7: rsync
3076" 8: fetch
3077" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003078" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003079" g:netrw_machine= hostname
3080" b:netrw_fname = filename
3081" g:netrw_port = optional port number (for ftp)
3082" g:netrw_choice = copy of input url (choice)
3083fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003084" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003085
Bram Moolenaar251e1912011-06-19 05:09:16 +02003086 " sanity check: choice should have at least three slashes in it
3087 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3088 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3089 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003090" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003091 return
3092 endif
3093
Bram Moolenaar5c736222010-01-06 20:54:52 +01003094 " record current g:netrw_machine, if any
3095 " curmachine used if protocol == ftp and no .netrc
3096 if exists("g:netrw_machine")
3097 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003098" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003099 else
3100 let curmachine= "N O T A HOST"
3101 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003102 if exists("g:netrw_port")
3103 let netrw_port= g:netrw_port
3104 endif
3105
3106 " insure that netrw_ftp_cmd starts off every method determination
3107 " with the current g:netrw_ftp_cmd
3108 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003109
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003110 " initialization
3111 let b:netrw_method = 0
3112 let g:netrw_machine = ""
3113 let b:netrw_fname = ""
3114 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003115 let g:netrw_choice = a:choice
3116
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003117 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003118 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003119 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3120 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003121 " rcpurm : rcp://[user@]host/filename Use rcp
3122 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003123 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003124 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003125 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 " rsyncurm : rsync://host[:port]/path Use rsync
3127 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3128 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003129 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003130 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3131 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003132 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3133 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003135 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003136 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003137 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003138 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003139 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003140 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003141 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003142
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003143" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003144 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003145 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003146 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003147" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003148 let b:netrw_method = 1
3149 let userid = substitute(a:choice,rcpurm,'\1',"")
3150 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3151 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003152 if userid != ""
3153 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003155
Bram Moolenaaradc21822011-04-01 18:03:16 +02003156 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003157 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003158" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003159 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003160 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3161 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3162 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003163
Bram Moolenaar15146672011-10-20 22:22:38 +02003164 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003165 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003166" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003167 let b:netrw_method = 5
3168 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3169 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003170 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003171
Bram Moolenaaradc21822011-04-01 18:03:16 +02003172 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003173 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003174" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003175 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003176 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003177 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3178 else
3179 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3180 endif
3181 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003182
Bram Moolenaaradc21822011-04-01 18:03:16 +02003183 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003184 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003185" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003186 let b:netrw_method = 7
3187 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3188 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003189
Bram Moolenaaradc21822011-04-01 18:03:16 +02003190 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003191 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003192" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003193 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003194 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3195 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3196 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003197" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003198 if userid != ""
3199 let g:netrw_uid= userid
3200 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003201
Bram Moolenaaradc21822011-04-01 18:03:16 +02003202 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003203 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003204 call NetUserPass("ftp:".g:netrw_machine)
3205 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003206 " if there's a change in hostname, require password re-entry
3207 unlet s:netrw_passwd
3208 endif
3209 if exists("netrw_port")
3210 unlet netrw_port
3211 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003212 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003213
Bram Moolenaar446cb832008-06-24 21:56:24 +00003214 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003215 let b:netrw_method = 3
3216 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003217 let host= substitute(g:netrw_machine,'\..*$','','')
3218 if exists("s:netrw_hup[host]")
3219 call NetUserPass("ftp:".host)
3220
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003221 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003222" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3223" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003224 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003225 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003226" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003227 endif
3228 let b:netrw_method= 2
3229 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003230" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003231 let b:netrw_method= 2
3232 else
3233 if !exists("g:netrw_uid") || g:netrw_uid == ""
3234 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003235 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003236 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003237 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003238 endif
3239 let b:netrw_method= 3
3240 endif
3241 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003242
Bram Moolenaaradc21822011-04-01 18:03:16 +02003243 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003244 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003245" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003246 let b:netrw_method = 8
3247 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3248 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3249 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3250 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003251
Bram Moolenaaradc21822011-04-01 18:03:16 +02003252 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003253 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003254" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003256 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3257 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003258 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003259 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003260 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003261
Bram Moolenaaradc21822011-04-01 18:03:16 +02003262 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003263 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003264" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003265 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003266 let b:netrw_method = 3
3267 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3268 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003269
Bram Moolenaar9964e462007-05-05 17:54:07 +00003270 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003271 let b:netrw_method = 2
3272 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3273 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3274 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003275
Bram Moolenaaradc21822011-04-01 18:03:16 +02003276 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003277 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003278" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003279 let b:netrw_method = 9
3280 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3281 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003282
Bram Moolenaaradc21822011-04-01 18:03:16 +02003283 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003284 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003285" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003286 let b:netrw_method = 1
3287 let userid = substitute(a:choice,rcphf,'\2',"")
3288 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3289 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003290" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3291" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3292" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3293" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003294 if userid != ""
3295 let g:netrw_uid= userid
3296 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003297
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003298 " Method#10: file://user@hostname/...path-to-file {{{3
3299 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003300" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003301 let b:netrw_method = 10
3302 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003303" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003304
Bram Moolenaaradc21822011-04-01 18:03:16 +02003305 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003306 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003307 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003308 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003309 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003310 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003312 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003313
Bram Moolenaar81695252004-12-29 20:58:21 +00003314 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003315 " remove any leading [:#] from port number
3316 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3317 elseif exists("netrw_port")
3318 " retain port number as implicit for subsequent ftp operations
3319 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003320 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003321
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003322" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3323" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3324" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3325" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003326" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003327" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003328" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003329" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003330" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003331" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003332" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003333" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335
3336" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003337" NetReadFixup: this sort of function is typically written by the user {{{2
3338" to handle extra junk that their system's ftp dumps
3339" into the transfer. This function is provided as an
3340" example and as a fix for a Windows 95 problem: in my
3341" experience, win95's ftp always dumped four blank lines
3342" at the end of the transfer.
3343if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3344 fun! NetReadFixup(method, line1, line2)
3345" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003346
3347 " sanity checks -- attempt to convert inputs to integers
3348 let method = a:method + 0
3349 let line1 = a:line1 + 0
3350 let line2 = a:line2 + 0
3351 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3352" call Dret("NetReadFixup")
3353 return
3354 endif
3355
Bram Moolenaar9964e462007-05-05 17:54:07 +00003356 if method == 3 " ftp (no <.netrc>)
3357 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003358 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003359 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003360 call histdel("/",-1)
3361 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003362 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003363
Bram Moolenaar9964e462007-05-05 17:54:07 +00003364" call Dret("NetReadFixup")
3365 endfun
3366endif
3367
3368" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003369" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003370" Usage: :call NetUserPass() -- will prompt for userid and password
3371" :call NetUserPass("uid") -- will prompt for password
3372" :call NetUserPass("uid","password") -- sets global userid and password
3373" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3374" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003375fun! NetUserPass(...)
3376
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003377" call Dfunc("NetUserPass() a:0=".a:0)
3378
3379 if !exists('s:netrw_hup')
3380 let s:netrw_hup= {}
3381 endif
3382
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003384 " case: no input arguments
3385
3386 " change host and username if not previously entered; get new password
3387 if !exists("g:netrw_machine")
3388 let g:netrw_machine= input('Enter hostname: ')
3389 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003390 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003391 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392 let g:netrw_uid= input('Enter username: ')
3393 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003394 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003395 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003396
3397 " set up hup database
3398 let host = substitute(g:netrw_machine,'\..*$','','')
3399 if !exists('s:netrw_hup[host]')
3400 let s:netrw_hup[host]= {}
3401 endif
3402 let s:netrw_hup[host].uid = g:netrw_uid
3403 let s:netrw_hup[host].passwd = s:netrw_passwd
3404
3405 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003406 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003407
3408 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003409 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003410 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003411" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003412 let host = substitute(a:1,'^ftp:','','')
3413 let host = substitute(host,'\..*','','')
3414 if exists("s:netrw_hup[host]")
3415 let g:netrw_uid = s:netrw_hup[host].uid
3416 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003417" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3418" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003419 else
3420 let g:netrw_uid = input("Enter UserId: ")
3421 let s:netrw_passwd = inputsecret("Enter Password: ")
3422 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003423
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003424 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003425 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003426" 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 +02003427 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003428 if g:netrw_machine =~ '[0-9.]\+'
3429 let host= g:netrw_machine
3430 else
3431 let host= substitute(g:netrw_machine,'\..*$','','')
3432 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003433 else
3434 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003435 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003436 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003437" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003438 if exists("g:netrw_passwd")
3439 " ask for password if one not previously entered
3440 let s:netrw_passwd= g:netrw_passwd
3441 else
3442 let s:netrw_passwd = inputsecret("Enter Password: ")
3443 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003444 endif
3445
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003446" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003447 if exists("host")
3448 if !exists('s:netrw_hup[host]')
3449 let s:netrw_hup[host]= {}
3450 endif
3451 let s:netrw_hup[host].uid = g:netrw_uid
3452 let s:netrw_hup[host].passwd = s:netrw_passwd
3453 endif
3454
3455 elseif a:0 == 2
3456 let g:netrw_uid = a:1
3457 let s:netrw_passwd = a:2
3458
3459 elseif a:0 == 3
3460 " enter hostname, user-id, and password into the hup dictionary
3461 let host = substitute(a:1,'^\a\+:','','')
3462 let host = substitute(host,'\..*$','','')
3463 if !exists('s:netrw_hup[host]')
3464 let s:netrw_hup[host]= {}
3465 endif
3466 let s:netrw_hup[host].uid = a:2
3467 let s:netrw_hup[host].passwd = a:3
3468 let g:netrw_uid = s:netrw_hup[host].uid
3469 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003470" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3471" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003473
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003474" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476
Bram Moolenaar85850f32019-07-19 22:05:51 +02003477" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003478" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003479" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003481" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003482" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3483fun! s:ExplorePatHls(pattern)
3484" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3485 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003486" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003487 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003488" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003489 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3490" call Dret("s:ExplorePatHls repat<".repat.">")
3491 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003492endfun
3493
3494" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003495" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003496" 0: (user: <mb>) bookmark current directory
3497" 1: (user: <gb>) change to the bookmarked directory
3498" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003499" 3: (browsing) records current directory history
3500" 4: (user: <u>) go up (previous) directory, using history
3501" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003502" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003503fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003504" 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 +02003505 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3506" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3507 return
3508 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003509
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003510 let ykeep = @@
3511 let curbufnr = bufnr("%")
3512
Bram Moolenaar9964e462007-05-05 17:54:07 +00003513 if a:chg == 0
3514 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003515" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003516 if exists("s:netrwmarkfilelist_{curbufnr}")
3517 call s:NetrwBookmark(0)
3518 echo "bookmarked marked files"
3519 else
3520 call s:MakeBookmark(a:curdir)
3521 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003522 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003523
KSR-Yasudaf4498252023-10-06 03:34:17 +09003524 try
3525 call s:NetrwBookHistSave()
3526 catch
3527 endtry
3528
Bram Moolenaar9964e462007-05-05 17:54:07 +00003529 elseif a:chg == 1
3530 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003531" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003532 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003533" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003534 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003535 else
3536 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3537 endif
3538
3539 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003540" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003541 let didwork= 0
3542 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003543" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003544 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003545" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003546 let cnt= 1
3547 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003548" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003549 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003550 let didwork = 1
3551 let cnt = cnt + 1
3552 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003553 endif
3554
3555 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003556 " Note: history is saved only when PerformListing is done;
3557 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3558 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003559 let first = 1
3560 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003561 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003562 while ( first || cnt != g:netrw_dirhistcnt )
3563" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003564 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003565" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003566 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003567 let didwork= 1
3568 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003569 let histcnt = histcnt + 1
3570 let first = 0
3571 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003572 if cnt < 0
3573 let cnt= cnt + g:netrw_dirhistmax
3574 endif
3575 endwhile
3576 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003577 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003578 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003579 if didwork
3580 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3581 endif
3582
3583 elseif a:chg == 3
3584 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003585" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003586 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 +02003587 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003588 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3589 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003590 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003591" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003592 endif
3593
3594 elseif a:chg == 4
3595 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003596" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003597 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003598 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3599 if g:netrw_dirhistcnt < 0
3600 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003601 endif
3602 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003603 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003604 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003605 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3606" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003607 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003608 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003609" call Decho("setl ma noro",'~'.expand("<slnum>"))
3610 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003611 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003612" call Decho("setl nomod",'~'.expand("<slnum>"))
3613" 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 +00003614 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003615" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3616 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003617 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003618 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003619 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003620 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003621 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003622 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003623 echo "Sorry, no predecessor directory exists yet"
3624 endif
3625
3626 elseif a:chg == 5
3627 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003628" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003629 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003630 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3631 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3632" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003633 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003634" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003635 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003636 sil! NetrwKeepj %d _
3637" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3638" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003639 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003640" 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 +02003641 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003642" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3643 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003644 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003645 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3646 if g:netrw_dirhistcnt < 0
3647 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003648 endif
3649 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003650 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003651 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003652 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003653 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003654 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003655
3656 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003657" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003658 if exists("s:netrwmarkfilelist_{curbufnr}")
3659 call s:NetrwBookmark(1)
3660 echo "removed marked files from bookmarks"
3661 else
3662 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003663 let iremove = v:count
3664 let dremove = g:netrw_bookmarklist[iremove - 1]
3665" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003666 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003667" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3668 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3669 echo "removed ".dremove." from g:netrw_bookmarklist"
3670" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003671 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003672" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003673
3674 try
3675 call s:NetrwBookHistSave()
3676 catch
3677 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003678 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003679 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003680 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003681 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003682" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003683endfun
3684
3685" ---------------------------------------------------------------------
3686" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003687" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003688" Sister function: s:NetrwBookHistSave()
3689fun! s:NetrwBookHistRead()
3690" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003691 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003692" 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 +02003693 return
3694 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003695 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003696
3697 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003698 if !exists("s:netrw_initbookhist")
3699 let home = s:NetrwHome()
3700 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003701 if filereadable(s:NetrwFile(savefile))
3702" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003703 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003704 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003705
3706 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003707 if g:netrw_dirhistmax > 0
3708 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003709 if filereadable(s:NetrwFile(savefile))
3710" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003711 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003712 endif
3713 let s:netrw_initbookhist= 1
3714 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003715 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003716 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003717
Bram Moolenaar97d62492012-11-15 21:28:22 +01003718 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003719" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3720" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003721" call Dret("s:NetrwBookHistRead")
3722endfun
3723
3724" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003725" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003726" Sister function: s:NetrwBookHistRead()
3727" I used to do this via viminfo but that appears to
3728" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003729" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3730" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003731" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003732fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003733" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003734 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003735" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003736 return
3737 endif
3738
Bram Moolenaar5c736222010-01-06 20:54:52 +01003739 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003740" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003741 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003742
3743 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003744 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003745" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003746 if g:netrw_use_noswf
3747 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3748 else
3749 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3750 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003751 setl nocin noai noci magic nospell nohid wig= noaw
3752 setl ma noro write
3753 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003754 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003755
Bram Moolenaar85850f32019-07-19 22:05:51 +02003756 " rename enew'd file: .netrwhist -- no attempt to merge
3757 " record dirhistmax and current dirhistcnt
3758 " save history
3759" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003760 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003761 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003762 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3763 if g:netrw_dirhistmax > 0
3764 let lastline = line("$")
3765 let cnt = g:netrw_dirhistcnt
3766 let first = 1
3767 while ( first || cnt != g:netrw_dirhistcnt )
3768 let lastline= lastline + 1
3769 if exists("g:netrw_dirhist_{cnt}")
3770 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3771" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3772 endif
3773 let first = 0
3774 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3775 if cnt < 0
3776 let cnt= cnt + g:netrw_dirhistmax
3777 endif
3778 endwhile
3779 exe "sil! w! ".savefile
3780" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3781 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003782
Bram Moolenaar85850f32019-07-19 22:05:51 +02003783 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003784 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003785 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003786" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003787 " merge and write .netrwbook
3788 let savefile= s:NetrwHome()."/.netrwbook"
3789
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003790 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003791 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003792 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003793 for bdm in booklist
3794 if index(g:netrw_bookmarklist,bdm) == -1
3795 call add(g:netrw_bookmarklist,bdm)
3796 endif
3797 endfor
3798 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003799 endif
3800
3801 " construct and save .netrwbook
3802 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003803 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003804" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003805 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003806
3807 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003808 let bgone= bufnr("%")
3809 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003810 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003811
3812" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003813endfun
3814
3815" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003816" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3817" list of the contents of a local or remote directory. It is assumed that the
3818" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3819" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003820" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003821fun! s:NetrwBrowse(islocal,dirname)
3822 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003823" 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 +02003824" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3825" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3826" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003827
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003828 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3829 " This is useful when one edits a local file, then :e ., then :Rex
3830 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3831 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003832" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003833 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003834
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003835 " s:NetrwBrowse : initialize history {{{3
3836 if !exists("s:netrw_initbookhist")
3837 NetrwKeepj call s:NetrwBookHistRead()
3838 endif
3839
3840 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003841 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003842 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003843" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003844 else
3845 let dirname= a:dirname
3846 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003847
Bram Moolenaar85850f32019-07-19 22:05:51 +02003848 " repoint t:netrw_lexbufnr if appropriate
3849 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3850" call Decho("set repointlexbufnr to true!")
3851 let repointlexbufnr= 1
3852 endif
3853
3854 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003855 if exists("s:netrw_skipbrowse")
3856 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003857" 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 +01003858" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003859 return
3860 endif
3861 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003862 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003863" call Dret("s:NetrwBrowse : missing shellescape()")
3864 return
3865 endif
3866 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003867 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003868" call Dret("s:NetrwBrowse : missing fnameescape()")
3869 return
3870 endif
3871
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003872 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003873 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003874
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003875 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003876 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3877 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3878" call Decho("clearing marked files",'~'.expand("<slnum>"))
3879 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3880 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003881 endif
3882
3883 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003884 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003885" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3886" 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 +02003887 if s:NetrwLcd(dirname)
3888" call Dret("s:NetrwBrowse : lcd failure")
3889 return
3890 endif
3891 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003892" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003893
Bram Moolenaar5c736222010-01-06 20:54:52 +01003894 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003895 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003896" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003897 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003898" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003899 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003900 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003901 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003902" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003903
3904 " remove any filetype indicator from end of dirname, except for the
3905 " "this is a directory" indicator (/).
3906 " There shouldn't be one of those here, anyway.
3907 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003908" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003909 call s:RemotePathAnalysis(dirname)
3910
3911 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3912 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003913 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003914 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003915" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003916 let b:netrw_curdir = dirname
3917 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003918 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003919 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3920 sil call netrw#NetRead(2,url)
3921 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003922" call Decho("url<".url.">",'~'.expand("<slnum>"))
3923" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3924" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003925 if s:path =~ '.bz2'
3926 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3927 elseif s:path =~ '.gz'
3928 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3929 elseif s:path =~ '.gz'
3930 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3931 else
3932 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3933 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003934 endif
3935
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003936 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003937 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003938 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003939" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003940 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003941" 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 +00003942
Bram Moolenaar446cb832008-06-24 21:56:24 +00003943" call Dret("s:NetrwBrowse : file<".s:fname.">")
3944 return
3945 endif
3946
Bram Moolenaaradc21822011-04-01 18:03:16 +02003947 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003948 call s:UseBufWinVars()
3949
3950 " set up some variables {{{3
3951 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003952 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003953 let s:last_sort_by = g:netrw_sort_by
3954
3955 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003956 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003957
Bram Moolenaar97d62492012-11-15 21:28:22 +01003958 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003959" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003960 let svpos = winsaveview()
3961" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003962 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003963
Bram Moolenaar446cb832008-06-24 21:56:24 +00003964 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003965 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3966 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3967" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3968" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3969 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3970 else
3971" " call Decho("2match none",'~'.expand("<slnum>"))
3972 2match none
3973 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003974 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003975 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003976 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003977" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003978 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003979" 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 +01003980" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003981 return
3982 endif
3983
3984 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003985" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003986 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003987 if b:netrw_curdir =~ '[/\\]$'
3988 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3989 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003990 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3991 let b:netrw_curdir= b:netrw_curdir."/"
3992 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003993 if b:netrw_curdir == ''
3994 if has("amiga")
3995 " On the Amiga, the empty string connotes the current directory
3996 let b:netrw_curdir= getcwd()
3997 else
3998 " under unix, when the root directory is encountered, the result
3999 " from the preceding substitute is an empty string.
4000 let b:netrw_curdir= '/'
4001 endif
4002 endif
4003 if !a:islocal && b:netrw_curdir !~ '/$'
4004 let b:netrw_curdir= b:netrw_curdir.'/'
4005 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004006" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004007
4008 " ------------
4009 " (local only) {{{3
4010 " ------------
4011 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004012" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004013
4014 " Set up ShellCmdPost handling. Append current buffer to browselist
4015 call s:LocalFastBrowser()
4016
4017 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
4018 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004019" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
4020" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004021 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004022 if s:NetrwLcd(b:netrw_curdir)
4023" call Dret("s:NetrwBrowse : lcd failure")
4024 return
4025 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004026 endif
4027 endif
4028
4029 " --------------------------------
4030 " remote handling: {{{3
4031 " --------------------------------
4032 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004033" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004034
Bram Moolenaar97d62492012-11-15 21:28:22 +01004035 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004036" 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 +02004037 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004038 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004039" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004040 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4041 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4042 if dirname !~ '/$'
4043 let dirname= dirname.'/'
4044 endif
4045 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004046" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004047 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004048 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004049" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004050 endif
4051
4052 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4053 if dirname !~ dirpat
4054 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004055 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004056 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004057 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004058" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004059 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004060" 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 +00004061" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4062 return
4063 endif
4064 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004065" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004066 endif " (additional remote handling)
4067
Bram Moolenaar85850f32019-07-19 22:05:51 +02004068 " -------------------------------
4069 " Perform Directory Listing: {{{3
4070 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004071 NetrwKeepj call s:NetrwMaps(a:islocal)
4072 NetrwKeepj call s:NetrwCommands(a:islocal)
4073 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004074
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004075 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004076 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004077" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4078
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004079 " If there is a rexposn: restore position with rexposn
4080 " Otherwise : set rexposn
4081 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004082" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4083 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4084 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4085 NetrwKeepj exe w:netrw_bannercnt
4086 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004087 else
4088 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4089 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004090 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004091 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004092" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004093 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004094 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004095
Bram Moolenaar85850f32019-07-19 22:05:51 +02004096 " repoint t:netrw_lexbufnr if appropriate
4097 if exists("repointlexbufnr")
4098 let t:netrw_lexbufnr= bufnr("%")
4099" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4100 endif
4101
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004102 " restore position
4103 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004104" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4105 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004106 endif
4107
Bram Moolenaara6878372014-03-22 21:02:50 +01004108 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004109 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4110 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004111" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4112" 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 +02004113" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004114 return
4115endfun
4116
4117" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004118" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4119" may not apply correctly; ie. netrw's idea of the current directory may
4120" differ from vim's. This function insures that netrw's idea of the current
4121" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004122" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004123fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004124" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4125" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4126" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4127" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4128" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004129
4130 " clean up any leading treedepthstring
4131 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4132 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004133" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004134 else
4135 let fname= a:fname
4136 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004137
4138 if g:netrw_keepdir
4139 " vim's idea of the current directory possibly may differ from netrw's
4140 if !exists("b:netrw_curdir")
4141 let b:netrw_curdir= getcwd()
4142 endif
4143
4144 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004145 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004146 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004147 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004148" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004149 else
4150 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004151 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004152" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004153 endif
4154
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004155 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004156 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004157 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004158" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004159 else
4160 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004161 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004162" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004163 endif
4164 else
4165 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004166 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004167" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4168" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4169" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004170 endif
4171
Bram Moolenaar85850f32019-07-19 22:05:51 +02004172" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004173 return ret
4174endfun
4175
4176" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004177" s:NetrwFileInfo: supports qf (query for file information) {{{2
4178fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004179" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004180 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004181 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004182 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004183 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004184 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004185 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004186 let lsopt= "-lsadh --si"
4187 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004188" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004189 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004190
4191 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004192 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004193" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004194
Bram Moolenaara6878372014-03-22 21:02:50 +01004195 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004196 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004197" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004198
4199 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004200 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004201" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004202
Bram Moolenaar446cb832008-06-24 21:56:24 +00004203 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004204" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004205 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004206" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004207 endif
4208 else
4209 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004210" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4211 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004212 let fname= substitute(a:fname,".$","","")
4213 else
4214 let fname= a:fname
4215 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004216 let t = getftime(s:NetrwFile(fname))
4217 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004218 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004219 let sz= s:NetrwHumanReadable(sz)
4220 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004221 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4222" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004223 endif
4224 else
4225 echo "sorry, \"qf\" not supported yet for remote files"
4226 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004227 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004228" call Dret("s:NetrwFileInfo")
4229endfun
4230
4231" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004232" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4233fun! s:NetrwFullPath(filename)
4234" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4235 let filename= a:filename
4236 if filename !~ '^/'
4237 let filename= resolve(getcwd().'/'.filename)
4238 endif
4239 if filename != "/" && filename =~ '/$'
4240 let filename= substitute(filename,'/$','','')
4241 endif
4242" " call Dret("s:NetrwFullPath <".filename.">")
4243 return filename
4244endfun
4245
4246" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004247" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004248" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004249" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004250" 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 +00004251fun! s:NetrwGetBuffer(islocal,dirname)
4252" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004253" 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 +02004254" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4255" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004256 let dirname= a:dirname
4257
4258 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004259" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004260 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004261" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004262 let s:netrwbuf= {}
4263 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004264" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4265" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4266
4267 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4268 let bufnum = -1
4269
4270 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4271 if has_key(s:netrwbuf,"NetrwTreeListing")
4272 let bufnum= s:netrwbuf["NetrwTreeListing"]
4273 else
4274 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4275 endif
4276" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4277 if !bufexists(bufnum)
4278 call remove(s:netrwbuf,"NetrwTreeListing"])
4279 let bufnum= -1
4280 endif
4281 elseif bufnr("NetrwTreeListing") != -1
4282 let bufnum= bufnr("NetrwTreeListing")
4283" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4284 else
4285" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4286 let bufnum= -1
4287 endif
4288
4289 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004290 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004291" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004292 if !bufexists(bufnum)
4293 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4294 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004295 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004296
Bram Moolenaar446cb832008-06-24 21:56:24 +00004297 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004298" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004299 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004300 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004301" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4302
Bram Moolenaar71badf92023-04-22 22:40:14 +01004303 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004304 " IF the buffer already has the desired name
4305 " AND it is empty
4306 let curbuf = bufname("%")
4307 if curbuf == '.'
4308 let curbuf = getcwd()
4309 endif
4310" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004311" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004312" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4313" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4314" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4315" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4316 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004317" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4318 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004319 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004320" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004321 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004322 " 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 +00004323
4324 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004325 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004326" 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 +00004327 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004328" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004329 " name the buffer
4330 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4331 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004332" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004333 let w:netrw_treebufnr = bufnr("%")
4334 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004335 if g:netrw_use_noswf
4336 setl nobl bt=nofile noswf
4337 else
4338 setl nobl bt=nofile
4339 endif
4340 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4341 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4342 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4343 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004344" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004345 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004346 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004347 " enter the new buffer into the s:netrwbuf dictionary
4348 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4349" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4350" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004351 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004352" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004353
4354 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004355" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004356 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004357 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004358 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004359
4360 if &ft == "netrw"
4361" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4362 exe "sil! NetrwKeepj noswapfile b ".bufnum
4363" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004364 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004365" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4366 call s:NetrwEditBuf(bufnum)
4367" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004368 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004369" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004370 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004371 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004372 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004373
4374 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004375 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004376
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004377 if line("$") <= 1 && getline(1) == ""
4378 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004379 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004380" 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>"))
4381" 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 +01004382" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4383 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004384
Bram Moolenaar97d62492012-11-15 21:28:22 +01004385 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004386" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004387 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004388 sil NetrwKeepj %d _
4389" 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>"))
4390" 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 +01004391" 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 +00004392 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004393
Bram Moolenaar446cb832008-06-24 21:56:24 +00004394 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004395" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4396" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004397 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004398 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004399 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004400" 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>"))
4401" 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 +01004402" 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 +00004403 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004404
Bram Moolenaar446cb832008-06-24 21:56:24 +00004405 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004406" 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>"))
4407" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4408" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004409 return 1
4410 endif
4411 endif
4412
4413 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4414 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4415 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4416 " med 1 D H
4417 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004418" 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 +00004419 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004420 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004421 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004422
4423 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004424" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4425" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4426 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004427
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004428" 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>"))
4429" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4430" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004431 return 0
4432endfun
4433
4434" ---------------------------------------------------------------------
4435" s:NetrwGetcwd: get the current directory. {{{2
4436" Change backslashes to forward slashes, if any.
4437" If doesc is true, escape certain troublesome characters
4438fun! s:NetrwGetcwd(doesc)
4439" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4440 let curdir= substitute(getcwd(),'\\','/','ge')
4441 if curdir !~ '[\/]$'
4442 let curdir= curdir.'/'
4443 endif
4444 if a:doesc
4445 let curdir= fnameescape(curdir)
4446 endif
4447" call Dret("NetrwGetcwd <".curdir.">")
4448 return curdir
4449endfun
4450
4451" ---------------------------------------------------------------------
4452" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4453fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004454" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4455" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4456 let keepsol= &l:sol
4457 setl nosol
4458
Bram Moolenaar446cb832008-06-24 21:56:24 +00004459 call s:UseBufWinVars()
4460
4461 " insure that w:netrw_liststyle is set up
4462 if !exists("w:netrw_liststyle")
4463 if exists("g:netrw_liststyle")
4464 let w:netrw_liststyle= g:netrw_liststyle
4465 else
4466 let w:netrw_liststyle= s:THINLIST
4467 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004468" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004469 endif
4470
4471 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4472 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004473" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004474 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004475 let dirname= "./"
4476 let curline= getline('.')
4477
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004478 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004479 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004480 let s:netrw_skipbrowse= 1
4481 echo 'Pressing "s" also works'
4482
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004483 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004484 let s:netrw_skipbrowse= 1
4485 echo 'Press "S" to edit sorting sequence'
4486
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004487 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004488 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004490
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004491 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004492 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004493 let s:netrw_skipbrowse= 1
4494 echo 'Pressing "a" also works'
4495
4496 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004497 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004498 endif
4499
4500 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004501" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004502 NetrwKeepj norm! 0
4503 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004504
4505 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004506" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004507 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4509
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004510 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004511" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004512 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004513 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004514
4515 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004516" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004517 let dirname= getline('.')
4518
4519 if !exists("b:netrw_cpf")
4520 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004521 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 +01004522 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004523" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004524 endif
4525
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004526" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004527 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004528" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4529" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004530 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004531 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004532 else
4533 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004534 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004535 endif
4536 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004537 let eofname= filestart + b:netrw_cpf + 1
4538 if eofname <= col("$")
4539 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004540 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004541 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004542 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004543 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004544 let dirname = @a
4545 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004546" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004547 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004548" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004549 endif
4550
4551 " symlinks are indicated by a trailing "@". Remove it before further processing.
4552 let dirname= substitute(dirname,"@$","","")
4553
4554 " executables are indicated by a trailing "*". Remove it before further processing.
4555 let dirname= substitute(dirname,"\*$","","")
4556
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004557 let &l:sol= keepsol
4558
Bram Moolenaar446cb832008-06-24 21:56:24 +00004559" call Dret("s:NetrwGetWord <".dirname.">")
4560 return dirname
4561endfun
4562
4563" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004564" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4565" g:netrw_bufsettings will be used after the listing is produced.
4566" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004567fun! s:NetrwListSettings(islocal)
4568" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004569" 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 +00004570 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004571" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4572 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4573 setl bt=nofile nobl ma nonu nowrap noro nornu
4574 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004575 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004576 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004577 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004578" call Dredir("ls!","s:NetrwListSettings")
4579" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004580 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004581 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004582 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004583 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004584 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004585 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004586 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004587" 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 +00004588" call Dret("s:NetrwListSettings")
4589endfun
4590
4591" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004592" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004593" islocal=0: remote browsing
4594" =1: local browsing
4595fun! s:NetrwListStyle(islocal)
4596" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004597
Bram Moolenaar97d62492012-11-15 21:28:22 +01004598 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004599 let fname = s:NetrwGetWord()
4600 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004601 let svpos = winsaveview()
4602" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004603 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004604" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4605" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4606" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004607
Bram Moolenaar85850f32019-07-19 22:05:51 +02004608 " repoint t:netrw_lexbufnr if appropriate
4609 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4610" call Decho("set repointlexbufnr to true!")
4611 let repointlexbufnr= 1
4612 endif
4613
Bram Moolenaar446cb832008-06-24 21:56:24 +00004614 if w:netrw_liststyle == s:THINLIST
4615 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004616" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004617 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4618
4619 elseif w:netrw_liststyle == s:LONGLIST
4620 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004621" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004622 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4623
4624 elseif w:netrw_liststyle == s:WIDELIST
4625 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004626" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004627 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4628
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004629 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004630" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004631 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4632
4633 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004634 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004635 let g:netrw_liststyle = s:THINLIST
4636 let w:netrw_liststyle = g:netrw_liststyle
4637 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4638 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004639 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004640" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004641
4642 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004643" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4644 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004645 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004646" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004647 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004648" 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 +00004649
4650 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004651" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004652 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004653 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004654
Bram Moolenaar85850f32019-07-19 22:05:51 +02004655 " repoint t:netrw_lexbufnr if appropriate
4656 if exists("repointlexbufnr")
4657 let t:netrw_lexbufnr= bufnr("%")
4658" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4659 endif
4660
Bram Moolenaar13600302014-05-22 18:26:40 +02004661 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004662" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4663 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004664 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004665
4666" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4667endfun
4668
4669" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004670" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4671fun! s:NetrwBannerCtrl(islocal)
4672" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4673
Bram Moolenaar97d62492012-11-15 21:28:22 +01004674 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004675 " toggle the banner (enable/suppress)
4676 let g:netrw_banner= !g:netrw_banner
4677
4678 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004679 let svpos= winsaveview()
4680" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004681 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4682
4683 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004684 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4685 let fname= s:NetrwGetWord()
4686 sil NetrwKeepj $
4687 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4688" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4689 if result <= 0 && exists("w:netrw_bannercnt")
4690 exe "NetrwKeepj ".w:netrw_bannercnt
4691 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004692 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004693 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004694" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4695endfun
4696
4697" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004698" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4699"
4700" No bang: enters files/directories into Netrw's bookmark system
4701" No argument and in netrw buffer:
4702" if there are marked files: bookmark marked files
4703" otherwise : bookmark file/directory under cursor
4704" No argument and not in netrw buffer: bookmarks current open file
4705" Has arguments: globs them individually and bookmarks them
4706"
4707" With bang: deletes files/directories from Netrw's bookmark system
4708fun! s:NetrwBookmark(del,...)
4709" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4710 if a:0 == 0
4711 if &ft == "netrw"
4712 let curbufnr = bufnr("%")
4713
4714 if exists("s:netrwmarkfilelist_{curbufnr}")
4715 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004716" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004717 let svpos = winsaveview()
4718" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004719 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004720 for fname in s:netrwmarkfilelist_{curbufnr}
4721 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4722 endfor
4723 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4724 call s:NetrwUnmarkList(curbufnr,curdir)
4725 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004726" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4727 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004728 else
4729 let fname= s:NetrwGetWord()
4730 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4731 endif
4732
4733 else
4734 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004735" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004736 let fname= expand("%")
4737 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4738 endif
4739
4740 else
4741 " bookmark specified files
4742 " attempts to infer if working remote or local
4743 " by deciding if the current file begins with an url
4744 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004745 let islocal= expand("%") !~ '^\a\{3,}://'
4746" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004747 let i = 1
4748 while i <= a:0
4749 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004750 if v:version > 704 || (v:version == 704 && has("patch656"))
4751 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004752 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004753 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004754 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004755 else
4756 let mbfiles= [a:{i}]
4757 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004758" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004759 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004760" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004761 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4762 endfor
4763 let i= i + 1
4764 endwhile
4765 endif
4766
4767 " update the menu
4768 call s:NetrwBookmarkMenu()
4769
4770" call Dret("s:NetrwBookmark")
4771endfun
4772
4773" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004774" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4775" .2.[cnt] for bookmarks, and
4776" .3.[cnt] for history
4777" (see s:NetrwMenu())
4778fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004779 if !exists("s:netrw_menucnt")
4780 return
4781 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004782" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004783
4784 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004785 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004786 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004787" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004788 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4789 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004790 endif
4791 if !exists("s:netrw_initbookhist")
4792 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004793 endif
4794
4795 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004796 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004797 let cnt= 1
4798 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004799" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004800 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004801
4802 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004803 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004804
4805 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004806 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 +01004807 let cnt= cnt + 1
4808 endfor
4809
4810 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004811
4812 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004813 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004814 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004815 let first = 1
4816 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004817 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004818 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004819 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004820 if exists("g:netrw_dirhist_{cnt}")
4821 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004822" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004823 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4824 endif
4825 let first = 0
4826 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4827 if cnt < 0
4828 let cnt= cnt + g:netrw_dirhistmax
4829 endif
4830 endwhile
4831 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004832
Bram Moolenaar9964e462007-05-05 17:54:07 +00004833 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004834" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004835endfun
4836
4837" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004838" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4839" directory and a new directory name. Also, if the
4840" "new directory name" is actually a file,
4841" NetrwBrowseChgDir() edits the file.
4842fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004843" 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 +01004844" 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 +00004845
Bram Moolenaar97d62492012-11-15 21:28:22 +01004846 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004847 if !exists("b:netrw_curdir")
4848 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4849 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004850 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004851" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4852" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004853" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004854" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004855 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004856 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004857" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004858
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004859 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004860" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004861 call s:SavePosn(s:netrw_posn)
4862 NetrwKeepj call s:NetrwOptionsSave("s:")
4863 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004864 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004865 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004866 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004867 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004868 endif
4869 let newdir = a:newdir
4870 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004871 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004872" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004873" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004874" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004875
4876 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004877" 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 +01004878 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004879" 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 +01004880 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004881 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004882" 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 +01004883 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004884" 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 +02004885 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004886 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004887 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004888 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004889" 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 +01004890 endif
4891 endif
4892" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004893" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004894 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004895
Bram Moolenaar446cb832008-06-24 21:56:24 +00004896 " set up o/s-dependent directory recognition pattern
4897 if has("amiga")
4898 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004899 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004900 let dirpat= '[\/]$'
4901 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004902" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903
4904 if dirname !~ dirpat
4905 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004906 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004907 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004908" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004909 endif
4910
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004911" 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 +01004912 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004913 " ------------------------------
4914 " NetrwBrowseChgDir: edit a file {{{3
4915 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004916" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004917
Bram Moolenaar97d62492012-11-15 21:28:22 +01004918 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004919 let s:rexposn_{bufnr("%")}= winsaveview()
4920" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004921" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4922" 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 +01004923
Bram Moolenaar446cb832008-06-24 21:56:24 +00004924 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004925" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4926" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004927" let newdir = s:NetrwTreePath(s:netrw_treetop)
4928" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004929 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004930 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4931" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4932 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004933 if dirname =~ '/$'
4934 let dirname= dirname.newdir
4935 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004936 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004937 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004938" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4939" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004940 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004941" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004942 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004943 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004944 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004945 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004946" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004947 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004948 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004949" 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 +02004950 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004951 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004952 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004953" " 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 +01004954 if type(g:netrw_browse_split) == 3
4955 " open file in server
4956 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004957" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004958 call s:NetrwServerEdit(a:islocal,dirname)
4959" call Dret("s:NetrwBrowseChgDir")
4960 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004961
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004962 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004963 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004964" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004965 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4966 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004967 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004968 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004969 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004970 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004971
Bram Moolenaar446cb832008-06-24 21:56:24 +00004972 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004973 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004974" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004975 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4976 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004977 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004978 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004979 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004980 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004981
Bram Moolenaar446cb832008-06-24 21:56:24 +00004982 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004983 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004984" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004985 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004986 if !exists("b:netrw_curdir")
4987 let b:netrw_curdir= getcwd()
4988 endif
4989 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004990
Bram Moolenaar446cb832008-06-24 21:56:24 +00004991 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004992 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004993" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004994 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004995 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004996" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004997 return
4998 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004999 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005000
Bram Moolenaar9964e462007-05-05 17:54:07 +00005001 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00005002 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005003" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005004 call s:NetrwMenu(0)
5005 " optional change to window
5006 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005007" 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 +02005008 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09005009 " if g:netrw_chgwin is set to one more than the last window, then
5010 " vertically split the last window to make that window available.
5011 let curwin= winnr()
5012 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
5013 vs
5014 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02005015 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005016 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00005017 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005018 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00005019 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005020
Bram Moolenaar9964e462007-05-05 17:54:07 +00005021 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005022
Bram Moolenaar446cb832008-06-24 21:56:24 +00005023 " the point where netrw actually edits the (local) file
5024 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01005025 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005026 if !&mod
5027 " if e the new file would fail due to &mod, then don't change any of the flags
5028 let dolockout= 1
5029 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005030 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005031" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005032 " some like c-^ to return to the last edited file
5033 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005034 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5035 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005036 call s:NetrwEditFile("e","",dirname)
5037" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005038 " COMBAK -- cuc cul related
5039 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005040 if &hidden || &bufhidden == "hide"
5041 " file came from vim's hidden storage. Don't "restore" options with it.
5042 let dorestore= 0
5043 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005044 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005045" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005046 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005047
5048 " handle g:Netrw_funcref -- call external-to-netrw functions
5049 " This code will handle g:Netrw_funcref as an individual function reference
5050 " or as a list of function references. It will ignore anything that's not
5051 " a function reference. See :help Funcref for information about function references.
5052 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005053" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005054 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005055" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005056 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005057 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005058" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005059 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005060 if type(Fncref) == 2
5061 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005062 endif
5063 endfor
5064 endif
5065 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005066 endif
5067
5068 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005069 " ----------------------------------------------------
5070 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5071 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005072" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005073 let dirname = newdir
5074 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005075 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005076 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005077
5078 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005079 " ---------------------------------------------
5080 " NetrwBrowseChgDir: refresh the directory list {{{3
5081 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005082" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005083 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005084 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005085
5086 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005087 " --------------------------------------
5088 " NetrwBrowseChgDir: go up one directory {{{3
5089 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005090" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005091
5092 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5093 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005094" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5095" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005096 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005097 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005098 endif
5099
5100 if has("amiga")
5101 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005102" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005103 if a:islocal
5104 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5105 let dirname= substitute(dirname,'/$','','')
5106 else
5107 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5108 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005109" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005110
Bram Moolenaar8d043172014-01-23 14:24:41 +01005111 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
5112 " windows
5113 if a:islocal
5114 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5115 if dirname == ""
5116 let dirname= '/'
5117 endif
5118 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005119 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005120 endif
5121 if dirname =~ '^\a:$'
5122 let dirname= dirname.'/'
5123 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005124" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005125
Bram Moolenaar446cb832008-06-24 21:56:24 +00005126 else
5127 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005128" 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 +00005129 if a:islocal
5130 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5131 if dirname == ""
5132 let dirname= '/'
5133 endif
5134 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005135 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005136 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005137" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005138 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005139 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005140 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005141
5142 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005143 " --------------------------------------
5144 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5145 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005146" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005147 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5148" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005149 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005150 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005151" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5152 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005153 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005154 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005155" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005156 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005157 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005158" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005159
5160 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005161" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005162 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005163" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 let haskey= 1
5165 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005166" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167 endif
5168
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005169 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005170" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005171 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005172 if has_key(w:netrw_treedict,treedir."/")
5173 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005174" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005175 let haskey = 1
5176 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005177" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005178 endif
5179 endif
5180
5181 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005182" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005183 if !haskey && treedir =~ '/$'
5184 let treedir= substitute(treedir,'/$','','')
5185 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005186" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005187 let haskey = 1
5188 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005189" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005190 endif
5191 endif
5192
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005193" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005194 if haskey
5195 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005196" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005197 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005198" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5199" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005200 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005201 else
5202 " go down one directory
5203 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005204" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5205" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005206 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005207 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005208" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005209 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005210
5211 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005212 " ----------------------------------------
5213 " NetrwBrowseChgDir: Go down one directory {{{3
5214 " ----------------------------------------
5215 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005216" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005217 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005218 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005219 endif
5220
Bram Moolenaar97d62492012-11-15 21:28:22 +01005221 " --------------------------------------
5222 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5223 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005224 if dorestore
5225 " dorestore is zero'd when a local file was hidden or bufhidden;
5226 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005227" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005228 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005229" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005230" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005231 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005232 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005233" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005234 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005235" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5236" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005237 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005238" 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 +02005239 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005240" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5241" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005242 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005243" 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 +02005244 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005245 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005246 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005247 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005248
Bram Moolenaar446cb832008-06-24 21:56:24 +00005249" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5250 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005251endfun
5252
5253" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005254" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5255" for thin, long, and wide: cursor placed just after banner
5256" for tree, keeps cursor on current filename
5257fun! s:NetrwBrowseUpDir(islocal)
5258" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005259 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5260 " this test needed because occasionally this function seems to be incorrectly called
5261 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005262 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005263 " directories.
5264" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5265 return
5266 endif
5267
Bram Moolenaara6878372014-03-22 21:02:50 +01005268 norm! 0
5269 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005270" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005271 let curline= getline(".")
5272 let swwline= winline() - 1
5273 if exists("w:netrw_treetop")
5274 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005275 elseif exists("b:netrw_curdir")
5276 let w:netrw_treetop= b:netrw_curdir
5277 else
5278 let w:netrw_treetop= getcwd()
5279 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005280 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005281 let curfile = getline(".")
5282 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005283 if a:islocal
5284 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5285 else
5286 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5287 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005288" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5289" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5290 if w:netrw_treetop == '/'
5291 keepj call search('^\M'.curfile,"w")
5292 elseif curfile == '../'
5293 keepj call search('^\M'.curfile,"wb")
5294 else
5295" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5296 while 1
5297 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5298 let treepath= s:NetrwTreePath(w:netrw_treetop)
5299" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5300 if treepath == curpath
5301 break
5302 endif
5303 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005304 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005305
Bram Moolenaara6878372014-03-22 21:02:50 +01005306 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005307" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005308 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005309 if exists("b:netrw_curdir")
5310 let curdir= b:netrw_curdir
5311 else
5312 let curdir= expand(getcwd())
5313 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005314 if a:islocal
5315 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5316 else
5317 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5318 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005319 call s:RestorePosn(s:netrw_posn)
5320 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005321 let curdir= '\<'. escape(curdir, '~'). '/'
5322 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005323 endif
5324" call Dret("s:NetrwBrowseUpDir")
5325endfun
5326
5327" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005328" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005329" given filename; typically this means given their extension.
5330" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005331fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005332 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005333" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005334
Bram Moolenaar91359012019-11-30 17:57:03 +01005335 if a:remote == 0 && isdirectory(a:fname)
5336 " if its really just a local directory, then do a "gf" instead
5337" 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 +01005338" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5339 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005340" call Dret("netrw#BrowseX")
5341 return
5342 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5343 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5344" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5345" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5346" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5347" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5348 norm! gf
5349" call Dret("netrw#BrowseX")
5350 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005351 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005352" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005353
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005354 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5355 let remote = a:remote
5356 else
5357 let remote = 0
5358 endif
5359
Bram Moolenaar97d62492012-11-15 21:28:22 +01005360 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005361 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005362" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005363
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005364 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5365 let awkeep = &aw
5366 set noaw
5367
Bram Moolenaar5c736222010-01-06 20:54:52 +01005368 " special core dump handler
5369 if a:fname =~ '/core\(\.\d\+\)\=$'
5370 if exists("g:Netrw_corehandler")
5371 if type(g:Netrw_corehandler) == 2
5372 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005373" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005374 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005375 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005376 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005377" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005378 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005379 if type(Fncref) == 2
5380 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005381 endif
5382 endfor
5383 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005384" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005385 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005386 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005387 let &aw= awkeep
5388" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005389 return
5390 endif
5391 endif
5392
Bram Moolenaar446cb832008-06-24 21:56:24 +00005393 " set up the filename
5394 " (lower case the extension, make a local copy of a remote file)
5395 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5396 if has("win32") || has("win95") || has("win64") || has("win16")
5397 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005398 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005399 if exten =~ "[\\/]"
5400 let exten= ""
5401 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005402" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005403
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005404 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005405 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005406" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005407 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005408 call netrw#NetRead(3,a:fname)
5409 " attempt to rename tempfile
5410 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005411 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005412" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5413" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005414 if s:netrw_tmpfile != newname && newname != ""
5415 if rename(s:netrw_tmpfile,newname) == 0
5416 " renaming succeeded
5417" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5418 let fname= newname
5419 else
5420 " renaming failed
5421" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5422 let fname= s:netrw_tmpfile
5423 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005424 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005425 let fname= s:netrw_tmpfile
5426 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005427 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005428" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005429 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005430 " special ~ handler for local
5431 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005432" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5433 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005434 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005435 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005436" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5437" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005438
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005439 " set up redirection (avoids browser messages)
5440 " by default, g:netrw_suppress_gx_mesg is true
5441 if g:netrw_suppress_gx_mesg
5442 if &srr =~ "%s"
5443 if (has("win32") || has("win95") || has("win64") || has("win16"))
5444 let redir= substitute(&srr,"%s","nul","")
5445 else
5446 let redir= substitute(&srr,"%s","/dev/null","")
5447 endif
5448 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5449 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005450 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005451 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005452 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005453 else
5454 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005455 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005456" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005457
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005458 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005459 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005460" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005461 if g:netrw_browsex_viewer =~ '\s'
5462 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5463 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5464 let oviewer = ''
5465 let cnt = 1
5466 while !executable(viewer) && viewer != oviewer
5467 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5468 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5469 let cnt = cnt + 1
5470 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005471" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005472 endwhile
5473 else
5474 let viewer = g:netrw_browsex_viewer
5475 let viewopt = ""
5476 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005477" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005478 endif
5479
5480 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005481" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005482 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005483" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005484 let ret= netrwFileHandlers#Invoke(exten,fname)
5485
5486 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005487" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005488 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005489 let ret= v:shell_error
5490
5491 elseif has("win32") || has("win64")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005492" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005493 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005494 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005495 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005496 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005497 else
5498 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5499 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005500 let ret= v:shell_error
5501
Bram Moolenaar97d62492012-11-15 21:28:22 +01005502 elseif has("win32unix")
5503 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005504" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005505 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005506" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005507 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005508 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005509" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005510 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005511 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005512" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005513 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005514 else
5515 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5516 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005517 let ret= v:shell_error
5518
Bram Moolenaar85850f32019-07-19 22:05:51 +02005519 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005520" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5521 if a:fname =~ '^https\=://'
5522 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5523 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005524" call Decho("fname<".fname.">")
5525" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005526 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5527
5528 else
5529 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5530 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005531 let ret= v:shell_error
5532
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005533 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5534" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5535 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5536 let ret= v:shell_error
5537
5538 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5539" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5540 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5541 let ret= v:shell_error
5542
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005543 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005544" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005545 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005546 let ret= v:shell_error
5547
5548 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005549" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005550 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005551 let ret= v:shell_error
5552
5553 else
5554 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005555" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005556 let ret= netrwFileHandlers#Invoke(exten,fname)
5557 endif
5558
5559 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5560 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005561" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005562 let ret= netrwFileHandlers#Invoke(exten,fname)
5563 endif
5564
Bram Moolenaarc236c162008-07-13 17:41:49 +00005565 " restoring redraw! after external file handlers
5566 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005567
5568 " cleanup: remove temporary file,
5569 " delete current buffer if success with handler,
5570 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005571 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005572 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005573" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005574"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005575" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005576" endif
5577
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005578 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005579 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005580 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005581 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005582 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005583 if use_ctrlo
5584 exe "sil! NetrwKeepj norm! \<c-o>"
5585 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005586 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005587" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005588 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005589 let @@ = ykeep
5590 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005591
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005592" call Dret("netrw#BrowseX")
5593endfun
5594
5595" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005596" netrw#GX: gets word under cursor for gx support {{{2
5597" See also: netrw#BrowseXVis
5598" netrw#BrowseX
5599fun! netrw#GX()
5600" call Dfunc("netrw#GX()")
5601 if &ft == "netrw"
5602 let fname= s:NetrwGetWord()
5603 else
5604 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5605 endif
5606" call Dret("netrw#GX <".fname.">")
5607 return fname
5608endfun
5609
5610" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005611" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5612fun! netrw#BrowseXVis()
5613" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005614 let akeep = @a
5615 norm! gv"ay
5616 let gxfile= @a
5617 let @a = akeep
5618 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005619" call Dret("netrw#BrowseXVis")
5620endfun
5621
5622" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005623" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5624" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5625" to become an unlisted buffer, so in that case don't bwipe it.
5626fun! s:NetrwBufRename(newname)
5627" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5628" call Dredir("ls!","s:NetrwBufRename (before rename)")
5629 let oldbufname= bufname(bufnr("%"))
5630" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5631
5632 if oldbufname != a:newname
5633" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5634 let b:junk= 1
5635" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5636 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005637" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005638 let oldbufnr= bufnr(oldbufname)
5639" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5640" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5641 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5642" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5643 exe "bwipe! ".oldbufnr
5644" else " Decho
5645" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005646" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5647" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5648" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005649 endif
5650" call Dredir("ls!","s:NetrwBufRename (after rename)")
5651" else " Decho
5652" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5653 endif
5654
5655" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5656endfun
5657
5658" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005659" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005660fun! netrw#CheckIfRemote(...)
5661" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5662 if a:0 > 0
5663 let curfile= a:1
5664 else
5665 let curfile= expand("%")
5666 endif
5667" call Decho("curfile<".curfile.">")
5668 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005669" call Dret("netrw#CheckIfRemote 1")
5670 return 1
5671 else
5672" call Dret("netrw#CheckIfRemote 0")
5673 return 0
5674 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005675endfun
5676
5677" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005678" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5679fun! s:NetrwChgPerm(islocal,curdir)
5680" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005681 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005682 call inputsave()
5683 let newperm= input("Enter new permission: ")
5684 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005685 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5686 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5687" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005688 call system(chgperm)
5689 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005690 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005691 endif
5692 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005693 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005694 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005695 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005696" call Dret("s:NetrwChgPerm")
5697endfun
5698
5699" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005700" s:CheckIfKde: checks if kdeinit is running {{{2
5701" Returns 0: kdeinit not running
5702" 1: kdeinit is running
5703fun! s:CheckIfKde()
5704" call Dfunc("s:CheckIfKde()")
5705 " seems kde systems often have gnome-open due to dependencies, even though
5706 " gnome-open's subsidiary display tools are largely absent. Kde systems
5707 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5708 if !exists("s:haskdeinit")
5709 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005710 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005711 if v:shell_error
5712 let s:haskdeinit = 0
5713 endif
5714 else
5715 let s:haskdeinit= 0
5716 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005717" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005718 endif
5719
5720" call Dret("s:CheckIfKde ".s:haskdeinit)
5721 return s:haskdeinit
5722endfun
5723
5724" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005725" s:NetrwClearExplore: clear explore variables (if any) {{{2
5726fun! s:NetrwClearExplore()
5727" call Dfunc("s:NetrwClearExplore()")
5728 2match none
5729 if exists("s:explore_match") |unlet s:explore_match |endif
5730 if exists("s:explore_indx") |unlet s:explore_indx |endif
5731 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5732 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5733 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5734 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5735 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5736 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5737 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5738" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005739" call Dret("s:NetrwClearExplore")
5740endfun
5741
5742" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005743" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5744fun! s:NetrwEditBuf(bufnum)
5745" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5746 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5747" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5748 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5749 else
5750" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005751 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005752 endif
5753" call Dret("s:NetrwEditBuf")
5754endfun
5755
5756" ---------------------------------------------------------------------
5757" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5758" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5759fun! s:NetrwEditFile(cmd,opt,fname)
5760" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5761 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5762" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5763 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5764 else
5765" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5766 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5767 endif
5768" call Dret("s:NetrwEditFile")
5769endfun
5770
5771" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005772" s:NetrwExploreListUniq: {{{2
5773fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005774" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005775
5776 " this assumes that the list is already sorted
5777 let newexplist= []
5778 for member in a:explist
5779 if !exists("uniqmember") || member != uniqmember
5780 let uniqmember = member
5781 let newexplist = newexplist + [ member ]
5782 endif
5783 endfor
5784
Bram Moolenaar15146672011-10-20 22:22:38 +02005785" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005786 return newexplist
5787endfun
5788
5789" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005790" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5791fun! s:NetrwForceChgDir(islocal,newdir)
5792" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005793 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005794 if a:newdir !~ '/$'
5795 " ok, looks like force is needed to get directory-style treatment
5796 if a:newdir =~ '@$'
5797 let newdir= substitute(a:newdir,'@$','/','')
5798 elseif a:newdir =~ '[*=|\\]$'
5799 let newdir= substitute(a:newdir,'.$','/','')
5800 else
5801 let newdir= a:newdir.'/'
5802 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005803" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005804 else
5805 " should already be getting treatment as a directory
5806 let newdir= a:newdir
5807 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005808 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005809 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005810 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005811" call Dret("s:NetrwForceChgDir")
5812endfun
5813
5814" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005815" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005816" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5817" expr : this is the expression to follow the directory. Will use s:ComposePath()
5818" pare =1: remove the current directory from the resulting glob() filelist
5819" =0: leave the current directory in the resulting glob() filelist
5820fun! s:NetrwGlob(direntry,expr,pare)
5821" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005822 if netrw#CheckIfRemote()
5823 keepalt 1sp
5824 keepalt enew
5825 let keep_liststyle = w:netrw_liststyle
5826 let w:netrw_liststyle = s:THINLIST
5827 if s:NetrwRemoteListing() == 0
5828 keepj keepalt %s@/@@
5829 let filelist= getline(1,$)
5830 q!
5831 else
5832 " remote listing error -- leave treedict unchanged
5833 let filelist= w:netrw_treedict[a:direntry]
5834 endif
5835 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005836 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5837 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5838 if a:pare
5839 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5840 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005841 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005842 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5843 if a:pare
5844 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5845 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005846 endif
5847" call Dret("s:NetrwGlob ".string(filelist))
5848 return filelist
5849endfun
5850
5851" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005852" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5853fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005854" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005855 if a:newfile =~ '[/@*=|\\]$'
5856 let newfile= substitute(a:newfile,'.$','','')
5857 else
5858 let newfile= a:newfile
5859 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005860 if a:islocal
5861 call s:NetrwBrowseChgDir(a:islocal,newfile)
5862 else
5863 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5864 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005865" call Dret("s:NetrwForceFile")
5866endfun
5867
5868" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005869" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5870" and switches the hiding mode. The actual hiding is done by
5871" s:NetrwListHide().
5872" g:netrw_hide= 0: show all
5873" 1: show not-hidden files
5874" 2: show hidden files only
5875fun! s:NetrwHide(islocal)
5876" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005877 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005878 let svpos= winsaveview()
5879" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005880
5881 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005882" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5883" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005884
5885 " hide the files in the markfile list
5886 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005887" 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 +00005888 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5889 " remove fname from hiding list
5890 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5891 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5892 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005893" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005894 else
5895 " append fname to hiding list
5896 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5897 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5898 else
5899 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5900 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005901" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005902 endif
5903 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005904 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005905 let g:netrw_hide= 1
5906
5907 else
5908
5909 " switch between show-all/show-not-hidden/show-hidden
5910 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005911 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005912 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005913 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005914 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005915" call Dret("NetrwHide")
5916 return
5917 endif
5918 endif
5919
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005920 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005921" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5922 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005923 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005924" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005925endfun
5926
5927" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005928" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5929fun! s:NetrwHideEdit(islocal)
5930" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5931
5932 let ykeep= @@
5933 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005934 let svpos= winsaveview()
5935" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005936
5937 " get new hiding list from user
5938 call inputsave()
5939 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5940 call inputrestore()
5941 let g:netrw_list_hide= newhide
5942" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5943
5944 " refresh the listing
5945 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5946
5947 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005948" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5949 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005950 let @@= ykeep
5951
5952" call Dret("NetrwHideEdit")
5953endfun
5954
5955" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005956" s:NetrwHidden: invoked by "gh" {{{2
5957fun! s:NetrwHidden(islocal)
5958" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005959 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005960 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005961 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005962" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005963
5964 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005965 " remove .file pattern from hiding list
5966" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005967 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005968 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005969" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005970 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5971 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005972" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005973 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5974 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005975 if g:netrw_list_hide =~ '^,'
5976 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5977 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005978
5979 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005980 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005981" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5982 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005983 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005984" call Dret("s:NetrwHidden")
5985endfun
5986
5987" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005988" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5989fun! s:NetrwHome()
5990 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005991 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005992 else
5993 " go to vim plugin home
5994 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005995 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005996 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005997 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005998 let home= basehome."/.vim"
5999 break
6000 endif
6001 endfor
6002 if home == ""
6003 " just pick the first directory
6004 let home= substitute(&rtp,',.*$','','')
6005 endif
6006 if (has("win32") || has("win95") || has("win64") || has("win16"))
6007 let home= substitute(home,'/','\\','g')
6008 endif
6009 endif
6010 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006011 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006012" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006013 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02006014" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006015 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01006016 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006017" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006018 call mkdir(home)
6019 endif
6020 endif
6021 let g:netrw_home= home
6022 return home
6023endfun
6024
6025" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006026" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
6027fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006028 if exists("s:netrwdrag")
6029 return
6030 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006031 if &ft != "netrw"
6032 return
6033 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006034" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006035
Bram Moolenaar97d62492012-11-15 21:28:22 +01006036 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006037 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006038 while getchar(0) != 0
6039 "clear the input stream
6040 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006041 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006042 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006043 let mouse_lnum = v:mouse_lnum
6044 let wlastline = line('w$')
6045 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006046" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6047" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006048 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6049 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006050 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006051" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6052 return
6053 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006054 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006055 " 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 +01006056 " without this test when its disabled.
6057 " 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 +01006058" 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 +01006059 if v:mouse_col > virtcol('.')
6060 let @@= ykeep
6061" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6062 return
6063 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006064
Bram Moolenaar446cb832008-06-24 21:56:24 +00006065 if a:islocal
6066 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006067 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006068 endif
6069 else
6070 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006071 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006072 endif
6073 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006074 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006075" call Dret("s:NetrwLeftmouse")
6076endfun
6077
6078" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006079" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6080fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006081 if &ft != "netrw"
6082 return
6083 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006084" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6085 call s:NetrwMarkFileTgt(a:islocal)
6086" call Dret("s:NetrwCLeftmouse")
6087endfun
6088
6089" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006090" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6091" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006092" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006093" a:islocal=2 : <c-r> used, remote
6094" a:islocal=3 : <c-r> used, local
6095fun! s:NetrwServerEdit(islocal,fname)
6096" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6097 let islocal = a:islocal%2 " =0: remote =1: local
6098 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006099" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006100
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006101 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006102 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006103 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006104" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006105 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006106 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006107 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6108 unlet s:netrw_browse_split_{winnr()}
6109 endif
6110 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6111" call Dret("s:NetrwServerEdit")
6112 return
6113 endif
6114
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006115" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006116 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006117" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006118
6119 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006120" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006121 let srvrname = g:netrw_browse_split[0]
6122 let tabnum = g:netrw_browse_split[1]
6123 let winnum = g:netrw_browse_split[2]
6124
6125 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006126" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006127
6128 if !ctrlr
6129 " user must have closed the server window and the user did not use <c-r>, but
6130 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006131" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006132 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006133 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006134 endif
6135 let g:netrw_browse_split= 0
6136 if exists("s:netrw_browse_split_".winnr())
6137 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6138 endif
6139 call s:NetrwBrowseChgDir(islocal,a:fname)
6140" call Dret("s:NetrwServerEdit")
6141 return
6142
6143 elseif has("win32") && executable("start")
6144 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006145" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006146 call system("start gvim --servername ".srvrname)
6147
6148 else
6149 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006150" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006151 call system("gvim --servername ".srvrname)
6152 endif
6153 endif
6154
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006155" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006156 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6157 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006158 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006159
6160 else
6161
6162 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6163
6164 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006165" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006166 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006167 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006168 endif
6169 let g:netrw_browse_split= 0
6170 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6171" call Dret("s:NetrwServerEdit")
6172 return
6173
6174 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006175" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006176 if has("win32") && executable("start")
6177 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006178" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006179 call system("start gvim --servername ".g:netrw_servername)
6180 else
6181 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006182" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006183 call system("gvim --servername ".g:netrw_servername)
6184 endif
6185 endif
6186 endif
6187
6188 while 1
6189 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006190" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6191 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006192 break
6193 catch /^Vim\%((\a\+)\)\=:E241/
6194 sleep 200m
6195 endtry
6196 endwhile
6197
6198 if exists("g:netrw_browse_split")
6199 if type(g:netrw_browse_split) != 3
6200 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6201 endif
6202 unlet g:netrw_browse_split
6203 endif
6204 let g:netrw_browse_split= [g:netrw_servername,1,1]
6205 endif
6206
6207 else
6208 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6209 endif
6210
6211" call Dret("s:NetrwServerEdit")
6212endfun
6213
6214" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006215" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6216fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006217 if &ft != "netrw"
6218 return
6219 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006220" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006221
Bram Moolenaar8d043172014-01-23 14:24:41 +01006222 let s:ngw= s:NetrwGetWord()
6223 call s:NetrwMarkFile(a:islocal,s:ngw)
6224
6225" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006226endfun
6227
6228" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006229" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6230" Used to mark multiple files.
6231fun! s:NetrwSLeftdrag(islocal)
6232" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6233 if !exists("s:netrwdrag")
6234 let s:netrwdrag = winnr()
6235 if a:islocal
6236 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006237 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006238 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006239 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006240 endif
6241 let ngw = s:NetrwGetWord()
6242 if !exists("s:ngw") || s:ngw != ngw
6243 call s:NetrwMarkFile(a:islocal,ngw)
6244 endif
6245 let s:ngw= ngw
6246" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6247endfun
6248
6249" ---------------------------------------------------------------------
6250" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6251fun! s:NetrwSLeftrelease(islocal)
6252" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6253 if exists("s:netrwdrag")
6254 nunmap <s-leftrelease>
6255 let ngw = s:NetrwGetWord()
6256 if !exists("s:ngw") || s:ngw != ngw
6257 call s:NetrwMarkFile(a:islocal,ngw)
6258 endif
6259 if exists("s:ngw")
6260 unlet s:ngw
6261 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006262 unlet s:netrwdrag
6263 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006264" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006265endfun
6266
6267" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006268" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6269" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006270fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006271" 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 +02006272" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006273 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006274
6275 " 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 +02006276 " How-it-works: take the hiding command, convert it into a range.
6277 " Duplicate characters don't matter.
6278 " Remove all such characters from the '/~@#...890' string.
6279 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006280" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006281 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006282 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006283" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006284
6285 while listhide != ""
6286 if listhide =~ ','
6287 let hide = substitute(listhide,',.*$','','e')
6288 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6289 else
6290 let hide = listhide
6291 let listhide = ""
6292 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006293" 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 +01006294 if g:netrw_sort_by =~ '^[ts]'
6295 if hide =~ '^\^'
6296" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6297 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6298 elseif hide =~ '^\\(\^'
6299 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6300 endif
6301" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6302 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006303
6304 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006305" 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 +00006306 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006307" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006308 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006309 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006310" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006311 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006312 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006313" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006314 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006315
Bram Moolenaar446cb832008-06-24 21:56:24 +00006316 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006317 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006318" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006319 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006320" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006321 endif
6322
Bram Moolenaaradc21822011-04-01 18:03:16 +02006323 " remove any blank lines that have somehow remained.
6324 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006325 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006326
Bram Moolenaar97d62492012-11-15 21:28:22 +01006327 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006328" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006329endfun
6330
6331" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006332" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006333" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006334fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006335" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006336
Bram Moolenaar97d62492012-11-15 21:28:22 +01006337 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006338 " get name of new directory from user. A bare <CR> will skip.
6339 " if its currently a directory, also request will be skipped, but with
6340 " a message.
6341 call inputsave()
6342 let newdirname= input("Please give directory name: ")
6343 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006344" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006345
6346 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006347 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006348" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006349 return
6350 endif
6351
6352 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006353" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006354
6355 " Local mkdir:
6356 " sanity checks
6357 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006358" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6359 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006360 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006361 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006362 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006363 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006364" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006365 return
6366 endif
6367 if s:FileReadable(fullnewdir)
6368 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006369 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006370 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006371 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006372" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006373 return
6374 endif
6375
6376 " requested new local directory is neither a pre-existing file or
6377 " directory, so make it!
6378 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006379 if has("unix")
6380 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6381 else
6382 call mkdir(fullnewdir,"p")
6383 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006384 else
6385 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006386 if s:NetrwLcd(b:netrw_curdir)
6387" call Dret("s:NetrwMakeDir : lcd failure")
6388 return
6389 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006390" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006391 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006392 if v:shell_error != 0
6393 let @@= ykeep
6394 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 +01006395" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006396 return
6397 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006398 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006399" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006400 if s:NetrwLcd(netrw_origdir)
6401" call Dret("s:NetrwBrowse : lcd failure")
6402 return
6403 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006404 endif
6405 endif
6406
6407 if v:shell_error == 0
6408 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006409" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006410 let svpos= winsaveview()
6411" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006412 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006413" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6414 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006415 elseif !exists("g:netrw_quiet")
6416 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6417 endif
6418" redraw!
6419
6420 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006421 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006422" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006423 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6424 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006425 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006426 if v:shell_error == 0
6427 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006428 let svpos= winsaveview()
6429" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006430 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006431" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6432 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006433 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006434 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006435 endif
6436" redraw!
6437
6438 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006439 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006440 let svpos= winsaveview()
6441" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006442" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006443 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006444" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006445 let remotepath= b:netrw_fname
6446 else
6447 let remotepath= ""
6448 endif
6449 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006450 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006451" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6452 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006453
Bram Moolenaar446cb832008-06-24 21:56:24 +00006454 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006455 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006456 let svpos= winsaveview()
6457" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006458" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006459 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006460" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006461 let remotepath= b:netrw_fname
6462 else
6463 let remotepath= ""
6464 endif
6465 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006466 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006467" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6468 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006469 endif
6470
Bram Moolenaar97d62492012-11-15 21:28:22 +01006471 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006472" call Dret("s:NetrwMakeDir")
6473endfun
6474
6475" ---------------------------------------------------------------------
6476" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6477fun! s:TreeSqueezeDir(islocal)
6478" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6479 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6480 " its a tree-listing style
6481 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006482 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006483 let depth = strchars(substitute(curdepth,' ','','g'))
6484 let srch = -1
6485" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6486" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006487" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006488" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6489 if depth >= 2
6490 NetrwKeepj norm! 0
6491 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6492 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6493" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6494" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6495 elseif depth == 1
6496 NetrwKeepj norm! 0
6497 let treedepthchr= substitute(s:treedepthstring,' ','','')
6498 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6499" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6500 endif
6501 if srch > 0
6502" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6503 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6504 exe srch
6505 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006506 endif
6507" call Dret("s:TreeSqueezeDir")
6508endfun
6509
6510" ---------------------------------------------------------------------
6511" s:NetrwMaps: {{{2
6512fun! s:NetrwMaps(islocal)
6513" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6514
Bram Moolenaar85850f32019-07-19 22:05:51 +02006515 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006516 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006517" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006518 if !hasmapto("<Plug>NetrwReturn")
6519 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006520" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006521 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6522 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006523" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006524 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6525 endif
6526 endif
6527 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006528" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006529 endif
6530
Bram Moolenaar85850f32019-07-19 22:05:51 +02006531 " generate default <Plug> maps {{{3
6532 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006533 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006534 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6535 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6536 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6537 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6538 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6539 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6540 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6541 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6542 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6543 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6544" ---------------------------------------------------------------------
6545" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6546" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6547" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6548" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6549" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6550" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6551" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6552" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6553" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6554" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6555" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6556" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6557" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6558" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6559" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6560" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6561" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6562" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6563" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6564" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6565" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6566" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6567" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6568" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6569" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6570" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6571" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6572" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6573" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6574" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6575" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6576" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6577" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6578" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6579" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6580" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6581" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6582" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6583" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6584" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6585" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6586" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6587" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6588" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6589" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6590" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6591" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6592
Bram Moolenaara6878372014-03-22 21:02:50 +01006593 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006594" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006595 " local normal-mode maps {{{3
6596 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6597 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6598 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6599 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6600 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6601 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6602 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6603 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6604 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6605 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6606 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6607" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006608 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6609 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6610 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006611 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006612 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006613 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6614 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6615 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6616 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006617 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6618 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6619 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6620 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6621 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6622 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6623 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6624 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6625 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6626 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6627 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6628 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6629 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006630 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006631 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006632 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6633 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6634 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6635 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6636 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006637 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006638 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006639 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6640 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006641 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6642 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6643 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006644 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006645 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006646 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6647 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006648 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006649 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006650 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6651 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6652 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006653 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6654 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006655
6656 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 +01006657 if !hasmapto('<Plug>NetrwHideEdit')
6658 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006659 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006660 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006661 if !hasmapto('<Plug>NetrwRefresh')
6662 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006663 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006664 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 +01006665 if s:didstarstar || !mapcheck("<s-down>","n")
6666 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006667 endif
6668 if s:didstarstar || !mapcheck("<s-up>","n")
6669 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006670 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006671 if !hasmapto('<Plug>NetrwTreeSqueeze')
6672 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006673 endif
6674 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006675 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6676 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006677 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6678 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6679 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6680 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6681 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6682 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6683 imap <buffer> <leftmouse> <Plug>ILeftmouse
6684 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006685 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6686 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6687 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6688 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6689 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006690 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006691 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6692 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006693 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006694 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6695 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6696 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6697 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6698 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6699 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6700 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006701 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6702
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006703 " support user-specified maps
6704 call netrw#UserMaps(1)
6705
Bram Moolenaar85850f32019-07-19 22:05:51 +02006706 else
6707 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006708" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006709 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006710 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6711 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6712 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6713 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6714 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6715 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6716 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6717 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6718 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6719 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6720 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6721" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006722 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6723 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6724 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6725 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6726 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6727 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6728 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6729 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006730 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006731 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006732 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6733 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6734 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6735 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6736 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6737 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6738 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6739 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6740 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6741 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6742 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006743 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006744 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006745 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6746 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6747 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6748 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6749 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006750 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6751 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6752 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6753 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006754 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006755 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6756 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006757 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006758 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 +01006759 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6760 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6761 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6762 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6763 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6764 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6765 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6766 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6767 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006768 if !hasmapto('<Plug>NetrwHideEdit')
6769 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006770 endif
6771 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6772 if !hasmapto('<Plug>NetrwRefresh')
6773 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006774 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006775 if !hasmapto('<Plug>NetrwTreeSqueeze')
6776 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006777 endif
6778 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006779
6780 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006781 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006782
6783 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6784 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006785 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006786 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006787 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006788 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006789 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006790 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006791 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006792 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006793 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006794 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006795 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6796 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6797 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006798 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006799 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006800 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6801 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006802 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006803 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6804 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6805 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6806 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6807 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6808 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6809 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006810 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006811
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006812 " support user-specified maps
6813 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006814 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006815
6816" call Dret("s:NetrwMaps")
6817endfun
6818
6819" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006820" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006821" If -buffer, the command is only available from within netrw buffers
6822" Otherwise, the command is available from any window, so long as netrw
6823" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006824fun! s:NetrwCommands(islocal)
6825" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6826
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006827 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6828 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006829 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 +01006830 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006831 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006832 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006833 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006834 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006835 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006836
6837" call Dret("s:NetrwCommands")
6838endfun
6839
6840" ---------------------------------------------------------------------
6841" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6842" glob()ing only works with local files
6843fun! s:NetrwMarkFiles(islocal,...)
6844" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006845 let curdir = s:NetrwGetCurdir(a:islocal)
6846 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006847 while i <= a:0
6848 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006849 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006850 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006851 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006852 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006853 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006854 else
6855 let mffiles= [a:{i}]
6856 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006857" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006858 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006859" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006860 call s:NetrwMarkFile(a:islocal,mffile)
6861 endfor
6862 let i= i + 1
6863 endwhile
6864" call Dret("s:NetrwMarkFiles")
6865endfun
6866
6867" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006868" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006869fun! s:NetrwMarkTarget(...)
6870" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6871 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006872 let curdir = s:NetrwGetCurdir(1)
6873 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006874 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006875 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6876 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006877 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006878" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006879 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006880 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6881 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006882 let svpos = winsaveview()
6883" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006884 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006885" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6886 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006887" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006888endfun
6889
6890" ---------------------------------------------------------------------
6891" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6892" mark and unmark files. If a markfile list exists,
6893" then the rename and delete functions will use it instead
6894" of whatever may happen to be under the cursor at that
6895" moment. When the mouse and gui are available,
6896" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006897"
6898" Creates two lists
6899" s:netrwmarkfilelist -- holds complete paths to all marked files
6900" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6901"
6902" Creates a marked file match string
6903" s:netrwmarfilemtch_# -- used with 2match to display marked files
6904"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006905" Creates a buffer version of islocal
6906" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006907fun! s:NetrwMarkFile(islocal,fname)
6908" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006909" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006910
6911 " sanity check
6912 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006913" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006914 return
6915 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006916 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006917
Bram Moolenaar97d62492012-11-15 21:28:22 +01006918 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006919 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006920 if a:fname =~ '^\a'
6921 let leader= '\<'
6922 else
6923 let leader= ''
6924 endif
6925 if a:fname =~ '\a$'
6926 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6927 else
6928 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6929 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006930
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006931 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006932 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006933" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6934" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6935" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006936 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006937
6938 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006939 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006940" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006941 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006942 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006943
6944 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006945 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006946" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006947 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6948 if s:netrwmarkfilelist_{curbufnr} == []
6949 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006950" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006951 call s:NetrwUnmarkList(curbufnr,curdir)
6952 else
6953 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006954" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006955 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006956 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006957 for fname in s:netrwmarkfilelist_{curbufnr}
6958 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006959 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006960 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006961 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006962 endif
6963 let first= 0
6964 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006965" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006966 endif
6967 endif
6968
6969 else
6970 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006971" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006972
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006973" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006974 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006975 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6976" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006977
6978 " build initial markfile matching pattern
6979 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006980 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006981 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006982 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006983 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006984" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006985 endif
6986
6987 " handle global markfilelist
6988 if exists("s:netrwmarkfilelist")
6989 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6990 if index(s:netrwmarkfilelist,dname) == -1
6991 " append new filename to global markfilelist
6992 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006993" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006994 else
6995 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006996" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6997" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006998 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006999" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007000 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007001" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007002 unlet s:netrwmarkfilelist
7003 endif
7004 endif
7005 else
7006 " initialize new global-directory markfilelist
7007 let s:netrwmarkfilelist= []
7008 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007009" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007010 endif
7011
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007012 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02007013 if has("syntax") && exists("g:syntax_on") && g:syntax_on
7014 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
7015" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
7016 if exists("g:did_drchip_netrwlist_syntax")
7017 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
7018 endif
7019 else
7020" " call Decho("2match none",'~'.expand("<slnum>"))
7021 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01007022 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007023 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007024 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007025" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
7026" 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 +00007027endfun
7028
7029" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007030" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7031" mA: move the argument list to marked file list (tomflist=1)
7032" Uses the global marked file list
7033fun! s:NetrwMarkFileArgList(islocal,tomflist)
7034" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7035
7036 let svpos = winsaveview()
7037" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7038 let curdir = s:NetrwGetCurdir(a:islocal)
7039 let curbufnr = bufnr("%")
7040
7041 if a:tomflist
7042 " mA: move argument list to marked file list
7043 while argc()
7044 let fname= argv(0)
7045" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7046 exe "argdel ".fnameescape(fname)
7047 call s:NetrwMarkFile(a:islocal,fname)
7048 endwhile
7049
7050 else
7051 " ma: move marked file list to argument list
7052 if exists("s:netrwmarkfilelist")
7053
7054 " for every filename in the marked list
7055 for fname in s:netrwmarkfilelist
7056" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7057 exe "argadd ".fnameescape(fname)
7058 endfor " for every file in the marked list
7059
7060 " unmark list and refresh
7061 call s:NetrwUnmarkList(curbufnr,curdir)
7062 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7063" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7064 NetrwKeepj call winrestview(svpos)
7065 endif
7066 endif
7067
7068" call Dret("s:NetrwMarkFileArgList")
7069endfun
7070
7071" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007072" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7073" compress/decompress files using the programs
7074" in g:netrw_compress and g:netrw_uncompress,
7075" using g:netrw_compress_suffix to know which to
7076" do. By default:
7077" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007078" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007079fun! s:NetrwMarkFileCompress(islocal)
7080" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007081 let svpos = winsaveview()
7082" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007083 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007084 let curbufnr = bufnr("%")
7085
Bram Moolenaarff034192013-04-24 18:51:19 +02007086 " sanity check
7087 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007088 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007089" call Dret("s:NetrwMarkFileCompress")
7090 return
7091 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007092" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007093
Bram Moolenaar446cb832008-06-24 21:56:24 +00007094 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007095
7096 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007097 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007098 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007099" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007100 if exists("g:netrw_decompress['".sfx."']")
7101 " fname has a suffix indicating that its compressed; apply associated decompression routine
7102 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007103" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007104 let exe= netrw#WinPath(exe)
7105 if a:islocal
7106 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007107 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007108 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007109 call system(exe." ".fname)
7110 if v:shell_error
7111 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007112 endif
7113 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007114 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7115 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007116 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007117
Bram Moolenaarff034192013-04-24 18:51:19 +02007118 endif
7119 unlet sfx
7120
Bram Moolenaar446cb832008-06-24 21:56:24 +00007121 if exists("exe")
7122 unlet exe
7123 elseif a:islocal
7124 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007125 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007126 if v:shell_error
7127 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7128 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007129 else
7130 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007131 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007132 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007133 endfor " for every file in the marked list
7134
Bram Moolenaar446cb832008-06-24 21:56:24 +00007135 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007136 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007137" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7138 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007139 endif
7140" call Dret("s:NetrwMarkFileCompress")
7141endfun
7142
7143" ---------------------------------------------------------------------
7144" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7145" If no marked files, then set up directory as the
7146" target. Currently does not support copying entire
7147" directories. Uses the local-buffer marked file list.
7148" Returns 1=success (used by NetrwMarkFileMove())
7149" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007150fun! s:NetrwMarkFileCopy(islocal,...)
7151" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7152
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007153 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007154 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007155 if b:netrw_curdir !~ '/$'
7156 if !exists("b:netrw_curdir")
7157 let b:netrw_curdir= curdir
7158 endif
7159 let b:netrw_curdir= b:netrw_curdir."/"
7160 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007161
Bram Moolenaarff034192013-04-24 18:51:19 +02007162 " sanity check
7163 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007164 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007165" call Dret("s:NetrwMarkFileCopy")
7166 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007167 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007168" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007169
Bram Moolenaar446cb832008-06-24 21:56:24 +00007170 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007171 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007172" call Dret("s:NetrwMarkFileCopy 0")
7173 return 0
7174 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007175" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007176
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007177 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007178 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007179" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007180 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007181 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7182" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7183 return
7184 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007185
7186 " copy marked files while within the same directory (ie. allow renaming)
7187 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7188 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7189 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007190" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007191 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007192 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7193 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007194" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007195 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007196 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007197 let oldname = a:1
7198 else
7199 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007200" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007201 let s:recursive= 1
7202 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7203 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7204 if ret == 0
7205 break
7206 endif
7207 endfor
7208 unlet s:recursive
7209 call s:NetrwUnmarkList(curbufnr,curdir)
7210" call Dret("s:NetrwMarkFileCopy ".ret)
7211 return ret
7212 endif
7213
7214 call inputsave()
7215 let newname= input("Copy ".oldname." to : ",oldname,"file")
7216 call inputrestore()
7217 if newname == ""
7218" call Dret("s:NetrwMarkFileCopy 0")
7219 return 0
7220 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007221 let args= s:ShellEscape(oldname)
7222 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007223 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007224 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7225 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007226 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007227 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7228 let args= substitute(args,'/','\\','g')
7229 let tgt = substitute(tgt, '/','\\','g')
7230 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007231 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7232 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7233 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7234 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7235" call Decho("args <".args.">",'~'.expand("<slnum>"))
7236" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007237 if isdirectory(s:NetrwFile(args))
7238" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007239 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007240" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007241 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7242 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7243 " contents to a target. One must append the source directory name to the target to get xcopy to
7244 " do the right thing.
7245 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007246" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007247 endif
7248 else
7249 let copycmd= g:netrw_localcopycmd
7250 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007251 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007252 let copycmd = substitute(copycmd,'\s.*$','','')
7253 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007254 let copycmd = netrw#WinPath(copycmd).copycmdargs
7255 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007256 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007257 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007258" call Decho("args <".args.">",'~'.expand("<slnum>"))
7259" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7260" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7261" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007262 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007263 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007264 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007265 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 +01007266 else
7267 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7268 endif
7269" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007270 return 0
7271 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007272
7273 elseif a:islocal && !s:netrwmftgt_islocal
7274 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007275" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007276 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007277
7278 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007279 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007280" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007281 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007282
7283 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007284 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007285" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007286 let curdir = getcwd()
7287 let tmpdir = s:GetTempfile("")
7288 if tmpdir !~ '/'
7289 let tmpdir= curdir."/".tmpdir
7290 endif
7291 if exists("*mkdir")
7292 call mkdir(tmpdir)
7293 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007294 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007295 if v:shell_error != 0
7296 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 +01007297" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007298 return
7299 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007300 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007301 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007302 if s:NetrwLcd(tmpdir)
7303" call Dret("s:NetrwMarkFileCopy : lcd failure")
7304 return
7305 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007306 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007307 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007308 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007309 if getcwd() == tmpdir
7310 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007311 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007312 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007313 if s:NetrwLcd(curdir)
7314" call Dret("s:NetrwMarkFileCopy : lcd failure")
7315 return
7316 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007317 if delete(tmpdir,"d")
7318 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007319 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007320 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007321 if s:NetrwLcd(curdir)
7322" call Dret("s:NetrwMarkFileCopy : lcd failure")
7323 return
7324 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007325 endif
7326 endif
7327 endif
7328
7329 " -------
7330 " cleanup
7331 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007332" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007333 " remove markings from local buffer
7334 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007335" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7336" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7337" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7338" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7339" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7340" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7341 if exists("s:recursive")
7342" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7343 else
7344" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007345 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007346 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007347 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007348 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007349 else
7350 " refresh local and targets for fast browsing
7351 if !exists("s:recursive")
7352 " remove markings from local buffer
7353" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7354 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7355 endif
7356
7357 " refresh buffers
7358 if s:netrwmftgt_islocal
7359" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7360 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7361 endif
7362 if a:islocal && s:netrwmftgt != curdir
7363" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7364 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7365 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007366 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007367
Bram Moolenaar446cb832008-06-24 21:56:24 +00007368" call Dret("s:NetrwMarkFileCopy 1")
7369 return 1
7370endfun
7371
7372" ---------------------------------------------------------------------
7373" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7374" invoke vim's diff mode on the marked files.
7375" Either two or three files can be so handled.
7376" Uses the global marked file list.
7377fun! s:NetrwMarkFileDiff(islocal)
7378" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7379 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007380
Bram Moolenaarff034192013-04-24 18:51:19 +02007381 " sanity check
7382 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007383 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007384" call Dret("s:NetrwMarkFileDiff")
7385 return
7386 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007387 let curdir= s:NetrwGetCurdir(a:islocal)
7388" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007389
Bram Moolenaara6878372014-03-22 21:02:50 +01007390 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007391 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007392 for fname in s:netrwmarkfilelist
7393 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007394 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007395" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007396 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007397 diffthis
7398 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007399 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007400" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007401 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007402 diffthis
7403 else
7404 break
7405 endif
7406 endfor
7407 call s:NetrwUnmarkList(curbufnr,curdir)
7408 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007409
Bram Moolenaar446cb832008-06-24 21:56:24 +00007410" call Dret("s:NetrwMarkFileDiff")
7411endfun
7412
7413" ---------------------------------------------------------------------
7414" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7415" Uses global markfilelist
7416fun! s:NetrwMarkFileEdit(islocal)
7417" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7418
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007419 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007420 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007421
7422 " sanity check
7423 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007424 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007425" call Dret("s:NetrwMarkFileEdit")
7426 return
7427 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007428" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007429
Bram Moolenaar446cb832008-06-24 21:56:24 +00007430 if exists("s:netrwmarkfilelist_{curbufnr}")
7431 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007432 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007433 " unmark markedfile list
7434" call s:NetrwUnmarkList(curbufnr,curdir)
7435 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007436" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007437 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007438 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007439 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007440
Bram Moolenaar446cb832008-06-24 21:56:24 +00007441" call Dret("s:NetrwMarkFileEdit")
7442endfun
7443
7444" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007445" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007446fun! s:NetrwMarkFileQFEL(islocal,qfel)
7447" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7448 call s:NetrwUnmarkAll()
7449 let curbufnr= bufnr("%")
7450
7451 if !empty(a:qfel)
7452 for entry in a:qfel
7453 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007454" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007455 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007456" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007457 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7458 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7459 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7460 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007461" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007462 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7463 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007464" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007465 endif
7466 endfor
7467 echo "(use me to edit marked files)"
7468 else
7469 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7470 endif
7471
7472" call Dret("s:NetrwMarkFileQFEL")
7473endfun
7474
7475" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007476" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7477" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7478" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7479fun! s:NetrwMarkFileExe(islocal,enbloc)
7480" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007481 let svpos = winsaveview()
7482" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007483 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007484 let curbufnr = bufnr("%")
7485
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007486 if a:enbloc == 0
7487 " individually apply command to files, one at a time
7488 " sanity check
7489 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7490 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7491" call Dret("s:NetrwMarkFileExe")
7492 return
7493 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007494" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007495
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007496 if exists("s:netrwmarkfilelist_{curbufnr}")
7497 " get the command
7498 call inputsave()
7499 let cmd= input("Enter command: ","","file")
7500 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007501" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007502 if cmd == ""
7503" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7504 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007505 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007506
7507 " apply command to marked files, individually. Substitute: filename -> %
7508 " If no %, then append a space and the filename to the command
7509 for fname in s:netrwmarkfilelist_{curbufnr}
7510 if a:islocal
7511 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007512 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007513 endif
7514 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007515 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007516 endif
7517 if cmd =~ '%'
7518 let xcmd= substitute(cmd,'%',fname,'g')
7519 else
7520 let xcmd= cmd.' '.fname
7521 endif
7522 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007523" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007524 let ret= system(xcmd)
7525 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007526" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007527 let ret= s:RemoteSystem(xcmd)
7528 endif
7529 if v:shell_error < 0
7530 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7531 break
7532 else
7533 echo ret
7534 endif
7535 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007536
7537 " unmark marked file list
7538 call s:NetrwUnmarkList(curbufnr,curdir)
7539
7540 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007541 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007542" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7543 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007544 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007545 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007546 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007547
7548 else " apply command to global list of files, en bloc
7549
7550 call inputsave()
7551 let cmd= input("Enter command: ","","file")
7552 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007553" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007554 if cmd == ""
7555" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7556 return
7557 endif
7558 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007559 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007560 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007561 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007562 endif
7563 if a:islocal
7564 call system(cmd)
7565 if v:shell_error < 0
7566 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7567 endif
7568 else
7569 let ret= s:RemoteSystem(cmd)
7570 endif
7571 call s:NetrwUnmarkAll()
7572
7573 " refresh the listing
7574 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007575" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7576 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007577
7578 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007579
Bram Moolenaar446cb832008-06-24 21:56:24 +00007580" call Dret("s:NetrwMarkFileExe")
7581endfun
7582
7583" ---------------------------------------------------------------------
7584" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7585" as the marked file(s) (toggles suffix presence)
7586" Uses the local marked file list.
7587fun! s:NetrwMarkHideSfx(islocal)
7588" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007589 let svpos = winsaveview()
7590" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007591 let curbufnr = bufnr("%")
7592
7593 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7594 if exists("s:netrwmarkfilelist_{curbufnr}")
7595
7596 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007597" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007598 " construct suffix pattern
7599 if fname =~ '\.'
7600 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7601 else
7602 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7603 endif
7604 " determine if its in the hiding list or not
7605 let inhidelist= 0
7606 if g:netrw_list_hide != ""
7607 let itemnum = 0
7608 let hidelist= split(g:netrw_list_hide,',')
7609 for hidepat in hidelist
7610 if sfxpat == hidepat
7611 let inhidelist= 1
7612 break
7613 endif
7614 let itemnum= itemnum + 1
7615 endfor
7616 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007617" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007618 if inhidelist
7619 " remove sfxpat from list
7620 call remove(hidelist,itemnum)
7621 let g:netrw_list_hide= join(hidelist,",")
7622 elseif g:netrw_list_hide != ""
7623 " append sfxpat to non-empty list
7624 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7625 else
7626 " set hiding list to sfxpat
7627 let g:netrw_list_hide= sfxpat
7628 endif
7629 endfor
7630
7631 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007632 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007633" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7634 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007635 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007636 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007637 endif
7638
7639" call Dret("s:NetrwMarkHideSfx")
7640endfun
7641
7642" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007643" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007644" Uses the local marked-file list.
7645fun! s:NetrwMarkFileVimCmd(islocal)
7646" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007647 let svpos = winsaveview()
7648" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007649 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007650 let curbufnr = bufnr("%")
7651
Bram Moolenaarff034192013-04-24 18:51:19 +02007652 " sanity check
7653 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007654 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007655" call Dret("s:NetrwMarkFileVimCmd")
7656 return
7657 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007658" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007659
Bram Moolenaar15146672011-10-20 22:22:38 +02007660 if exists("s:netrwmarkfilelist_{curbufnr}")
7661 " get the command
7662 call inputsave()
7663 let cmd= input("Enter vim command: ","","file")
7664 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007665" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007666 if cmd == ""
7667" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7668 return
7669 endif
7670
7671 " apply command to marked files. Substitute: filename -> %
7672 " If no %, then append a space and the filename to the command
7673 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007674" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007675 if a:islocal
7676 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007677 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007678" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007679 exe cmd
7680 exe "sil! keepalt wq!"
7681 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007682" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007683 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007684 endif
7685 endfor
7686
7687 " unmark marked file list
7688 call s:NetrwUnmarkList(curbufnr,curdir)
7689
7690 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007691 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007692" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7693 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007694 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007695 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007696 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007697
Bram Moolenaar15146672011-10-20 22:22:38 +02007698" call Dret("s:NetrwMarkFileVimCmd")
7699endfun
7700
7701" ---------------------------------------------------------------------
7702" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7703" as the marked file(s) (toggles suffix presence)
7704" Uses the local marked file list.
7705fun! s:NetrwMarkHideSfx(islocal)
7706" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007707 let svpos = winsaveview()
7708" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007709 let curbufnr = bufnr("%")
7710
7711 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7712 if exists("s:netrwmarkfilelist_{curbufnr}")
7713
7714 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007715" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007716 " construct suffix pattern
7717 if fname =~ '\.'
7718 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7719 else
7720 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7721 endif
7722 " determine if its in the hiding list or not
7723 let inhidelist= 0
7724 if g:netrw_list_hide != ""
7725 let itemnum = 0
7726 let hidelist= split(g:netrw_list_hide,',')
7727 for hidepat in hidelist
7728 if sfxpat == hidepat
7729 let inhidelist= 1
7730 break
7731 endif
7732 let itemnum= itemnum + 1
7733 endfor
7734 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007735" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007736 if inhidelist
7737 " remove sfxpat from list
7738 call remove(hidelist,itemnum)
7739 let g:netrw_list_hide= join(hidelist,",")
7740 elseif g:netrw_list_hide != ""
7741 " append sfxpat to non-empty list
7742 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7743 else
7744 " set hiding list to sfxpat
7745 let g:netrw_list_hide= sfxpat
7746 endif
7747 endfor
7748
7749 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007750 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007751" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7752 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007753 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007754 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007755 endif
7756
7757" call Dret("s:NetrwMarkHideSfx")
7758endfun
7759
7760" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007761" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7762" Uses the global markfilelist
7763fun! s:NetrwMarkFileGrep(islocal)
7764" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007765 let svpos = winsaveview()
7766" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007767 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007768 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007769
7770 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007771" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007772 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007773" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007774 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007775 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007776" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007777 let netrwmarkfilelist= "*"
7778 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007779
Bram Moolenaarff034192013-04-24 18:51:19 +02007780 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007781" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007782 call inputsave()
7783 let pat= input("Enter pattern: ","")
7784 call inputrestore()
7785 let patbang = ""
7786 if pat =~ '^!'
7787 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007788 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007789 endif
7790 if pat =~ '^\i'
7791 let pat = escape(pat,'/')
7792 let pat = '/'.pat.'/'
7793 else
7794 let nonisi = pat[0]
7795 endif
7796
7797 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007798" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007799 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007800 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007801 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007802 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007803" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7804 return
7805 endtry
7806 echo "(use :cn, :cp to navigate, :Rex to return)"
7807
7808 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007809" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7810 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007811
7812 if exists("nonisi")
7813 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007814" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007815 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007816 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007818 endif
7819
7820" call Dret("s:NetrwMarkFileGrep")
7821endfun
7822
7823" ---------------------------------------------------------------------
7824" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7825" uses the global marked file list
7826" s:netrwmfloc= 0: target directory is remote
7827" = 1: target directory is local
7828fun! s:NetrwMarkFileMove(islocal)
7829" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007830 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007831 let curbufnr = bufnr("%")
7832
7833 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007834 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007835 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007836" call Dret("s:NetrwMarkFileMove")
7837 return
7838 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007839" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007840
Bram Moolenaar446cb832008-06-24 21:56:24 +00007841 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007842 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007843" call Dret("s:NetrwMarkFileCopy 0")
7844 return 0
7845 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007846" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007847
7848 if a:islocal && s:netrwmftgt_islocal
7849 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007850" call Decho("move from local to local",'~'.expand("<slnum>"))
7851" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007852 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007853 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7854" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7855 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007856 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007857 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007858" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007859 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007860 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007861" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007862 if g:netrw_localmovecmd =~ '\s'
7863 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7864 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7865 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007866" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007867 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007868 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007869" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007870 endif
7871 else
7872 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007873" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007874 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007875 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007876 if g:netrw_keepdir
7877 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7878 let fname= b:netrw_curdir."/".fname
7879 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007880 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7881 let fname= substitute(fname,'/','\\','g')
7882 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007883" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007884 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007885 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007886 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007887 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 +01007888 else
7889 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7890 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007891 break
7892 endif
7893 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007894
7895 elseif a:islocal && !s:netrwmftgt_islocal
7896 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007897" call Decho("move from local to remote",'~'.expand("<slnum>"))
7898" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007899 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007900 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007901" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007902 for fname in mflist
7903 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7904 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7905 endfor
7906 unlet mflist
7907
7908 elseif !a:islocal && s:netrwmftgt_islocal
7909 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007910" call Decho("move from remote to local",'~'.expand("<slnum>"))
7911" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007912 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007913 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007914" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007915 for fname in mflist
7916 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7917 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7918 endfor
7919 unlet mflist
7920
7921 elseif !a:islocal && !s:netrwmftgt_islocal
7922 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007923" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7924" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007925 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007926 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007927" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007928 for fname in mflist
7929 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7930 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7931 endfor
7932 unlet mflist
7933 endif
7934
7935 " -------
7936 " cleanup
7937 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007938" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007939
7940 " remove markings from local buffer
7941 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7942
7943 " refresh buffers
7944 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007945" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007946 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007947 endif
7948 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007949" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007950 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007951 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007952 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007953" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007954 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007955 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007956
Bram Moolenaar446cb832008-06-24 21:56:24 +00007957" call Dret("s:NetrwMarkFileMove")
7958endfun
7959
7960" ---------------------------------------------------------------------
7961" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7962" using the hardcopy command. Local marked-file list only.
7963fun! s:NetrwMarkFilePrint(islocal)
7964" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7965 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007966
7967 " sanity check
7968 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007969 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007970" call Dret("s:NetrwMarkFilePrint")
7971 return
7972 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007973" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7974 let curdir= s:NetrwGetCurdir(a:islocal)
7975
Bram Moolenaar446cb832008-06-24 21:56:24 +00007976 if exists("s:netrwmarkfilelist_{curbufnr}")
7977 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007978 call s:NetrwUnmarkList(curbufnr,curdir)
7979 for fname in netrwmarkfilelist
7980 if a:islocal
7981 if g:netrw_keepdir
7982 let fname= s:ComposePath(curdir,fname)
7983 endif
7984 else
7985 let fname= curdir.fname
7986 endif
7987 1split
7988 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007989" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007990 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007991" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007992 hardcopy
7993 q
7994 endfor
7995 2match none
7996 endif
7997" call Dret("s:NetrwMarkFilePrint")
7998endfun
7999
8000" ---------------------------------------------------------------------
8001" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
8002" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02008003" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00008004fun! s:NetrwMarkFileRegexp(islocal)
8005" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
8006
8007 " get the regular expression
8008 call inputsave()
8009 let regexp= input("Enter regexp: ","","file")
8010 call inputrestore()
8011
8012 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008013 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008014" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008015 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008016" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008017 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008018 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008019 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008020 else
8021 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008022 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008023 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008024" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008025
8026 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008027 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02008028 if fname =~ '^'.fnameescape(curdir)
8029" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8030 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8031 else
8032" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8033 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8034 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008035 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008036
8037 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008038" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008039
8040 " convert displayed listing into a filelist
8041 let eikeep = &ei
8042 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008043 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008044 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008045" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008046 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008047 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008048 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008049 sil NetrwKeepj norm! "ap
8050 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008051 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008052 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008053 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008054 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008055 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008056 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008057 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008058 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008059 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008060 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008061 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8062 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008063 call histdel("/",-1)
8064 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008065 endif
8066 " convert regexp into the more usual glob-style format
8067 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008068" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008069 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008070 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008071 let filelist= getline(1,line("$"))
8072 q!
8073 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008074 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008075 endfor
8076 unlet filelist
8077 let @a = areg
8078 let &ei = eikeep
8079 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008080 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008081
8082" call Dret("s:NetrwMarkFileRegexp")
8083endfun
8084
8085" ---------------------------------------------------------------------
8086" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8087" Uses the local marked file list.
8088fun! s:NetrwMarkFileSource(islocal)
8089" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8090 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008091
8092 " sanity check
8093 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008094 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008095" call Dret("s:NetrwMarkFileSource")
8096 return
8097 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008098" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8099 let curdir= s:NetrwGetCurdir(a:islocal)
8100
Bram Moolenaar446cb832008-06-24 21:56:24 +00008101 if exists("s:netrwmarkfilelist_{curbufnr}")
8102 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008103 call s:NetrwUnmarkList(curbufnr,curdir)
8104 for fname in netrwmarkfilelist
8105 if a:islocal
8106 if g:netrw_keepdir
8107 let fname= s:ComposePath(curdir,fname)
8108 endif
8109 else
8110 let fname= curdir.fname
8111 endif
8112 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008113" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008114 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008115 endfor
8116 2match none
8117 endif
8118" call Dret("s:NetrwMarkFileSource")
8119endfun
8120
8121" ---------------------------------------------------------------------
8122" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8123" Uses the global markfilelist
8124fun! s:NetrwMarkFileTag(islocal)
8125" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008126 let svpos = winsaveview()
8127" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008128 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008129 let curbufnr = bufnr("%")
8130
Bram Moolenaarff034192013-04-24 18:51:19 +02008131 " sanity check
8132 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008133 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008134" call Dret("s:NetrwMarkFileTag")
8135 return
8136 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008137" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008138
Bram Moolenaar446cb832008-06-24 21:56:24 +00008139 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008140" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8141 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008142 call s:NetrwUnmarkAll()
8143
8144 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008145
8146" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8147 call system(g:netrw_ctags." ".netrwmarkfilelist)
8148 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8150 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008151
Bram Moolenaar446cb832008-06-24 21:56:24 +00008152 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008153 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008154 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008155 let curdir= b:netrw_curdir
8156 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008157 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008158 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008159" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008160 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008161 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008162 wq!
8163 endif
8164 2match none
8165 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008166" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8167 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008168 endif
8169
8170" call Dret("s:NetrwMarkFileTag")
8171endfun
8172
8173" ---------------------------------------------------------------------
8174" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008175" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008176" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008177" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008178" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008179fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008180" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8181 let svpos = winsaveview()
8182" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184 let hadtgt = exists("s:netrwmftgt")
8185 if !exists("w:netrw_bannercnt")
8186 let w:netrw_bannercnt= b:netrw_bannercnt
8187 endif
8188
8189 " set up target
8190 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008192 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8193 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008194" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008195 unlet s:netrwmftgt s:netrwmftgt_islocal
8196 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008197 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008198 endif
8199 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008200" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8201 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008202" call Dret("s:NetrwMarkFileTgt : removed target")
8203 return
8204 else
8205 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008206" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008207 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008208
8209 else
8210 " get word under cursor.
8211 " * If directory, use it for the target.
8212 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008213" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008214 let curword= s:NetrwGetWord()
8215 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008216 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008217 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008218" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008219 elseif !a:islocal && tgtdir =~ '/$'
8220 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008221" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008222 else
8223 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008224" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008225 endif
8226 endif
8227 if a:islocal
8228 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8229 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008230" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008231 endif
8232 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008233 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008234 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8235 endif
8236 let s:netrwmftgt_islocal= a:islocal
8237
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008238 " need to do refresh so that the banner will be updated
8239 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008240 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008241" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008242 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008243 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008244" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008245 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008246 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8247 else
8248 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8249 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008250" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8251 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008252 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008253 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008254 endif
8255
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008256" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8257" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008258" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8259endfun
8260
8261" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008262" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8263fun! s:NetrwGetCurdir(islocal)
8264" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8265
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008266 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008267 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8268" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8269 elseif !exists("b:netrw_curdir")
8270 let b:netrw_curdir= getcwd()
8271" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8272 endif
8273
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008274" 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 +01008275 if b:netrw_curdir !~ '\<\a\{3,}://'
8276 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008277" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008278 if g:netrw_keepdir == 0
8279 call s:NetrwLcd(curdir)
8280 endif
8281 endif
8282
8283" call Dret("s:NetrwGetCurdir <".curdir.">")
8284 return b:netrw_curdir
8285endfun
8286
8287" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008288" s:NetrwOpenFile: query user for a filename and open it {{{2
8289fun! s:NetrwOpenFile(islocal)
8290" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008291 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008292 call inputsave()
8293 let fname= input("Enter filename: ")
8294 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008295" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8296
8297 " determine if Lexplore is in use
8298 if exists("t:netrw_lexbufnr")
8299 " check if t:netrw_lexbufnr refers to a netrw window
8300" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8301 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8302 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8303" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8304 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8305 exe "NetrwKeepj e ".fnameescape(fname)
8306 let @@= ykeep
8307" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8308 endif
8309 endif
8310
8311 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008312 if fname !~ '[/\\]'
8313 if exists("b:netrw_curdir")
8314 if exists("g:netrw_quiet")
8315 let netrw_quiet_keep = g:netrw_quiet
8316 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008317 let g:netrw_quiet = 1
8318 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008319 let s:rexposn_{bufnr("%")}= winsaveview()
8320" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008321 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008322 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008323 else
8324 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8325 endif
8326 if exists("netrw_quiet_keep")
8327 let g:netrw_quiet= netrw_quiet_keep
8328 else
8329 unlet g:netrw_quiet
8330 endif
8331 endif
8332 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008333 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008334 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008335 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008336" call Dret("s:NetrwOpenFile")
8337endfun
8338
8339" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008340" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8341" For the mapping to this function be made via
8342" netrwPlugin, you'll need to have had
8343" g:netrw_usetab set to non-zero.
8344fun! netrw#Shrink()
8345" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8346 let curwin = winnr()
8347 let wiwkeep = &wiw
8348 set wiw=1
8349
8350 if &ft == "netrw"
8351 if winwidth(0) > g:netrw_wiw
8352 let t:netrw_winwidth= winwidth(0)
8353 exe "vert resize ".g:netrw_wiw
8354 wincmd l
8355 if winnr() == curwin
8356 wincmd h
8357 endif
8358" call Decho("vert resize 0",'~'.expand("<slnum>"))
8359 else
8360 exe "vert resize ".t:netrw_winwidth
8361" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8362 endif
8363
8364 elseif exists("t:netrw_lexbufnr")
8365 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8366 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8367 let t:netrw_winwidth= winwidth(0)
8368 exe "vert resize ".g:netrw_wiw
8369 wincmd l
8370 if winnr() == curwin
8371 wincmd h
8372 endif
8373" call Decho("vert resize 0",'~'.expand("<slnum>"))
8374 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8375 exe "vert resize ".t:netrw_winwidth
8376" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8377 else
8378 call netrw#Lexplore(0,0)
8379 endif
8380
8381 else
8382 call netrw#Lexplore(0,0)
8383 endif
8384 let wiw= wiwkeep
8385
8386" call Dret("netrw#Shrink")
8387endfun
8388
8389" ---------------------------------------------------------------------
8390" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8391fun! s:NetSortSequence(islocal)
8392" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8393
8394 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008395 let svpos= winsaveview()
8396" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008397 call inputsave()
8398 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8399 call inputrestore()
8400
8401 " refresh the listing
8402 let g:netrw_sort_sequence= newsortseq
8403 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008404" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8405 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008406 let @@= ykeep
8407
8408" call Dret("NetSortSequence")
8409endfun
8410
8411" ---------------------------------------------------------------------
8412" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8413" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008414" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008415fun! s:NetrwUnmarkList(curbufnr,curdir)
8416" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8417
8418 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008419 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008420 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8421 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8422 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8423 call remove(s:netrwmarkfilelist,idx) " remove from global list
8424 endfor
8425 if s:netrwmarkfilelist == []
8426 unlet s:netrwmarkfilelist
8427 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008428
Bram Moolenaar446cb832008-06-24 21:56:24 +00008429 " getting rid of the local marked-file lists is easy
8430 unlet s:netrwmarkfilelist_{a:curbufnr}
8431 endif
8432 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8433 unlet s:netrwmarkfilemtch_{a:curbufnr}
8434 endif
8435 2match none
8436" call Dret("s:NetrwUnmarkList")
8437endfun
8438
8439" ---------------------------------------------------------------------
8440" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8441fun! s:NetrwUnmarkAll()
8442" call Dfunc("s:NetrwUnmarkAll()")
8443 if exists("s:netrwmarkfilelist")
8444 unlet s:netrwmarkfilelist
8445 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008446 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008447 2match none
8448" call Dret("s:NetrwUnmarkAll")
8449endfun
8450
8451" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008452" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008453fun! s:NetrwUnmarkAll2()
8454" call Dfunc("s:NetrwUnmarkAll2()")
8455 redir => netrwmarkfilelist_let
8456 let
8457 redir END
8458 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008459 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008460 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8461 for flist in netrwmarkfilelist_list
8462 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8463 unlet s:netrwmarkfilelist_{curbufnr}
8464 unlet s:netrwmarkfilemtch_{curbufnr}
8465 endfor
8466" call Dret("s:NetrwUnmarkAll2")
8467endfun
8468
8469" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008470" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8471"
8472" Marked files are in two types of lists:
8473" s:netrwmarkfilelist -- holds complete paths to all marked files
8474" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8475"
8476" Marked files suitable for use with 2match are in:
8477" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008478fun! s:NetrwUnMarkFile(islocal)
8479" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008480 let svpos = winsaveview()
8481" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008482 let curbufnr = bufnr("%")
8483
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008484 " unmark marked file list
8485 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8486 if exists("s:netrwmarkfilelist")
8487" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008488 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008489 endif
8490
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008491 let ibuf= 1
8492 while ibuf < bufnr("$")
8493 if exists("s:netrwmarkfilelist_".ibuf)
8494 unlet s:netrwmarkfilelist_{ibuf}
8495 unlet s:netrwmarkfilemtch_{ibuf}
8496 endif
8497 let ibuf = ibuf + 1
8498 endwhile
8499 2match none
8500
Bram Moolenaar446cb832008-06-24 21:56:24 +00008501" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008502"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8503call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008504" call Dret("s:NetrwUnMarkFile")
8505endfun
8506
8507" ---------------------------------------------------------------------
8508" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8509fun! s:NetrwMenu(domenu)
8510
8511 if !exists("g:NetrwMenuPriority")
8512 let g:NetrwMenuPriority= 80
8513 endif
8514
Bram Moolenaaradc21822011-04-01 18:03:16 +02008515 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008516" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8517
8518 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008519" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008520 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008521 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8525 if g:netrw_dirhistmax > 0
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8530 else
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8532 endif
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8547 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 +01008548 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 +02008549 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8552 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8553 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8555 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8556 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8558 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8559 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8560 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8561 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8562 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8563 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8564 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8565 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8566 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8567 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8568 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8569 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8570 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8571 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8572 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8573 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8574 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8575 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8576 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8577 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8578 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>'
8579 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>'
8580 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>'
8581 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8582 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>'
8583 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>'
8584 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 +01008585 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 +02008586 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8587 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008588 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008589 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8590 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008591
8592 elseif !a:domenu
8593 let s:netrwcnt = 0
8594 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008595 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008596 exe curwin."wincmd w"
8597
8598 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008599" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008600 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008601" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008602 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008603 endif
8604 endif
8605" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008606 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607 endif
8608
8609endfun
8610
8611" ---------------------------------------------------------------------
8612" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8613" Used by the O maps (as <SID>NetrwObtain())
8614fun! s:NetrwObtain(islocal)
8615" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8616
Bram Moolenaar97d62492012-11-15 21:28:22 +01008617 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008618 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008619 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008620 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008621 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8622 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008623 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008624 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008625 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008626
8627" call Dret("NetrwObtain")
8628endfun
8629
8630" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008631" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8632" If there's only one window, then the window will first be split.
8633" Returns:
8634" choice = 0 : didn't have to choose
8635" choice = 1 : saved modified file in window first
8636" choice = 2 : didn't save modified file, opened window
8637" choice = 3 : cancel open
8638fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008639" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008640
Bram Moolenaar97d62492012-11-15 21:28:22 +01008641 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008642 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008643 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008644" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645
8646 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008647 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008648 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008649" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8650" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8651 let curword = s:NetrwGetWord()
8652 let choice = 0
8653 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8654" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008655 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008656" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008657 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008658" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008659" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008660" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008661
Bram Moolenaar8d043172014-01-23 14:24:41 +01008662 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008663 if lastwinnr == 1
8664 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008665" 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 +02008666 " g:netrw_preview=0: preview window shown in a horizontally split window
8667 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008668 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008669 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008670 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008671" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008672 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008673 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008674 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008675 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008676" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008677 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008678 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008679 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008680" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008681
8682 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008683" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008684 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008685" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008686 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008687" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008688 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008689" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008690 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008691" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008692" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008693" call Decho("COMBAK#12: mod=".&mod)
8694
8695 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8696 " whoops -- user trying to open file in the Lexplore window.
8697 " Use Lexplore's opening-file window instead.
8698" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8699" exe g:netrw_chgwin."wincmd w"
8700 wincmd p
8701 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8702 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008703
8704 " prevwinnr: the window number of the "prev" window
8705 " prevbufnr: the buffer number of the buffer in the "prev" window
8706 " bnrcnt : the qty of windows open on the "prev" buffer
8707 let prevwinnr = winnr()
8708 let prevbufnr = bufnr("%")
8709 let prevbufname = bufname("%")
8710 let prevmod = &mod
8711 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008712" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008713 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008714" 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 +01008715" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008716
8717 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008718 " and it doesn't appear in any other extant window, then ask the
8719 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008720 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008721" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008722 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008723" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008724 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008725" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008726
8727 if bnrcnt == 1 && &hidden == 0
8728 " only one copy of the modified buffer in a window, and
8729 " hidden not set, so overwriting will lose the modified file. Ask first...
8730 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008731" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008732 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008733" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008734
8735 if choice == 1
8736 " Yes -- write file & then browse
8737 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008738 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008739 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008740 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008741 exe origwin."wincmd w"
8742 let &ei = eikeep
8743 let @@ = ykeep
8744" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008745 return choice
8746 endif
8747
8748 elseif choice == 2
8749 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008750" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008751 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008752
8753 else
8754 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008755" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008756 exe origwin."wincmd w"
8757 let &ei= eikeep
8758 let @@ = ykeep
8759" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008760 return choice
8761 endif
8762 endif
8763 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008764 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008765 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008766" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008767
8768 " restore b:netrw_curdir (window split/enew may have lost it)
8769 let b:netrw_curdir= curdir
8770 if a:islocal < 2
8771 if a:islocal
8772 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8773 else
8774 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8775 endif
8776 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008777 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008778" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008779 return choice
8780endfun
8781
8782" ---------------------------------------------------------------------
8783" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8784" Always assumed to be local -> remote
8785" call s:NetrwUpload(filename, target)
8786" call s:NetrwUpload(filename, target, fromdirectory)
8787fun! s:NetrwUpload(fname,tgt,...)
8788" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8789
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008790 if a:tgt =~ '^\a\{3,}://'
8791 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792 else
8793 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8794 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008795" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008796
8797 if a:0 > 0
8798 let fromdir= a:1
8799 else
8800 let fromdir= getcwd()
8801 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008802" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008803
8804 if type(a:fname) == 1
8805 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008806" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008807 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008808" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8809 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8810" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008811 if a:tgt =~ '/$'
8812 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008813" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008814 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008815 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008816" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008817 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008818" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008819 endif
8820 q!
8821
8822 elseif type(a:fname) == 3
8823 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008824" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008825 let curdir= getcwd()
8826 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008827 if s:NetrwLcd(fromdir)
8828" call Dret("s:NetrwUpload : lcd failure")
8829 return
8830 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008831 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008832 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008833 if exists("g:netrw_port") && g:netrw_port != ""
8834 let useport= " ".g:netrw_scpport." ".g:netrw_port
8835 else
8836 let useport= ""
8837 endif
8838 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8839 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008840 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 +02008841 if s:NetrwLcd(curdir)
8842" call Dret("s:NetrwUpload : lcd failure")
8843 return
8844 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008845
8846 elseif a:tgt =~ '^ftp:'
8847 call s:NetrwMethod(a:tgt)
8848
8849 if b:netrw_method == 2
8850 " handle uploading a list of files via ftp+.netrc
8851 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008852 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008853" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008854
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008855 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008856" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008857
8858 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008859 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008860" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008861 endif
8862
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008863 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008864" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008865
Bram Moolenaaradc21822011-04-01 18:03:16 +02008866 if tgtdir == ""
8867 let tgtdir= '/'
8868 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008869 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008870" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008871
8872 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008873 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8874" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008875 endfor
8876
8877 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008878 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 +00008879 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008880" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8881 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008882 endif
8883 " 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 +01008884 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008885 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008886 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8887 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8888 else
8889 bw!|q
8890 endif
8891
8892 elseif b:netrw_method == 3
8893 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8894 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008895 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008896 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008897 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008898
8899 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008900 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008901" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008902 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008903 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008904" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008905 endif
8906
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008907 if exists("g:netrw_uid") && g:netrw_uid != ""
8908 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008909 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008910" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008911 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008912 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008913 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008914" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008915 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008916 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008917" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008918 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008919 endif
8920
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008921 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008922" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008923
8924 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008925 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008926" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008927 endif
8928
8929 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008930 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008931" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008932 endif
8933
8934 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008935 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008936" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008937 endfor
8938
8939 " perform ftp:
8940 " -i : turns off interactive prompting from ftp
8941 " -n unix : DON'T use <.netrc>, even though it exists
8942 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008943 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008944 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008945 " 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 +01008946 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008947 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008948 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8949 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008950 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008951 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8952 let &debug = debugkeep
8953 let mod = 1
8954 else
8955 bw!|q
8956 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008957 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008958" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008959 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008960 endif
8961 else
8962 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8963 endif
8964 endif
8965
8966" call Dret("s:NetrwUpload")
8967endfun
8968
8969" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008970" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008971fun! s:NetrwPreview(path) range
8972" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008973" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8974" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008975 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008976 NetrwKeepj call s:NetrwOptionsSave("s:")
8977 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8978 NetrwKeepj call s:NetrwOptionsSafe(1)
8979 else
8980 NetrwKeepj call s:NetrwOptionsSafe(0)
8981 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008982 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008983" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008984 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008985" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8986 if g:netrw_preview
8987 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008988 let pvhkeep = &pvh
8989 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8990 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008991" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8992 else
8993 " horizontal split
8994 let pvhkeep = &pvh
8995 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8996 let &pvh = winheight(0) - winsz
8997" 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 +02008998 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008999 " g:netrw_preview g:netrw_alto
9000 " 1 : vert 1: top -- preview window is vertically split off and on the left
9001 " 1 : vert 0: bot -- preview window is vertically split off and on the right
9002 " 0 : 1: top -- preview window is horizontally split off and on the top
9003 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
9004 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009005 " 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 +02009006 " the BufEnter event set up in netrwPlugin.vim
9007" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
9008 let eikeep = &ei
9009 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009010 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009011 let &ei= eikeep
9012" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009013 if exists("pvhkeep")
9014 let &pvh= pvhkeep
9015 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009016 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009017 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009018 endif
9019 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009020 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 +00009021 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009022 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009023 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009024" call Dret("NetrwPreview")
9025endfun
9026
9027" ---------------------------------------------------------------------
9028" s:NetrwRefresh: {{{2
9029fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009030" 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 +00009031 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009032 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009033" call Decho("setl ma noro",'~'.expand("<slnum>"))
9034" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009035 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009036 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9037 if !exists("w:netrw_treetop")
9038 if exists("b:netrw_curdir")
9039 let w:netrw_treetop= b:netrw_curdir
9040 else
9041 let w:netrw_treetop= getcwd()
9042 endif
9043 endif
9044 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9045 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009046
9047 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009048 let screenposn = winsaveview()
9049" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009050
9051" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9052" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9053 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009055 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009056 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009057 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009058 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009059
9060 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009061" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9062 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009063
9064 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009065 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9066 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9067" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9068 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9069 else
9070" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9071 2match none
9072 endif
9073 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074
Bram Moolenaar97d62492012-11-15 21:28:22 +01009075" restore
9076 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009077" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009078endfun
9079
9080" ---------------------------------------------------------------------
9081" s:NetrwRefreshDir: refreshes a directory by name {{{2
9082" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009083" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009084fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009085" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009086 if g:netrw_fastbrowse == 0
9087 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009088" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009089 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009090" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009091
9092 if tgtwin > 0
9093 " tgtwin is being displayed, so refresh it
9094 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009095" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009096 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009097 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009098 exe curwin."wincmd w"
9099
9100 elseif bufnr(a:dirname) > 0
9101 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009102" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9103 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009104 endif
9105
9106 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009107" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009108 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009109 endif
9110" call Dret("s:NetrwRefreshDir")
9111endfun
9112
9113" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009114" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9115" window number to do its editing in.
9116" Supports [count]C where the count, if present, is used to specify
9117" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009118fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009119" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009120 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009121" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009122 if a:1 == "" " :NetrwC win#
9123 let g:netrw_chgwin= winnr()
9124 else " :NetrwC
9125 let g:netrw_chgwin= a:1
9126 endif
9127 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009128 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009129 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009130 let g:netrw_chgwin= winnr()
9131 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009132 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009133" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009134endfun
9135
9136" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009137" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9138" What this function does is to compute a priority for the patterns
9139" in the g:netrw_sort_sequence. It applies a substitute to any
9140" "files" that satisfy each pattern, putting the priority / in
9141" front. An "*" pattern handles the default priority.
9142fun! s:NetrwSetSort()
9143" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009144 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009145 if w:netrw_liststyle == s:LONGLIST
9146 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9147 else
9148 let seqlist = g:netrw_sort_sequence
9149 endif
9150 " sanity check -- insure that * appears somewhere
9151 if seqlist == ""
9152 let seqlist= '*'
9153 elseif seqlist !~ '\*'
9154 let seqlist= seqlist.',*'
9155 endif
9156 let priority = 1
9157 while seqlist != ""
9158 if seqlist =~ ','
9159 let seq = substitute(seqlist,',.*$','','e')
9160 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9161 else
9162 let seq = seqlist
9163 let seqlist = ""
9164 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009166 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009167 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009168 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009169 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009170 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009171 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009172" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009173
9174 " sanity check
9175 if w:netrw_bannercnt > line("$")
9176 " apparently no files were left after a Hiding pattern was used
9177" call Dret("SetSort : no files left after hiding")
9178 return
9179 endif
9180 if seq == '*'
9181 let starpriority= spriority
9182 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009183 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009184 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009185 " sometimes multiple sorting patterns will match the same file or directory.
9186 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009187 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9188 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009189 endif
9190 let priority = priority + 1
9191 endwhile
9192 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009193 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9194 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009195 endif
9196
9197 " Following line associated with priority -- items that satisfy a priority
9198 " pattern get prefixed by ###/ which permits easy sorting by priority.
9199 " Sometimes files can satisfy multiple priority patterns -- only the latest
9200 " priority pattern needs to be retained. So, at this point, these excess
9201 " priority prefixes need to be removed, but not directories that happen to
9202 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009203 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9204 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009205 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009206
9207" call Dret("SetSort")
9208endfun
9209
Bram Moolenaarff034192013-04-24 18:51:19 +02009210" ---------------------------------------------------------------------
9211" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9212" Implements [count]Tb (bookhist<b>)
9213" [count]Th (bookhist<h>)
9214" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009215fun! s:NetrwSetTgt(islocal,bookhist,choice)
9216" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009217
9218 if a:bookhist == 'b'
9219 " supports choosing a bookmark as a target using a qb-generated list
9220 let choice= a:choice - 1
9221 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009222 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009223 else
9224 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9225 endif
9226
9227 elseif a:bookhist == 'h'
9228 " supports choosing a history stack entry as a target using a qb-generated list
9229 let choice= (a:choice % g:netrw_dirhistmax) + 1
9230 if exists("g:netrw_dirhist_".choice)
9231 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009232 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009233 else
9234 echomsg "Sorry, history#".a:choice." not available!"
9235 endif
9236 endif
9237
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009238 " refresh the display
9239 if !exists("b:netrw_curdir")
9240 let b:netrw_curdir= getcwd()
9241 endif
9242 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9243
Bram Moolenaarff034192013-04-24 18:51:19 +02009244" call Dret("s:NetrwSetTgt")
9245endfun
9246
Bram Moolenaar446cb832008-06-24 21:56:24 +00009247" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009248" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009249fun! s:NetrwSortStyle(islocal)
9250" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009251 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009252 let svpos= winsaveview()
9253" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009254
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009255 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 +01009256 NetrwKeepj norm! 0
9257 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009258" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9259 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009260
9261" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9262endfun
9263
9264" ---------------------------------------------------------------------
9265" s:NetrwSplit: mode {{{2
9266" =0 : net and o
9267" =1 : net and t
9268" =2 : net and v
9269" =3 : local and o
9270" =4 : local and t
9271" =5 : local and v
9272fun! s:NetrwSplit(mode)
9273" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9274
Bram Moolenaar97d62492012-11-15 21:28:22 +01009275 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009276 call s:SaveWinVars()
9277
9278 if a:mode == 0
9279 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009280 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009281 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009282" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009283 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009284 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009285 NetrwKeepj call s:RestoreWinVars()
9286 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009287 unlet s:didsplit
9288
9289 elseif a:mode == 1
9290 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009291 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009292" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009293 tabnew
9294 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009295 NetrwKeepj call s:RestoreWinVars()
9296 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009297 unlet s:didsplit
9298
9299 elseif a:mode == 2
9300 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009301 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009302 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009303" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009304 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009305 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009306 NetrwKeepj call s:RestoreWinVars()
9307 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009308 unlet s:didsplit
9309
9310 elseif a:mode == 3
9311 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009312 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009313 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009314" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009315 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009316 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009317 NetrwKeepj call s:RestoreWinVars()
9318 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009319 unlet s:didsplit
9320
9321 elseif a:mode == 4
9322 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009323 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009324 let eikeep = &ei
9325 let netrw_winnr = winnr()
9326 let netrw_line = line(".")
9327 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009328 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009329 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009330 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009331 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9332 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009333 let &ei = eikeep
9334 let netrw_curdir = s:NetrwTreeDir(0)
9335" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009336 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009337 let b:netrw_curdir = netrw_curdir
9338 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009339 NetrwKeepj call s:RestoreWinVars()
9340 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009341 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009342 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009343 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9344 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009345 let &ei= eikeep
9346 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009347 unlet s:didsplit
9348
9349 elseif a:mode == 5
9350 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009351 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009352 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009353" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009354 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009355 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009356 NetrwKeepj call s:RestoreWinVars()
9357 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009358 unlet s:didsplit
9359
9360 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009361 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009362 endif
9363
Bram Moolenaar97d62492012-11-15 21:28:22 +01009364 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009365" call Dret("s:NetrwSplit")
9366endfun
9367
9368" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009369" s:NetrwTgtMenu: {{{2
9370fun! s:NetrwTgtMenu()
9371 if !exists("s:netrw_menucnt")
9372 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009373 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009374" call Dfunc("s:NetrwTgtMenu()")
9375
9376 " the following test assures that gvim is running, has menus available, and has menus enabled.
9377 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9378 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009379" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009380 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9381 endif
9382 if !exists("s:netrw_initbookhist")
9383 call s:NetrwBookHistRead()
9384 endif
9385
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009386 " try to cull duplicate entries
9387 let tgtdict={}
9388
Bram Moolenaarff034192013-04-24 18:51:19 +02009389 " target bookmarked places
9390 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009391" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009392 let cnt= 1
9393 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009394 if has_key(tgtdict,bmd)
9395 let cnt= cnt + 1
9396 continue
9397 endif
9398 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009399 let ebmd= escape(bmd,g:netrw_menu_escape)
9400 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009401" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009402 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 +02009403 let cnt= cnt + 1
9404 endfor
9405 endif
9406
9407 " target directory browsing history
9408 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009409" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009410 let histcnt = 1
9411 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009412 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009413 if exists("g:netrw_dirhist_{histcnt}")
9414 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009415 if has_key(tgtdict,histentry)
9416 let histcnt = histcnt + 1
9417 continue
9418 endif
9419 let tgtdict[histentry] = histcnt
9420 let ehistentry = escape(histentry,g:netrw_menu_escape)
9421" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009422 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 +02009423 endif
9424 let histcnt = histcnt + 1
9425 endwhile
9426 endif
9427 endif
9428" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009429endfun
9430
9431" ---------------------------------------------------------------------
9432" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9433" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009434fun! s:NetrwTreeDir(islocal)
9435" 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 +02009436" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009437" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9438" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9439" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009440" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009441
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009442 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009443 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009444" 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 +01009445 let treedir= s:treedir
9446 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009447 unlet s:prevwinopen
9448" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009449 return treedir
9450 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009451 if exists("s:prevwinopen")
9452 unlet s:prevwinopen
9453 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009454" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009455
Bram Moolenaar8d043172014-01-23 14:24:41 +01009456 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9457 let b:netrw_curdir= getcwd()
9458 endif
9459 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009460" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009461" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009462
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009463 let s:treecurpos= winsaveview()
9464" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009465" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009466
9467 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009468" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9469" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009470" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009471
9472 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009473 let curline= substitute(getline('.'),"\t -->.*$",'','')
9474 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009475" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009476 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009477" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9478 elseif curline =~ '@$'
9479" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009480 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009481" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009482 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009483" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009484 let treedir= ""
9485 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009486" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009487
9488 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009489" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9490" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009491" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009492 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009493" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009494 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009495" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9496 sil! NetrwKeepj %d _
9497" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009498 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009499" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009500" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009501 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009502" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009503
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009504" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009505" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009506" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009507
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009508 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9509" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9510" let newdir = w:netrw_treetop.'/'.potentialdir
9511" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9512" let treedir = s:NetrwTreePath(newdir)
9513" let w:netrw_treetop = newdir
9514" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9515" else
9516" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009517 if a:islocal && curline =~ '@$'
9518 if isdirectory(s:NetrwFile(potentialdir))
9519 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9520 let w:netrw_treetop = treedir
9521 endif
9522 else
9523 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9524 let treedir = s:NetrwTreePath(w:netrw_treetop)
9525 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009526 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009527" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009528
9529 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009530 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009531" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009532" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009533
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009534" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009535 return treedir
9536endfun
9537
9538" ---------------------------------------------------------------------
9539" s:NetrwTreeDisplay: recursive tree display {{{2
9540fun! s:NetrwTreeDisplay(dir,depth)
9541" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9542
9543 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009544 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009545
9546 " install ../ and shortdir
9547 if a:depth == ""
9548 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009549" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009550 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009551 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009552 if a:dir == w:netrw_treetop
9553 let shortdir= a:dir
9554 else
9555 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9556 endif
9557 call setline(line("$")+1,a:depth.shortdir)
9558 else
9559 let shortdir= substitute(a:dir,'^.*/','','e')
9560 call setline(line("$")+1,a:depth.shortdir.'/')
9561 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009562" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009563 " append a / to dir if its missing one
9564 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009565
9566 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009567 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009568" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009569
Bram Moolenaar85850f32019-07-19 22:05:51 +02009570 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9571 if g:netrw_hide == 1
9572 " hide given patterns
9573 let listhide= split(g:netrw_list_hide,',')
9574" call Decho("listhide=".string(listhide))
9575 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009576 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009577 endfor
9578
9579 elseif g:netrw_hide == 2
9580 " show given patterns (only)
9581 let listhide= split(g:netrw_list_hide,',')
9582" call Decho("listhide=".string(listhide))
9583 let entries=[]
9584 for entry in w:netrw_treedict[dir]
9585 for pat in listhide
9586 if entry =~ pat
9587 call add(entries,entry)
9588 break
9589 endif
9590 endfor
9591 endfor
9592 let w:netrw_treedict[dir]= entries
9593 endif
9594 if depth != ""
9595 " always remove "." and ".." entries when there's depth
9596 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9597 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9598 endif
9599
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009600" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009601 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009602 if dir =~ '/$'
9603 let direntry= substitute(dir.entry,'[@/]$','','e')
9604 else
9605 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9606 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009607" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009608 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009609" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009610 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009611 elseif 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>"))
9613 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9614 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9615" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009616 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009617 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009618" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009619 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009620 endif
9621 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009622" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009623
Bram Moolenaar446cb832008-06-24 21:56:24 +00009624" call Dret("NetrwTreeDisplay")
9625endfun
9626
9627" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009628" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9629fun! s:NetrwRefreshTreeDict(dir)
9630" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009631 if !exists("w:netrw_treedict")
9632" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9633 return
9634 endif
9635
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009636 for entry in w:netrw_treedict[a:dir]
9637 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9638" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9639
9640 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9641" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9642 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009643 let liststar = s:NetrwGlob(direntry,'*',1)
9644 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009645 let w:netrw_treedict[direntry] = liststar + listdotstar
9646" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9647
9648 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9649" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9650 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009651 let liststar = s:NetrwGlob(direntry.'/','*',1)
9652 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009653 let w:netrw_treedict[direntry]= liststar + listdotstar
9654" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9655
9656 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9657" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9658 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009659 let liststar = s:NetrwGlob(direntry.'/','*',1)
9660 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009661" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9662
9663 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009664" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009665 endif
9666 endfor
9667" call Dret("s:NetrwRefreshTreeDict")
9668endfun
9669
9670" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009671" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009672" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009673fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009674 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009675" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009676" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9677" 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>"))
9678" 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 +00009679
9680 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009681 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009682" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009683 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009684 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009685" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009686 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 +02009687" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009688 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009689 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009690" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009691 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009692 if exists("w:netrw_treetop")
9693 let s:netrw_treetop= w:netrw_treetop
9694 else
9695 let w:netrw_treetop= getcwd()
9696 let s:netrw_treetop= w:netrw_treetop
9697 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009698
Bram Moolenaar446cb832008-06-24 21:56:24 +00009699 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009700 " insure that we have a treedict, albeit empty
9701" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009702 let w:netrw_treedict= {}
9703 endif
9704
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009705 " update the dictionary for the current directory
9706" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009707" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009708 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009709 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009710" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009711 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009712
9713 " if past banner, record word
9714 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9715 let fname= expand("<cword>")
9716 else
9717 let fname= ""
9718 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009719" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9720" 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 +00009721
9722 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009723" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009724 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009725" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009726
9727 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9728 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009729" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009730 1d
9731 endwhile
9732
Bram Moolenaar13600302014-05-22 18:26:40 +02009733 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009734
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009735" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009736 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009737 endif
9738endfun
9739
9740" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009741" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009742" Normally, treetop is w:netrw_treetop, but a
9743" user of the function ( netrw#SetTreetop() )
9744" wipes that out prior to calling this function
9745fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009746" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9747 if line(".") < w:netrw_bannercnt + 2
9748 let treedir= a:treetop
9749 if treedir !~ '/$'
9750 let treedir= treedir.'/'
9751 endif
9752" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9753 return treedir
9754 endif
9755
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009756 let svpos = winsaveview()
9757" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009758 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009759" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009760 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009761" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9762 let curline= getline('.')
9763" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9764 if curline =~ '/$'
9765" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9766 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9767" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9768 elseif curline =~ '@\s\+-->'
9769" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9770 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9771 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9772" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009773 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009774" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009775 let treedir= ""
9776 endif
9777 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009778" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9779" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009780 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9781 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9782 let treedir= dirname.treedir
9783 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009784" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009785 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009786" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009787 if a:treetop =~ '/$'
9788 let treedir= a:treetop.treedir
9789 else
9790 let treedir= a:treetop.'/'.treedir
9791 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009792" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009793 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009794" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009795" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9796 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009797" call Dret("s:NetrwTreePath <".treedir.">")
9798 return treedir
9799endfun
9800
9801" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009802" s:NetrwWideListing: {{{2
9803fun! s:NetrwWideListing()
9804
9805 if w:netrw_liststyle == s:WIDELIST
9806" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9807 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009808 " cpf: characters per filename
9809 " fpl: filenames per line
9810 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009811 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009812 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009813" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009814 let b:netrw_cpf= 0
9815 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009816 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009817 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9818 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009819 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009820 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009821" call Dret("NetrwWideListing")
9822 return
9823 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009824 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009825 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009826" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009827
9828 " determine qty files per line (fpl)
9829 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9830 if w:netrw_fpl <= 0
9831 let w:netrw_fpl= 1
9832 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009833" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009834
9835 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009836 " fpc: files per column of wide listing
9837 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009838 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009839 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9840 let newcolstart = w:netrw_bannercnt + fpc
9841 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009842" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009843 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009844" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009845 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009846 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009847 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009848 while line("$") >= newcolstart
9849 if newcolend > line("$") | let newcolend= line("$") | endif
9850 let newcolqty= newcolend - newcolstart
9851 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009852 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009853 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009854 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009855 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009856 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009857 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009858 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009859 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009860 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009861 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009862" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009863 if @* != keepregstar | sil! let @* = keepregstar | endif
9864 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009865 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009866 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9867 NetrwKeepj call histdel("/",-1)
9868 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9869 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009870" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009871 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009872 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009873" 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 +00009874" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009875 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009876 else
9877 if hasmapto("w","n")
9878 sil! nunmap <buffer> w
9879 endif
9880 if hasmapto("b","n")
9881 sil! nunmap <buffer> b
9882 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009883 endif
9884
9885endfun
9886
9887" ---------------------------------------------------------------------
9888" s:PerformListing: {{{2
9889fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009890" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9891" 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 +02009892" 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>"))
9893 sil! NetrwKeepj %d _
9894" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009895
Bram Moolenaar15146672011-10-20 22:22:38 +02009896 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009897" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009898 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009899
Bram Moolenaar85850f32019-07-19 22:05:51 +02009900 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009901 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009902" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009903
9904" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009905" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009906" endif " Decho
9907
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009908" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009909 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9910 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009911" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9912 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009913 endif
9914
9915 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009916 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009917
9918 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009919 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009920" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009921 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009922 if exists("g:netrw_pchk")
9923 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9924 " failure detections.
9925 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009926 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009927 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9928 endif
9929 if exists("g:netrw_pchk")
9930 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9931 else
9932 let curdir= b:netrw_curdir
9933 endif
9934 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9935 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9936 else
9937 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009938 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009939 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009940 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009941 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009942" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009943 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009944 let w:netrw_bannercnt= 1
9945 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009946" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9947" 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 +00009948
Bram Moolenaar85850f32019-07-19 22:05:51 +02009949 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009950 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009951 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009952 let sortby= sortby." reversed"
9953 endif
9954
9955 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009956 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009957" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009958 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009959" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009960 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009961 NetrwKeepj put ='\" Sorted by '.sortby
9962 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009963 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9964 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009965" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009966 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009967 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009968 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9969 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009970 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009971" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009972" 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 +00009973 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009974
Bram Moolenaar85850f32019-07-19 22:05:51 +02009975 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009976 if g:netrw_banner
9977 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009978" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009979 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009980 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009981 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009982 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009983 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009984 endif
9985 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009986 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009987" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009988 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009989 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009991
9992 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009993 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009994" 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 +01009995 if g:netrw_list_hide != "" && g:netrw_hide
9996 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009997 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009998 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009999 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +010010000 endif
10001 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010002 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010003 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010004
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010005" 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 +010010006 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010007" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010008 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010009" 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 +010010010 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +010010011 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +010010012" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010013" 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 +000010014 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010015
10016 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +010010017 if g:netrw_banner
10018 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010019 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010020" 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 +010010021" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010022" 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 +010010023 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010024
Bram Moolenaar446cb832008-06-24 21:56:24 +000010025 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010026" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010027 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010028 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010029 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010030 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010031 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010032" 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 +010010033" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10034 return
10035 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010036 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010037
10038 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010039 if !exists("w:netrw_bannercnt")
10040 let w:netrw_bannercnt= 0
10041 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010042" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10043" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10044" 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 +010010045
Bram Moolenaar5c736222010-01-06 20:54:52 +010010046 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010047" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010048" 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 +000010049 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010050 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010051 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010052 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010053" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010054
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010055 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010056 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010057" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010058 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010059
Bram Moolenaar5c736222010-01-06 20:54:52 +010010060 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010061" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010062 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010063 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010064 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010065 else
10066 " reverse direction sorting
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 endif
10069 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010070
Bram Moolenaar446cb832008-06-24 21:56:24 +000010071 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010072" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010073 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10074 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010075
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010076 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010077 " exten: sort by extension
10078 " The histdel(...,-1) calls remove the last search from the search history
10079" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010080 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10081 NetrwKeepj call histdel("/",-1)
10082 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10083 NetrwKeepj call histdel("/",-1)
10084 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10085 NetrwKeepj call histdel("/",-1)
10086 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10087" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010088 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010089 " normal direction sorting
10090 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10091 else
10092 " reverse direction sorting
10093 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10094 endif
10095 endif
10096 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10097 NetrwKeepj call histdel("/",-1)
10098
Bram Moolenaar446cb832008-06-24 21:56:24 +000010099 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010100 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010101" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010102 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010103" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010104 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010105 else
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 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010109" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010110 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10111 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010112 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010113 endif
10114
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010115 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010116" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010117 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010118 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010119 call histdel("/",-1)
10120 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010121 endif
10122 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010123" 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 +000010124
10125 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010126" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10127" 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 +010010128 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010129" 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 +010010130 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010131" 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 +000010132
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010133 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010134 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010135" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010136 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010137 endif
10138
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010139 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010140 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010141" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10142 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010143 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010144" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10145 else
10146" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10147" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10148" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10149" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010150 endif
10151
10152 " record previous current directory
10153 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010154" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010155
10156 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010157" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10158" 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 +010010159 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010160" 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 +020010161 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010162" 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 +000010163
10164 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010165" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010166 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010167" 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 +010010168 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010169" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010170 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10171 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010172" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010173" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010174
Bram Moolenaar8d043172014-01-23 14:24:41 +010010175 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010176" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10177" 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 +010010178" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10179 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010180 unlet s:treecurpos
10181 endif
10182
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010183" 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>"))
10184" 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 +000010185" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10186endfun
10187
10188" ---------------------------------------------------------------------
10189" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010190fun! s:SetupNetrwStatusLine(statline)
10191" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10192
10193 if !exists("s:netrw_setup_statline")
10194 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010195" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010196
10197 if !exists("s:netrw_users_stl")
10198 let s:netrw_users_stl= &stl
10199 endif
10200 if !exists("s:netrw_users_ls")
10201 let s:netrw_users_ls= &laststatus
10202 endif
10203
10204 " set up User9 highlighting as needed
10205 let keepa= @a
10206 redir @a
10207 try
10208 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010209 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010210 if &bg == "dark"
10211 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10212 else
10213 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10214 endif
10215 endtry
10216 redir END
10217 let @a= keepa
10218 endif
10219
10220 " set up status line (may use User9 highlighting)
10221 " insure that windows have a statusline
10222 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010223 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010224 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010225" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010226 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010227
10228" call Dret("SetupNetrwStatusLine : stl=".&stl)
10229endfun
10230
Bram Moolenaar85850f32019-07-19 22:05:51 +020010231" =========================================
10232" Remote Directory Browsing Support: {{{1
10233" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010234
10235" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010236" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10237" This function assumes that a long listing will be received. Size, time,
10238" and reverse sorts will be requested of the server but not otherwise
10239" enforced here.
10240fun! s:NetrwRemoteFtpCmd(path,listcmd)
10241" 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 +010010242" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010243 " sanity check: {{{3
10244 if !exists("w:netrw_method")
10245 if exists("b:netrw_method")
10246 let w:netrw_method= b:netrw_method
10247 else
10248 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10249" call Dret("NetrwRemoteFtpCmd")
10250 return
10251 endif
10252 endif
10253
10254 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10255 let ffkeep= &ff
10256 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010257" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010258
10259 " clear off any older non-banner lines " {{{3
10260 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010261" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10262 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010263
10264 ".........................................
10265 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10266 " ftp + <.netrc>: Method #2
10267 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010268 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010269 endif
10270 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010271 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010272" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010273 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010274 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010275" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010276 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010277" 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>"))
10278 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 +010010279 else
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),'~'.expand("<slnum>"))
10281 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 +010010282 endif
10283
10284 ".........................................
10285 elseif w:netrw_method == 3 " {{{3
10286 " ftp + machine,id,passwd,filename: Method #3
10287 setl ff=unix
10288 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010289 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010290 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010291 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010292 endif
10293
10294 " handle userid and password
10295 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010296" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010297 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10298 call NetUserPass("ftp:".host)
10299 endif
10300 if exists("g:netrw_uid") && g:netrw_uid != ""
10301 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010302 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010303 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010304 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010305 endif
10306 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010307 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010308 endif
10309 endif
10310
10311 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010312 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010313 endif
10314 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010315 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010316" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010317 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010318 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010319
10320 " perform ftp:
10321 " -i : turns off interactive prompting from ftp
10322 " -n unix : DON'T use <.netrc>, even though it exists
10323 " -n win32: quit being obnoxious about password
10324 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010325" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010326 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010327" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010328" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10329" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010330 endif
10331
10332 ".........................................
10333 elseif w:netrw_method == 9 " {{{3
10334 " sftp username@machine: Method #9
10335 " s:netrw_sftp_cmd
10336 setl ff=unix
10337
10338 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010339 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010340" call Dret("NetrwRemoteFtpCmd")
10341 return
10342
10343 ".........................................
10344 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010345 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010346 endif
10347
10348 " cleanup for Windows " {{{3
10349 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010350 sil! NetrwKeepj %s/\r$//e
10351 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010352 endif
10353 if a:listcmd == "dir"
10354 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010355 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10356 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10357 NetrwKeepj call histdel("/",-1)
10358 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010359 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 +010010360 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10361 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010362 endif
10363 endif
10364
10365 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10366 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010367 exe 'NetrwKeepj '.w:netrw_bannercnt
10368 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010369 endif
10370 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010371 exe 'NetrwKeepj '.w:netrw_bannercnt
10372 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010373 endif
10374
10375 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010376 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010377" call Dret("NetrwRemoteFtpCmd")
10378endfun
10379
10380" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010381" s:NetrwRemoteListing: {{{2
10382fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010383" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010384
Bram Moolenaara6878372014-03-22 21:02:50 +010010385 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10386 let w:netrw_bannercnt= s:bannercnt
10387 endif
10388 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010389 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010390 endif
10391
Bram Moolenaar446cb832008-06-24 21:56:24 +000010392 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010393
Bram Moolenaar446cb832008-06-24 21:56:24 +000010394 " sanity check:
10395 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010396" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010398" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010399 if !exists("g:netrw_quiet")
10400 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10401 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010402 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010403" call Dret("s:NetrwRemoteListing -1")
10404 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010405 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010406
Bram Moolenaar8d043172014-01-23 14:24:41 +010010407 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010408" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010409 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010410 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010411 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 +000010412 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010413 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 +000010414 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010415 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010416
Bram Moolenaar85850f32019-07-19 22:05:51 +020010417 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010418" call Dret("s:NetrwRemoteListing -1")
10419 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010420 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010421" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010422
Bram Moolenaar446cb832008-06-24 21:56:24 +000010423 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010424" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010425 let w:netrw_method= b:netrw_method
10426 endif
10427
Bram Moolenaar13600302014-05-22 18:26:40 +020010428 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010429 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010430" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010431 let s:method = "ftp"
10432 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010433 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010434 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010435 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010436 let listcmd= g:netrw_ftp_sizelist_cmd
10437 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010438" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010439 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010440" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010441
Bram Moolenaara6878372014-03-22 21:02:50 +010010442 " report on missing file or directory messages
10443 if search('[Nn]o such file or directory\|Failed to change directory')
10444 let mesg= getline(".")
10445 if exists("w:netrw_bannercnt")
10446 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010447 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010448 setl noma
10449 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010450 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010451 call netrw#ErrorMsg(s:WARNING,mesg,96)
10452" call Dret("s:NetrwRemoteListing : -1")
10453 return -1
10454 endif
10455
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010456 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 +000010457 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010458" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010459 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010460
10461 " cleanup
10462 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010463 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10464 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010465 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010466 sil! NetrwKeepj %s/\r$//e
10467 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010468
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010469 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010470 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010471 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010472 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010473" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010474 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010475" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010476 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010477 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010478 exe "sil! NetrwKeepj ".line1
10479 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010480
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010481" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010482 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010483" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010484 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10485 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010486 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010487" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010488 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10489 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10490 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10491 NetrwKeepj call histdel("/",-1)
10492 NetrwKeepj call histdel("/",-1)
10493 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010494 endif
10495 endif
10496
Bram Moolenaar13600302014-05-22 18:26:40 +020010497 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010498 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010499" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010500 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010501" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010502 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010503" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10504 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010505 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010506 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10507 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10508 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10509 NetrwKeepj call histdel("/",-1)
10510 NetrwKeepj call histdel("/",-1)
10511 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010512 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010513 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10514 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010515 endif
10516 else
10517 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010518" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010519 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010520 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010521" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10522 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10523" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010524 endif
10525 endif
10526
10527 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010528 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010529" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010530 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10531 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010532 endif
10533 endif
10534
10535 if w:netrw_liststyle == s:LONGLIST
10536 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010537" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010538
10539 if s:method == "ftp"
10540 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010541 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010542 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010543 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010544 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010545 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010546 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010547 sil! NetrwKeepj 1
10548 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010549 let line2= line(".")
10550 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010551 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010552 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010553 endif
10554 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010555 exe "sil! NetrwKeepj ".line1
10556 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010557 endif
10558
10559 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010560" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010561 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 +000010562 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010563" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010564 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010565 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010566 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10567 NetrwKeepj call histdel("/",-1)
10568 NetrwKeepj call histdel("/",-1)
10569 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570 endif
10571 endif
10572
10573" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010574" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010576
10577" call Dret("s:NetrwRemoteListing 0")
10578 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010579endfun
10580
Bram Moolenaar446cb832008-06-24 21:56:24 +000010581" ---------------------------------------------------------------------
10582" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10583fun! s:NetrwRemoteRm(usrhost,path) range
10584" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010585" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010586 let svpos= winsaveview()
10587" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010588
10589 let all= 0
10590 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10591 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010592" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010593 for fname in s:netrwmarkfilelist_{bufnr("%")}
10594 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010595 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010597 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010598 let all= 1
10599 endif
10600 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010601 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010602
10603 else
10604 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010605" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010606
10607 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010608 let keepsol = &l:sol
10609 setl nosol
10610 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010611
10612 " remove multiple files and directories
10613 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010614 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010615 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010616 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010617 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010618 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010619 let all= 1
10620 endif
10621 let ctr= ctr + 1
10622 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010623 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010624 endif
10625
10626 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010627" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010628 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010629" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10630 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010631
10632" call Dret("s:NetrwRemoteRm")
10633endfun
10634
10635" ---------------------------------------------------------------------
10636" s:NetrwRemoteRmFile: {{{2
10637fun! s:NetrwRemoteRmFile(path,rmfile,all)
10638" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10639
10640 let all= a:all
10641 let ok = ""
10642
10643 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10644 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010645" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010646 if !all
10647 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010648" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010649 call inputsave()
10650 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10651 call inputrestore()
10652 echohl NONE
10653 if ok == ""
10654 let ok="no"
10655 endif
10656 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010657 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010658 let all= 1
10659 endif
10660 endif
10661
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010662 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010663" 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 +000010664 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010665" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010666 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010667 if path =~ '^\a\{3,}://'
10668 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010669 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010670 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010671 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10672 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010673" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010674 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010675" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010676 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010677 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010678 let ok="q"
10679 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010680 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010681" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10682" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10683" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010684 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010685 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010686 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010687 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010688 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010689" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010690 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010691 if v:shell_error != 0
10692 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010693 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 +010010694 else
10695 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10696 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010697 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010698 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010699 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010700" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010701 endif
10702 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010703 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010704" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010705 endif
10706
10707 else
10708 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010709" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010710 if !all
10711 call inputsave()
10712 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10713 call inputrestore()
10714 if ok == ""
10715 let ok="no"
10716 endif
10717 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010718 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010719 let all= 1
10720 endif
10721 endif
10722
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010723 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010724 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010725 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010726 else
10727 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010728 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10729" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010730 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010731" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010732
10733 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010734" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10735 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10736" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010737 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010738" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010739
10740 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010741 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010742 endif
10743 endif
10744 endif
10745
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010746 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010747" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010748 endif
10749 endif
10750
10751" call Dret("s:NetrwRemoteRmFile ".ok)
10752 return ok
10753endfun
10754
10755" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010756" s:NetrwRemoteRename: rename a remote file or directory {{{2
10757fun! s:NetrwRemoteRename(usrhost,path) range
10758" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10759
10760 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010761 let svpos = winsaveview()
10762" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010763 let ctr = a:firstline
10764 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10765
10766 " rename files given by the markfilelist
10767 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10768 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010769" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010770 if exists("subfrom")
10771 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010772" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010773 else
10774 call inputsave()
10775 let newname= input("Moving ".oldname." to : ",oldname)
10776 call inputrestore()
10777 if newname =~ '^s/'
10778 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10779 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10780 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010781" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010782 endif
10783 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010784
Bram Moolenaar446cb832008-06-24 21:56:24 +000010785 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010786 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010787 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010788 let oldname= s:ShellEscape(a:path.oldname)
10789 let newname= s:ShellEscape(a:path.newname)
10790" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010791 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010792 endif
10793
10794 endfor
10795 call s:NetrwUnMarkFile(1)
10796
10797 else
10798
10799 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010800 let keepsol= &l:sol
10801 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010802 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010803 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010804
10805 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010806" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010807
10808 call inputsave()
10809 let newname= input("Moving ".oldname." to : ",oldname)
10810 call inputrestore()
10811
10812 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10813 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10814 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010815 let oldname= s:ShellEscape(a:path.oldname)
10816 let newname= s:ShellEscape(a:path.newname)
10817" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010818 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010819 endif
10820
10821 let ctr= ctr + 1
10822 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010823 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010824 endif
10825
10826 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010827 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010828" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10829 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010830
10831" call Dret("NetrwRemoteRename")
10832endfun
10833
Bram Moolenaar85850f32019-07-19 22:05:51 +020010834" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010835" Local Directory Browsing Support: {{{1
10836" ==========================================
10837
10838" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010839" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010840" Should accept: file://localhost/etc/fstab
10841" file:///etc/fstab
10842" file:///c:/WINDOWS/clock.avi
10843" file:///c|/WINDOWS/clock.avi
10844" file://localhost/c:/WINDOWS/clock.avi
10845" file://localhost/c|/WINDOWS/clock.avi
10846" file://c:/foo.txt
10847" file:///c:/foo.txt
10848" 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 +020010849fun! netrw#FileUrlEdit(fname)
10850" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010851 let fname = a:fname
10852 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010853" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010854 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010855" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010856 endif
10857 if (has("win32") || has("win95") || has("win64") || has("win16"))
10858 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010859" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010860 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010861" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010862 endif
10863 endif
10864 let fname2396 = netrw#RFC2396(fname)
10865 let fname2396e= fnameescape(fname2396)
10866 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10867 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010868" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010869 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010870" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010871 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10872 endif
10873 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010874
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010875" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10876" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010877 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010878 exe 'NetrwKeepj keepalt edit '.plainfname
10879 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10880
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010881" 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 +020010882" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010883 exe "sil doau BufReadPost ".fname2396e
10884endfun
10885
10886" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010887" netrw#LocalBrowseCheck: {{{2
10888fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010889 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010890 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10891 "
10892 " unfortunate interaction -- split window debugging can't be used here, must use
10893 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10894 " another call to LocalBrowseCheck() when attempts to write
10895 " to the DBG buffer are made.
10896 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010897 " The &ft == "netrw" test was installed because the BufEnter event
10898 " would hit when re-entering netrw windows, creating unexpected
10899 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010900" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010901" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010902" 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 +010010903 " getting E930: Cannot use :redir inside execute
10904"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010905" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10906" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010907
Bram Moolenaar97d62492012-11-15 21:28:22 +010010908 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010909 if isdirectory(s:NetrwFile(a:dirname))
10910" 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 +010010911
Bram Moolenaar97d62492012-11-15 21:28:22 +010010912 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010913" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10914" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010915 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010916
Bram Moolenaar446cb832008-06-24 21:56:24 +000010917 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010918" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010919 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010920
Bram Moolenaar5c736222010-01-06 20:54:52 +010010921 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010922" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010923 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010924 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010925 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010926" 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 +010010927" call Dret("netrw#LocalBrowseCheck")
10928 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010929 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010930
Bram Moolenaar85850f32019-07-19 22:05:51 +020010931 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010932 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10933 " AND IF the listing style is not a tree listing
10934 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010935" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010936 let ibuf = 1
10937 let buflast = bufnr("$")
10938 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010939 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10940 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010941 endif
10942 let ibuf= ibuf + 1
10943 endwhile
10944 endif
10945 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010946" 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>"))
10947" 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 +000010948 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010949" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010950endfun
10951
10952" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010953" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010954" performed any shell command. The idea is to cause all local-browsing
10955" buffers to be refreshed after a user has executed some shell command,
10956" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010957fun! s:LocalBrowseRefresh()
10958" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010959" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10960" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010961
Bram Moolenaar446cb832008-06-24 21:56:24 +000010962 " determine which buffers currently reside in a tab
10963 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010964" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 return
10966 endif
10967 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010968" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010969 return
10970 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010971 if !empty(getcmdwintype())
10972 " cannot move away from cmdline window, see :h E11
10973 return
10974 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010975 if exists("s:netrw_events") && s:netrw_events == 1
10976 " s:LocalFastBrowser gets called (indirectly) from a
10977 let s:netrw_events= 2
10978" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10979 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010980 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010981 let itab = 1
10982 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010983 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010984 while itab <= tabpagenr("$")
10985 let buftablist = buftablist + tabpagebuflist()
10986 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010987 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010988 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010989" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10990" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010991 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10992 " | refresh any netrw window
10993 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010994 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010995 let ibl = 0
10996 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010997" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010998 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10999 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020011000 " (ibuf not shown in a current window AND
11001 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011002" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
11003 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011004 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011005" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011006 continue
11007 elseif index(tabpagebuflist(),ibuf) != -1
11008 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011009" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011010 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011011 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010011012 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
11013 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
11014 let g:netrw_quickhelp= g:netrw_quickhelp - 1
11015 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011016" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011017 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
11018 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11019 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011020 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011021 endif
11022 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011023" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011024 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011025" call Decho("restore window: win_gotoid(".curwinid.")")
11026 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011027 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011028
Bram Moolenaara6878372014-03-22 21:02:50 +010011029" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011030endfun
11031
11032" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011033" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11034"
11035" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011036" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011037" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11038" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011039" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011040"
11041" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11042" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011043" (re-using a buffer may not be as accurate)
11044"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011045" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011046" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11047" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11048" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11049" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011050fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011051" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11052" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11053" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11054" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011055
11056 " initialize browselist, a list of buffer numbers that the local browser has used
11057 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011058" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011059 let s:netrw_browselist= []
11060 endif
11061
11062 " append current buffer to fastbrowse list
11063 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011064" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011065 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011066" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011067 endif
11068
11069 " enable autocmd events to handle refreshing/removing local browser buffers
11070 " If local browse buffer is currently showing: refresh it
11071 " If local browse buffer is currently hidden : wipe it
11072 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11073 " =1 : medium speed, re-use directory listing for remote only
11074 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011075 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11076 let s:netrw_events= 1
11077 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011078 au!
11079 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011080" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011081 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011082 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011083" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011084 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011085 endif
11086 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011087
11088 " user must have changed fastbrowse to its fast setting, so remove
11089 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011090 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011091" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011092 unlet s:netrw_events
11093 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011094 au!
11095 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011096 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011097 endif
11098
Bram Moolenaar85850f32019-07-19 22:05:51 +020011099" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011100endfun
11101
11102" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011103" s:LocalListing: does the job of "ls" for local directories {{{2
11104fun! s:LocalListing()
11105" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011106" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11107" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11108" 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 +010011109
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011110" 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
11111" 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
11112" 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 +010011113
11114 " get the list of files contained in the current directory
11115 let dirname = b:netrw_curdir
11116 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011117 let filelist = s:NetrwGlob(dirname,"*",0)
11118 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011119" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011120
11121 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011122" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011123 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11124 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011125" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011126 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011127" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011128 endif
11129
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011130" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011131" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011132" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011133
11134 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11135 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11136 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011137" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11138" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011139 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" 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 +010011141
11142 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011143" call Decho(" ",'~'.expand("<slnum>"))
11144" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011145
11146 if getftype(filename) == "link"
11147 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011148" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011149 let pfile= filename."@"
11150
11151 elseif getftype(filename) == "socket"
11152 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011153" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011154 let pfile= filename."="
11155
11156 elseif getftype(filename) == "fifo"
11157 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011158" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011159 let pfile= filename."|"
11160
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011161 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011162 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011163" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011164 let pfile= filename."/"
11165
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011166 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011167 if (has("win32") || has("win95") || has("win64") || has("win16"))
11168 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11169 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011170" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011171 let pfile= filename."*"
11172 else
11173 " normal file
11174 let pfile= filename
11175 endif
11176 elseif executable(filename)
11177 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011178" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011179 let pfile= filename."*"
11180 else
11181 " normal file
11182 let pfile= filename
11183 endif
11184
11185 else
11186 " normal file
11187 let pfile= filename
11188 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011189" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011190
11191 if pfile =~ '//$'
11192 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011193" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011194 endif
11195 let pfile= strpart(pfile,dirnamelen)
11196 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011197" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11198" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011199
11200 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011201 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11202 let sz = getfsize(filename)
11203 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11204 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011205
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011206 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011207 let sz= s:NetrwHumanReadable(sz)
11208 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011209 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011210 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011211" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011212 endif
11213
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011214 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011215 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011216 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011217" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011218" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011219 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011220 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011221" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011222 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011223 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011224
11225 elseif g:netrw_sort_by =~ "^s"
11226 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011227" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011228" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011229 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011230 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011231" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011232 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011233 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011234
11235 else
11236 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011237" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011238" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011239 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011240 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011241" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011242 endfor
11243
11244 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011245 sil! NetrwKeepj g/^$/d
11246 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011247 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011248" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011249 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11250
11251" call Dret("s:LocalListing")
11252endfun
11253
11254" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011255" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11256fun! s:NetrwLocalExecute(cmd)
11257" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11258 let ykeep= @@
11259 " sanity check
11260 if !executable(a:cmd)
11261 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11262 let @@= ykeep
11263" call Dret("s:NetrwLocalExecute")
11264 return
11265 endif
11266
11267 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011268" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011269 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011270" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011271
11272 " strip any ansi escape sequences off
11273 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11274
11275 " show user the result(s)
11276 echomsg result
11277 let @@= ykeep
11278
11279" call Dret("s:NetrwLocalExecute")
11280endfun
11281
11282" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011283" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011284fun! s:NetrwLocalRename(path) range
11285" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11286
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011287 if !exists("w:netrw_bannercnt")
11288 let w:netrw_bannercnt= b:netrw_bannercnt
11289 endif
11290
Bram Moolenaar97d62492012-11-15 21:28:22 +010011291 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011292 let ykeep = @@
11293 let ctr = a:firstline
11294 let svpos = winsaveview()
11295 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011296" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011297
11298 " rename files given by the markfilelist
11299 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11300 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011301" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011302 if exists("subfrom")
11303 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011304" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011305 else
11306 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011307 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011308 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011309 if newname =~ ''
11310 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11311 let newname = substitute(newname,'^.*','','')
11312 elseif newname =~ ''
11313 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11314 let newname = substitute(newname,'[^/]*','','')
11315 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011316 if newname =~ '^s/'
11317 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11318 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011319" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011320 let newname = substitute(oldname,subfrom,subto,'')
11321 endif
11322 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011323 if !all && filereadable(newname)
11324 call inputsave()
11325 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11326 call inputrestore()
11327 if response == "all"
11328 let all= 1
11329 elseif response != "y" && response != "yes"
11330 " refresh the directory
11331" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11332 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11333" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11334 NetrwKeepj call winrestview(svpos)
11335 let @@= ykeep
11336" call Dret("NetrwLocalRename")
11337 return
11338 endif
11339 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011340 call rename(oldname,newname)
11341 endfor
11342 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011343
Bram Moolenaar97d62492012-11-15 21:28:22 +010011344 else
11345
11346 " attempt to rename files/directories
11347 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011348 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011349
11350 " sanity checks
11351 if line(".") < w:netrw_bannercnt
11352 let ctr= ctr + 1
11353 continue
11354 endif
11355 let curword= s:NetrwGetWord()
11356 if curword == "./" || curword == "../"
11357 let ctr= ctr + 1
11358 continue
11359 endif
11360
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011361 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011362 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011363" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011364
11365 call inputsave()
11366 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11367 call inputrestore()
11368
11369 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011370" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011371
11372 let ctr= ctr + 1
11373 endwhile
11374 endif
11375
11376 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011377" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011378 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011379" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11380 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011381 let @@= ykeep
11382
11383" call Dret("NetrwLocalRename")
11384endfun
11385
11386" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011387" s:NetrwLocalRm: {{{2
11388fun! s:NetrwLocalRm(path) range
11389" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011390" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011391
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011392 if !exists("w:netrw_bannercnt")
11393 let w:netrw_bannercnt= b:netrw_bannercnt
11394 endif
11395
Bram Moolenaar446cb832008-06-24 21:56:24 +000011396 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011397 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011398 let ret = 0
11399 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011400 let svpos = winsaveview()
11401" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011402
11403 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11404 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011405" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011406 for fname in s:netrwmarkfilelist_{bufnr("%")}
11407 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011408 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011409 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011410 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011411 let all= 1
11412 endif
11413 endfor
11414 call s:NetrwUnMarkFile(1)
11415
11416 else
11417 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011418" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011419
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011420 let keepsol= &l:sol
11421 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011422 let ctr = a:firstline
11423 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011424 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011425
11426 " sanity checks
11427 if line(".") < w:netrw_bannercnt
11428 let ctr= ctr + 1
11429 continue
11430 endif
11431 let curword= s:NetrwGetWord()
11432 if curword == "./" || curword == "../"
11433 let ctr= ctr + 1
11434 continue
11435 endif
11436 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011437 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011438 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011439 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011440 let all= 1
11441 endif
11442 let ctr= ctr + 1
11443 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011444 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011445 endif
11446
11447 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011448" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011449 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011450 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011451" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11452 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011453 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011454 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011455
11456" call Dret("s:NetrwLocalRm")
11457endfun
11458
11459" ---------------------------------------------------------------------
11460" s:NetrwLocalRmFile: remove file fname given the path {{{2
11461" Give confirmation prompt unless all==1
11462fun! s:NetrwLocalRmFile(path,fname,all)
11463" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011464
Bram Moolenaar446cb832008-06-24 21:56:24 +000011465 let all= a:all
11466 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011467 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011468 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11469" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011470
11471 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11472 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011473" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011474 if !all
11475 echohl Statement
11476 call inputsave()
11477 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11478 call inputrestore()
11479 echohl NONE
11480 if ok == ""
11481 let ok="no"
11482 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011483" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011484 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011485" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011486 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011487 let all= 1
11488 endif
11489 endif
11490
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011491 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011492 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011493" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011494 endif
11495
11496 else
11497 " attempt to remove directory
11498 if !all
11499 echohl Statement
11500 call inputsave()
11501 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11502 call inputrestore()
11503 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11504 if ok == ""
11505 let ok="no"
11506 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011507 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011508 let all= 1
11509 endif
11510 endif
11511 let rmfile= substitute(rmfile,'[\/]$','','e')
11512
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011513 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar71badf92023-04-22 22:40:14 +010011514 if delete(rmfile,"d")
11515 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011516 endif
11517 endif
11518 endif
11519
11520" call Dret("s:NetrwLocalRmFile ".ok)
11521 return ok
11522endfun
11523
Bram Moolenaar85850f32019-07-19 22:05:51 +020011524" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011525" Support Functions: {{{1
11526
Bram Moolenaar488c6512005-08-11 20:09:58 +000011527" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011528" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11529" 0: marked file list of current buffer
11530" 1: marked file target
11531fun! netrw#Access(ilist)
11532 if a:ilist == 0
11533 if exists("s:netrwmarkfilelist_".bufnr('%'))
11534 return s:netrwmarkfilelist_{bufnr('%')}
11535 else
11536 return "no-list-buf#".bufnr('%')
11537 endif
11538 elseif a:ilist == 1
11539 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011540 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011541endfun
11542
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011543" ---------------------------------------------------------------------
11544" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11545fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011546 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011547endfun
11548
Bram Moolenaara6878372014-03-22 21:02:50 +010011549" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011550" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11551" I expect this function to be used in
11552" :PChkAssert netrw#Expose("netrwmarkfilelist")
11553" for example.
11554fun! netrw#Expose(varname)
11555" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011556 if exists("s:".a:varname)
11557 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011558" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011559 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011560" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011561 if type(retval) == 3
11562 let retval = copy(retval)
11563 let i = 0
11564 while i < len(retval)
11565 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11566 let i = i + 1
11567 endwhile
11568 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011569" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011570 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011571 else
11572" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011573 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011574 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011575" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011576 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011577 endif
11578
11579" call Dret("netrw#Expose ".string(retval))
11580 return retval
11581endfun
11582
11583" ---------------------------------------------------------------------
11584" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11585fun! netrw#Modify(varname,newvalue)
11586" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11587 exe "let s:".a:varname."= ".string(a:newvalue)
11588" call Dret("netrw#Modify")
11589endfun
11590
11591" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011592" netrw#RFC2396: converts %xx into characters {{{2
11593fun! netrw#RFC2396(fname)
11594" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011595 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011596" call Dret("netrw#RFC2396 ".fname)
11597 return fname
11598endfun
11599
11600" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011601" netrw#UserMaps: supports user-specified maps {{{2
11602" see :help function()
11603"
11604" g:Netrw_UserMaps is a List with members such as:
11605" [[keymap sequence, function reference],...]
11606"
11607" The referenced function may return a string,
11608" refresh : refresh the display
11609" -other- : this string will be executed
11610" or it may return a List of strings.
11611"
11612" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011613" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011614" Related functions:
11615" netrw#Expose(varname) -- see s:varname variables
11616" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11617" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11618fun! netrw#UserMaps(islocal)
11619" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11620" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11621
11622 " set up usermaplist
11623 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11624" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11625 for umap in g:Netrw_UserMaps
11626" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11627" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11628 " if umap[0] is a string and umap[1] is a string holding a function name
11629 if type(umap[0]) == 1 && type(umap[1]) == 1
11630" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11631 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11632 else
11633 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11634 endif
11635 endfor
11636 endif
11637" call Dret("netrw#UserMaps")
11638endfun
11639
11640" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011641" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11642fun! netrw#WinPath(path)
11643" call Dfunc("netrw#WinPath(path<".a:path.">)")
11644 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11645 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011646 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011647 " remove trailing slash (Win95)
11648 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11649 " remove escaped spaces
11650 let path = substitute(path, '\ ', ' ', 'g')
11651 " convert slashes to backslashes
11652 let path = substitute(path, '/', '\', 'g')
11653 else
11654 let path= a:path
11655 endif
11656" call Dret("netrw#WinPath <".path.">")
11657 return path
11658endfun
11659
11660" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011661" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11662" cb : bl2mf=0 add marked files to buffer list
11663" cB : bl2mf=1 use bufferlist to mark files
11664" (mnemonic: cb = copy (marked files) to buffer list)
11665fun! s:NetrwBadd(islocal,bl2mf)
11666" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11667 if a:bl2mf
11668 " cB: add buffer list to marked files
11669 redir => bufl
11670 ls
11671 redir END
11672 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11673 for fname in bufl
11674 call s:NetrwMarkFile(a:islocal,fname)
11675 endfor
11676 else
11677 " cb: add marked files to buffer list
11678 for fname in s:netrwmarkfilelist_{bufnr("%")}
11679" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11680 exe "badd ".fnameescape(fname)
11681 endfor
11682 let curbufnr = bufnr("%")
11683 let curdir = s:NetrwGetCurdir(a:islocal)
11684 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11685 endif
11686" call Dret("s:NetrwBadd")
11687endfun
11688
11689" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011690" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11691fun! s:ComposePath(base,subdir)
11692" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11693
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011694 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011695" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011696 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011697 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011698 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011699 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011700 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011701 endif
11702
Bram Moolenaar85850f32019-07-19 22:05:51 +020011703 " COMBAK: test on windows with changing to root directory: :e C:/
11704 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011705" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011706 let ret= a:subdir
11707
Bram Moolenaar85850f32019-07-19 22:05:51 +020011708 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011709" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011710 if a:base =~ '[/\\]$'
11711 let ret= a:base.a:subdir
11712 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011713 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011714 endif
11715
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011716 elseif a:base =~ '^\a\{3,}://'
11717" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011718 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11719 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11720 if a:subdir == '../'
11721 if curpath =~ '[^/]/[^/]\+/$'
11722 let curpath= substitute(curpath,'[^/]\+/$','','')
11723 else
11724 let curpath=""
11725 endif
11726 let ret= urlbase.curpath
11727 else
11728 let ret= urlbase.curpath.a:subdir
11729 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011730" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11731" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11732" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011733
11734 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011735" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011736 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11737 if a:base =~ '^//'
11738 " keeping initial '//' for the benefit of network share listing support
11739 let ret= '/'.ret
11740 endif
11741 let ret= simplify(ret)
11742 endif
11743
11744" call Dret("s:ComposePath ".ret)
11745 return ret
11746endfun
11747
11748" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011749" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11750" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11751fun! s:DeleteBookmark(fname)
11752" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11753 call s:MergeBookmarks()
11754
11755 if exists("g:netrw_bookmarklist")
11756 let indx= index(g:netrw_bookmarklist,a:fname)
11757 if indx == -1
11758 let indx= 0
11759 while indx < len(g:netrw_bookmarklist)
11760 if g:netrw_bookmarklist[indx] =~ a:fname
11761 call remove(g:netrw_bookmarklist,indx)
11762 let indx= indx - 1
11763 endif
11764 let indx= indx + 1
11765 endwhile
11766 else
11767 " remove exact match
11768 call remove(g:netrw_bookmarklist,indx)
11769 endif
11770 endif
11771
11772" call Dret("s:DeleteBookmark")
11773endfun
11774
11775" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011776" s:FileReadable: o/s independent filereadable {{{2
11777fun! s:FileReadable(fname)
11778" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11779
11780 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011781 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011782 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011783 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011784 endif
11785
11786" call Dret("s:FileReadable ".ret)
11787 return ret
11788endfun
11789
11790" ---------------------------------------------------------------------
11791" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11792" Places correct suffix on end of temporary filename,
11793" using the suffix provided with fname
11794fun! s:GetTempfile(fname)
11795" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11796
11797 if !exists("b:netrw_tmpfile")
11798 " get a brand new temporary filename
11799 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011800" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011801
Bram Moolenaarc236c162008-07-13 17:41:49 +000011802 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011803" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011804
Bram Moolenaar9964e462007-05-05 17:54:07 +000011805 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011806 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11807" 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 +010011808 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011809" call Dret("s:GetTempfile getcwd<".getcwd().">")
11810 return ""
11811 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011812
Bram Moolenaar9964e462007-05-05 17:54:07 +000011813 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011814 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011815" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011816
Bram Moolenaar9964e462007-05-05 17:54:07 +000011817 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011818 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011819 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011820 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011821 if !exists("+shellslash") || !&ssl
11822 let tmpfile = substitute(tmpfile,'/','\','g')
11823 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011824 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011825 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011826 endif
11827 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011828" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011829 else
11830 " re-use temporary filename
11831 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011832" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011833 endif
11834
11835 " use fname's suffix for the temporary file
11836 if a:fname != ""
11837 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011838" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011839 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011840 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011841 elseif a:fname =~ '.txz$'
11842 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011843 else
11844 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11845 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011846" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011847 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011848" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011849 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011850" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011851 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11852 endif
11853 endif
11854
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011855" 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 +000011856" call Dret("s:GetTempfile <".tmpfile.">")
11857 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011858endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011859
11860" ---------------------------------------------------------------------
11861" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011862" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011863fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011864" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011865 if s:user == ""
11866 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11867 else
11868 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11869 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011870 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011871 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011872 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011873 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011874 else
11875 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11876 endif
11877" call Dret("s:MakeSshCmd <".sshcmd.">")
11878 return sshcmd
11879endfun
11880
11881" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011882" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11883fun! s:MakeBookmark(fname)
11884" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11885
11886 if !exists("g:netrw_bookmarklist")
11887 let g:netrw_bookmarklist= []
11888 endif
11889
11890 if index(g:netrw_bookmarklist,a:fname) == -1
11891 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011892 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011893 call add(g:netrw_bookmarklist,a:fname.'/')
11894 elseif a:fname !~ '/'
11895 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11896 else
11897 call add(g:netrw_bookmarklist,a:fname)
11898 endif
11899 call sort(g:netrw_bookmarklist)
11900 endif
11901
11902" call Dret("s:MakeBookmark")
11903endfun
11904
11905" ---------------------------------------------------------------------
11906" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11907fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011908" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011909 " get bookmarks from .netrwbook file
11910 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011911 if filereadable(s:NetrwFile(savefile))
11912" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011913 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011914" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011915 NetrwKeepj call delete(savefile)
11916 endif
11917" call Dret("s:MergeBookmarks")
11918endfun
11919
11920" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011921" s:NetrwBMShow: {{{2
11922fun! s:NetrwBMShow()
11923" call Dfunc("s:NetrwBMShow()")
11924 redir => bmshowraw
11925 menu
11926 redir END
11927 let bmshowlist = split(bmshowraw,'\n')
11928 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011929 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011930 if bmshowfuncs != []
11931 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011932 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011933 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011934 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011935 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011936 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011937" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11938endfun
11939
11940" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011941" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011942fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011943 if !exists("w:netrw_liststyle")
11944 let w:netrw_liststyle= g:netrw_liststyle
11945 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011946" 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 +020011947
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011948" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11949
Bram Moolenaaradc21822011-04-01 18:03:16 +020011950 if &ft != "netrw"
11951 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11952 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011953" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011954
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011955 elseif g:netrw_cursor == 8
11956 if w:netrw_liststyle == s:WIDELIST
11957 setl cursorline
11958 setl cursorcolumn
11959 else
11960 setl cursorline
11961 endif
11962 elseif g:netrw_cursor == 7
11963 setl cursorline
11964 elseif g:netrw_cursor == 6
11965 if w:netrw_liststyle == s:WIDELIST
11966 setl cursorline
11967 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011968 elseif g:netrw_cursor == 4
11969 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011970" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011971 setl cursorline
11972 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011973
11974 elseif g:netrw_cursor == 3
11975 " thin-long-tree: cursorline, user's cursorcolumn
11976 " wide : cursorline, cursorcolumn
11977 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011978" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011979 setl cursorline
11980 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011981 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011982" 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 +020011983 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011984 endif
11985
11986 elseif g:netrw_cursor == 2
11987 " thin-long-tree: cursorline, user's cursorcolumn
11988 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011989" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011990 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011991
11992 elseif g:netrw_cursor == 1
11993 " thin-long-tree: user's cursorline, user's cursorcolumn
11994 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011995 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011996" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011997 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011998 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011999" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012000 endif
12001
12002 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020012003 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012004" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012005 let &l:cursorline = s:netrw_usercul
12006 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012007 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020012008
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012009" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020012010" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012011endfun
12012
12013" ---------------------------------------------------------------------
12014" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
12015fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012016" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012017 if exists("s:netrw_usercul")
12018 let &l:cursorline = s:netrw_usercul
12019 endif
12020 if exists("s:netrw_usercuc")
12021 let &l:cursorcolumn = s:netrw_usercuc
12022 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012023" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012024" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12025endfun
12026
12027" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012028" s:NetrwDelete: Deletes a file. {{{2
12029" Uses Steve Hall's idea to insure that Windows paths stay
12030" acceptable. No effect on Unix paths.
12031" Examples of use: let result= s:NetrwDelete(path)
12032fun! s:NetrwDelete(path)
12033" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12034
Bram Moolenaar5c736222010-01-06 20:54:52 +010012035 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012036 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
12037 if exists("+shellslash")
12038 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012039 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012040 let result = delete(path)
12041 let &shellslash = sskeep
12042 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012043" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012044 let result= delete(path)
12045 endif
12046 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012047" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012048 let result= delete(path)
12049 endif
12050 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012051 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012052 endif
12053
12054" call Dret("s:NetrwDelete ".result)
12055 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012056endfun
12057
12058" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012059" s:NetrwBufRemover: removes a buffer that: {{{2s
12060" has buffer-id > 1
12061" is unlisted
12062" is unnamed
12063" does not appear in any window
12064fun! s:NetrwBufRemover(bufid)
12065" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12066" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12067" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12068" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12069" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12070
yasuda4dbb2662023-10-04 20:50:35 +020012071 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012072" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012073 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012074 endif
12075
12076" call Dret("s:NetrwBufRemover")
12077endfun
12078
12079" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012080" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012081fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012082" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012083" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012084
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012085 " Clean out the last buffer:
12086 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12087 " If so, delete it.
12088 call s:NetrwBufRemover(bufnr("$"))
12089
Bram Moolenaar446cb832008-06-24 21:56:24 +000012090 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012091" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012092 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12093 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12094 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12095 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12096 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12097 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12098 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12099 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12100 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12101 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12102 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12103 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12104 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12105 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12106 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12107 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12108
Bram Moolenaar85850f32019-07-19 22:05:51 +020012109 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012110" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012111 " when tree listing uses file TreeListing... a new buffer is made.
12112 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012113 " COMBAK: this causes a problem, see P43
12114" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012115 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012116 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012117 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012118" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012119 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012120
Bram Moolenaar446cb832008-06-24 21:56:24 +000012121 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012122" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012123 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12124 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12125 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12126 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12127 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12128 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12129 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12130 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12131 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12132 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12133 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12134 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12135 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12136 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12137 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12138 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12139
Bram Moolenaar5c736222010-01-06 20:54:52 +010012140 if a:0 > 0
12141 let b:netrw_curdir= a:1
12142 if b:netrw_curdir =~ '/$'
12143 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012144 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012145 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012146 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012147 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12148 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012149 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012150 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012151 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012152 endif
12153 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012154 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12155 let &l:bexpr = "netrw#BalloonHelp()"
12156 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012157
Bram Moolenaar8d043172014-01-23 14:24:41 +010012158" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012159endfun
12160
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012161" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012162" s:NetrwExe: executes a string using "!" {{{2
12163fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012164" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012165 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012166" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012167 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12168 set shell& shellcmdflag& shellxquote& shellxescape&
12169 set shellquote& shellpipe& shellredir& shellslash&
12170 exe a:cmd
12171 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12172 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012173" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012174 exe a:cmd
12175 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012176 if v:shell_error
12177 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12178 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012179" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012180endfun
12181
12182" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012183" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12184fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012185 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012186" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012187 let curbuf = bufnr("%")
12188 let curwin = winnr()
12189 let iwin = 1
12190 while iwin <= winnr("$")
12191 exe iwin."wincmd w"
12192 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12193 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12194 let winvars= w:
12195 break
12196 endif
12197 let iwin= iwin + 1
12198 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012199 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012200 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012201" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012202 for k in keys(winvars)
12203 let w:{k}= winvars[k]
12204 endfor
12205 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012206" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012207 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012208endfun
12209
Bram Moolenaara6878372014-03-22 21:02:50 +010012210" ---------------------------------------------------------------------
12211" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012212" Returns: 0=success
12213" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012214fun! s:NetrwLcd(newdir)
12215" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012216" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012217
Bram Moolenaar85850f32019-07-19 22:05:51 +020012218 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012219 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012220 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012221 catch /^Vim\%((\a\+)\)\=:E344/
12222 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12223 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012224 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012225 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12226 " forward slashes by earlier code; so check for both.
12227 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
12228 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12229 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012230 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012231 endif
12232 endif
12233 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012234 let err472= 1
12235 endtry
12236
12237 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012238 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12239 if exists("w:netrw_prvdir")
12240 let a:newdir= w:netrw_prvdir
12241 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012242 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012243" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012244 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012245" 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 +010012246 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012247 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012248" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12249 return -1
12250 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012251
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012252" call Decho("getcwd <".getcwd().">")
12253" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012254" call Dret("s:NetrwLcd 0")
12255 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012256endfun
12257
Bram Moolenaar9964e462007-05-05 17:54:07 +000012258" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012259" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12260" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12261fun! s:NetrwSaveWordPosn()
12262" call Dfunc("NetrwSaveWordPosn()")
12263 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12264" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12265endfun
12266
12267" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012268" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12269" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12270fun! s:NetrwHumanReadable(sz)
12271" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12272
12273 if g:netrw_sizestyle == 'h'
12274 if a:sz >= 1000000000
12275 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12276 elseif a:sz >= 10000000
12277 let sz = printf("%d",a:sz/1000000)."m"
12278 elseif a:sz >= 1000000
12279 let sz = printf("%.1f",a:sz/1000000.0)."m"
12280 elseif a:sz >= 10000
12281 let sz = printf("%d",a:sz/1000)."k"
12282 elseif a:sz >= 1000
12283 let sz = printf("%.1f",a:sz/1000.0)."k"
12284 else
12285 let sz= a:sz
12286 endif
12287
12288 elseif g:netrw_sizestyle == 'H'
12289 if a:sz >= 1073741824
12290 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12291 elseif a:sz >= 10485760
12292 let sz = printf("%d",a:sz/1048576)."M"
12293 elseif a:sz >= 1048576
12294 let sz = printf("%.1f",a:sz/1048576.0)."M"
12295 elseif a:sz >= 10240
12296 let sz = printf("%d",a:sz/1024)."K"
12297 elseif a:sz >= 1024
12298 let sz = printf("%.1f",a:sz/1024.0)."K"
12299 else
12300 let sz= a:sz
12301 endif
12302
12303 else
12304 let sz= a:sz
12305 endif
12306
12307" call Dret("s:NetrwHumanReadable ".sz)
12308 return sz
12309endfun
12310
12311" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012312" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12313" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12314fun! s:NetrwRestoreWordPosn()
12315" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012316 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012317" call Dret("NetrwRestoreWordPosn")
12318endfun
12319
12320" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012321" s:RestoreBufVars: {{{2
12322fun! s:RestoreBufVars()
12323" call Dfunc("s:RestoreBufVars()")
12324
12325 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12326 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12327 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12328 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12329 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12330 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12331
12332" call Dret("s:RestoreBufVars")
12333endfun
12334
12335" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012336" s:RemotePathAnalysis: {{{2
12337fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012338" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012339
Bram Moolenaara6878372014-03-22 21:02:50 +010012340 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012341 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012342 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012343 let s:user = substitute(a:dirname,dirpat,'\3','')
12344 let s:machine = substitute(a:dirname,dirpat,'\4','')
12345 let s:port = substitute(a:dirname,dirpat,'\5','')
12346 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012347 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012348 if s:machine =~ '@'
12349 let dirpat = '^\(.*\)@\(.\{-}\)$'
12350 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12351 let s:machine = substitute(s:machine,dirpat,'\2','')
12352 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012353
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012354" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12355" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12356" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12357" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12358" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12359" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012360
12361" call Dret("s:RemotePathAnalysis")
12362endfun
12363
12364" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012365" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12366" Returns status
12367" Runs system() on
12368" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012369" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012370fun! s:RemoteSystem(cmd)
12371" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12372 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012373 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 +000012374 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012375 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012376 else
12377 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12378 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12379 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012380 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012381 else
12382 let cmd= cmd.' '
12383 endif
12384 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012385" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012386 let ret= system(cmd)
12387 endif
12388" call Dret("s:RemoteSystem ".ret)
12389 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012390endfun
12391
12392" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012393" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012394fun! s:RestoreWinVars()
12395" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012396 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012397 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12398 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12399 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12400 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12401 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12402 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12403 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12404 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12405 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12406 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12407 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12408 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012409 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12410 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012411 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12412 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12413 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12414" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012415endfun
12416
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012417" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012418" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12419"
12420" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12421" is true) and a command, :Rexplore, which call this function.
12422"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012423" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012424"
12425" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012426fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012427 if exists("s:netrwdrag")
12428 return
12429 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012430" 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 +010012431" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12432" 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 +010012433
12434 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012435 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012436" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012437 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012438 unlet w:netrw_rexfile
12439" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012440 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012441" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012442" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12443" 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 +020012444 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012445
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012446 " ---------------------------
12447 " :Rex issued while in a file
12448 " ---------------------------
12449
Bram Moolenaara6878372014-03-22 21:02:50 +010012450 " record current file so :Rex can return to it from netrw
12451 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012452" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012453
12454 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012455" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012456 return
12457 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012458" 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 +020012459 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012460 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012461 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012462 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012463 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012464 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012465 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012466 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012467 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012468" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12469 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012470" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12471 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012472 if exists("s:rexposn_".bufnr('%'))
12473 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012474 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012475 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012476" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012477 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012478
Bram Moolenaar85850f32019-07-19 22:05:51 +020012479 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12480 if exists("s:explore_match")
12481 exe "2match netrwMarkFile /".s:explore_match."/"
12482 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012483 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012484
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012485" 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 +010012486" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012487endfun
12488
12489" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012490" s:SaveBufVars: save selected b: variables to s: variables {{{2
12491" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012492fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012493" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012494
12495 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12496 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12497 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12498 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12499 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12500 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12501
12502" call Dret("s:SaveBufVars")
12503endfun
12504
12505" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012506" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12507fun! s:SavePosn(posndict)
12508" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12509
Bram Moolenaar85850f32019-07-19 22:05:51 +020012510 if !exists("a:posndict[bufnr('%')]")
12511 let a:posndict[bufnr("%")]= []
12512 endif
12513" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12514 call add(a:posndict[bufnr("%")],winsaveview())
12515" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012516
12517" call Dret("s:SavePosn posndict")
12518 return a:posndict
12519endfun
12520
12521" ---------------------------------------------------------------------
12522" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12523fun! s:RestorePosn(posndict)
12524" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012525 if exists("a:posndict")
12526 if has_key(a:posndict,bufnr("%"))
12527" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12528 let posnlen= len(a:posndict[bufnr("%")])
12529 if posnlen > 0
12530 let posnlen= posnlen - 1
12531" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12532 call winrestview(a:posndict[bufnr("%")][posnlen])
12533 call remove(a:posndict[bufnr("%")],posnlen)
12534" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12535 endif
12536 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012537 endif
12538" call Dret("s:RestorePosn")
12539endfun
12540
12541" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012542" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012543fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012544" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012545 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12546 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12547 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12548 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12549 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12550 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12551 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12552 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12553 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12554 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12555 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12556 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12557 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12558 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12559 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12560 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12561 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12562 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12563" call Dret("s:SaveWinVars")
12564endfun
12565
12566" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012567" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012568" To allow separate windows to have their own activities, such as
12569" Explore **/pattern, several variables have been made window-oriented.
12570" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012571" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012572" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012573fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012574" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012575 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12576 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12577 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12578 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12579 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12580 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12581 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12582 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12583 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12584 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12585" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012586endfun
12587
12588" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012589" s:SetRexDir: set directory for :Rexplore {{{2
12590fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012591" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012592 let w:netrw_rexdir = a:dirname
12593 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012594 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012595" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12596" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012597" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012598" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012599" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012600endfun
12601
12602" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012603" s:ShowLink: used to modify thin and tree listings to show links {{{2
12604fun! s:ShowLink()
12605" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012606" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12607" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012608 if exists("b:netrw_curdir")
12609 norm! $?\a
12610 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12611 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012612" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12613" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12614" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12615 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012616 let dirlen = strlen(b:netrw_curdir)
12617 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012618" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012619 endif
12620 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012621" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12622" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012623 setl noro ma
12624 call setline(".",modline)
12625 setl ro noma nomod
12626 endif
12627" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12628endfun
12629
12630" ---------------------------------------------------------------------
12631" s:ShowStyle: {{{2
12632fun! s:ShowStyle()
12633 if !exists("w:netrw_liststyle")
12634 let liststyle= g:netrw_liststyle
12635 else
12636 let liststyle= w:netrw_liststyle
12637 endif
12638 if liststyle == s:THINLIST
12639 return s:THINLIST.":thin"
12640 elseif liststyle == s:LONGLIST
12641 return s:LONGLIST.":long"
12642 elseif liststyle == s:WIDELIST
12643 return s:WIDELIST.":wide"
12644 elseif liststyle == s:TREELIST
12645 return s:TREELIST.":tree"
12646 else
12647 return 'n/a'
12648 endif
12649endfun
12650
12651" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012652" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12653" Solution from Nicolai Weibull, vim docs (:help strlen()),
12654" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012655fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012656" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12657
12658 if v:version >= 703 && exists("*strdisplaywidth")
12659 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012660
Bram Moolenaar8d043172014-01-23 14:24:41 +010012661 elseif type(g:Align_xstrlen) == 1
12662 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12663 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012664
Bram Moolenaar8d043172014-01-23 14:24:41 +010012665 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012666 " number of codepoints (Latin a + combining circumflex is two codepoints)
12667 " (comment from TM, solution from NW)
12668 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012669
Bram Moolenaar8d043172014-01-23 14:24:41 +010012670 elseif g:Align_xstrlen == 2
12671 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012672 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12673 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012674 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012675
Bram Moolenaar8d043172014-01-23 14:24:41 +010012676 elseif g:Align_xstrlen == 3
12677 " virtual length (counting, for instance, tabs as anything between 1 and
12678 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012679 " preceded by lam, one otherwise, etc.)
12680 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012681 let modkeep= &l:mod
12682 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012683 call setline(line("."),a:x)
12684 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012685 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012686 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012687 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012688
Bram Moolenaar446cb832008-06-24 21:56:24 +000012689 else
12690 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012691 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012692 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012693" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012694 return ret
12695endfun
12696
12697" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012698" s:ShellEscape: shellescape(), or special windows handling {{{2
12699fun! s:ShellEscape(s, ...)
12700 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12701 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12702 endif
12703 let f = a:0 > 0 ? a:1 : 0
12704 return shellescape(a:s, f)
12705endfun
12706
12707" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012708" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012709fun! s:TreeListMove(dir)
12710" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012711 let curline = getline('.')
12712 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12713 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12714 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12715 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12716 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12717 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12718" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12719" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12720" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12721" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12722" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12723 " COMBAK : need to handle when on a directory
12724 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012725 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012726 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012727 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012728 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012729" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012730 elseif a:dir == '[]' && nxtline != ''
12731 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012732" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012733 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12734 if nl != 0
12735 NetrwKeepj norm! k
12736 else
12737 NetrwKeepj norm! G
12738 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012739" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012740 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012741 endif
12742
12743" call Dret("s:TreeListMove")
12744endfun
12745
12746" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012747" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12748" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12749" can't be called except via emenu. But due to locale, that menu line may not be called
12750" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12751fun! s:UpdateBuffersMenu()
12752" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012753 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012754 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012755 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012756 catch /^Vim\%((\a\+)\)\=:E/
12757 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012758 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012759 endtry
12760 endif
12761" call Dret("s:UpdateBuffersMenu")
12762endfun
12763
12764" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012765" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012766" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012767fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012768" call Dfunc("s:UseBufWinVars()")
12769 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012770 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12771 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12772 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12773 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12774 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12775 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12776 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12777 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12778 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 +000012779" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012780endfun
12781
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012782" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012783" s:UserMaps: supports user-defined UserMaps {{{2
12784" * calls a user-supplied funcref(islocal,curdir)
12785" * interprets result
12786" See netrw#UserMaps()
12787fun! s:UserMaps(islocal,funcname)
12788" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12789
12790 if !exists("b:netrw_curdir")
12791 let b:netrw_curdir= getcwd()
12792 endif
12793 let Funcref = function(a:funcname)
12794 let result = Funcref(a:islocal)
12795
12796 if type(result) == 1
12797 " if result from user's funcref is a string...
12798" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12799 if result == "refresh"
12800" call Decho("refreshing display",'~'.expand("<slnum>"))
12801 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12802 elseif result != ""
12803" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12804 exe result
12805 endif
12806
12807 elseif type(result) == 3
12808 " if result from user's funcref is a List...
12809" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12810 for action in result
12811 if action == "refresh"
12812" call Decho("refreshing display",'~'.expand("<slnum>"))
12813 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12814 elseif action != ""
12815" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12816 exe action
12817 endif
12818 endfor
12819 endif
12820
12821" call Dret("s:UserMaps")
12822endfun
12823
Bram Moolenaar85850f32019-07-19 22:05:51 +020012824" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012825" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012826" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012827let &cpo= s:keepcpo
12828unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012829
Bram Moolenaar85850f32019-07-19 22:05:51 +020012830" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012831" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012832" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012833" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012834" doing autoload/netrw.vim version v172g ~57
12835" varname<g:netrw_dirhistcnt> value=0 ~1
12836" varname<s:THINLIST> value=0 ~1
12837" varname<s:LONGLIST> value=1 ~1
12838" varname<s:WIDELIST> value=2 ~1
12839" varname<s:TREELIST> value=3 ~1
12840" varname<s:MAXLIST> value=4 ~1
12841" varname<g:netrw_use_errorwindow> value=2 ~1
12842" varname<g:netrw_http_xcmd> value=-q -O ~1
12843" varname<g:netrw_http_put_cmd> value=curl -T ~1
12844" varname<g:netrw_keepj> value=keepj ~1
12845" varname<g:netrw_rcp_cmd> value=rcp ~1
12846" varname<g:netrw_rsync_cmd> value=rsync ~1
12847" varname<g:netrw_rsync_sep> value=/ ~1
12848" varname<g:netrw_scp_cmd> value=scp -q ~1
12849" varname<g:netrw_sftp_cmd> value=sftp ~1
12850" varname<g:netrw_ssh_cmd> value=ssh ~1
12851" varname<g:netrw_alto> value=0 ~1
12852" varname<g:netrw_altv> value=1 ~1
12853" varname<g:netrw_banner> value=1 ~1
12854" varname<g:netrw_browse_split> value=0 ~1
12855" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12856" varname<g:netrw_chgwin> value=-1 ~1
12857" varname<g:netrw_clipboard> value=1 ~1
12858" varname<g:netrw_compress> value=gzip ~1
12859" varname<g:netrw_ctags> value=ctags ~1
12860" varname<g:netrw_cursor> value=2 ~1
12861" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12862" varname<g:netrw_cygdrive> value=/cygdrive ~1
12863" varname<s:didstarstar> value=0 ~1
12864" varname<g:netrw_dirhistcnt> value=0 ~1
12865" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12866" varname<g:netrw_dirhistmax> value=10 ~1
12867" varname<g:netrw_errorlvl> value=0 ~1
12868" varname<g:netrw_fastbrowse> value=1 ~1
12869" 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
12870" varname<g:netrw_ftpmode> value=binary ~1
12871" varname<g:netrw_hide> value=1 ~1
12872" varname<g:netrw_keepdir> value=1 ~1
12873" varname<g:netrw_list_hide> value= ~1
12874" varname<g:netrw_localmkdir> value=mkdir ~1
12875" varname<g:netrw_remote_mkdir> value=mkdir ~1
12876" varname<g:netrw_liststyle> value=0 ~1
12877" varname<g:netrw_markfileesc> value=*./[\~ ~1
12878" varname<g:netrw_maxfilenamelen> value=32 ~1
12879" varname<g:netrw_menu> value=1 ~1
12880" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12881" varname<g:netrw_mousemaps> value=1 ~1
12882" varname<g:netrw_retmap> value=0 ~1
12883" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12884" varname<g:netrw_preview> value=0 ~1