blob: f8335996a4db539e67ee630d484aaf3475cfe5ce [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
6" Last Change:
7" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
K.Takata8750e3c2023-11-22 18:20:01 +09008" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Christian Brabandtf9ca1392024-02-19 20:37:11 +010014" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000015" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010016" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000017" Permission is hereby granted to use and distribute this code,
18" with or without modifications, provided that this copyright
19" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000020" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000021" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000022" expressed or implied. By using this plugin, you agree that
23" in no event will the copyright holder be liable for any damages
24" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010025"
26" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
27" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
28"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020029"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000030"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000031" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000032" (James 1:22 RSV)
33" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000034" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000035if &cp || exists("g:loaded_netrw")
36 finish
37endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020038
39" Check that vim has patches that netrw requires.
40" Patches needed for v7.4: 1557, and 213.
41" (netrw will benefit from vim's having patch#656, too)
42let s:needspatches=[1557,213]
43if exists("s:needspatches")
44 for ptch in s:needspatches
45 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
46 if !exists("s:needpatch{ptch}")
47 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
48 endif
49 let s:needpatch{ptch}= 1
50 finish
51 endif
52 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020053endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020054
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010055let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000056if !exists("s:NOTE")
57 let s:NOTE = 0
58 let s:WARNING = 1
59 let s:ERROR = 2
60endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000061
Bram Moolenaar1afcace2005-11-25 19:54:28 +000062let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010063setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020064"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010065"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010066"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000067
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000068" ======================
69" Netrw Variables: {{{1
70" ======================
71
Bram Moolenaar071d4272004-06-13 20:20:40 +000072" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020073" netrw#ErrorMsg: {{{2
74" 0=note = s:NOTE
75" 1=warning = s:WARNING
76" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010077" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
78" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
79" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010080" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020081fun! netrw#ErrorMsg(level,msg,errnum)
82" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
83
84 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020085" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020086 return
87 endif
88
89 if a:level == 1
90 let level= "**warning** (netrw) "
91 elseif a:level == 2
92 let level= "**error** (netrw) "
93 else
94 let level= "**note** (netrw) "
95 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010096" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020097
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020098 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
99 " use popup window
100 if type(a:msg) == 3
101 let msg = [level]+a:msg
102 else
103 let msg= level.a:msg
104 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200105 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200106 let s:popuperr_text= ""
107 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200108 " (default) netrw creates a one-line window to show error/warning
109 " messages (reliably displayed)
110
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100111 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200112 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100113" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200114
115 " getting messages out reliably is just plain difficult!
116 " This attempt splits the current window, creating a one line window.
117 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100118" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200119 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100120" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200121 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100122 if type(a:msg) == 3
123 for msg in a:msg
124 NetrwKeepj call setline(line("$")+1,level.msg)
125 endfor
126 else
127 NetrwKeepj call setline(line("$")+1,level.a:msg)
128 endif
129 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200130 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100131" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200132 bo 1split
133 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200134 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200135 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100136 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100137" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200138 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100139 if type(a:msg) == 3
140 for msg in a:msg
141 NetrwKeepj call setline(line("$")+1,level.msg)
142 endfor
143 else
144 NetrwKeepj call setline(line("$"),level.a:msg)
145 endif
146 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200147 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100148" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200149 if &fo !~ '[ta]'
150 syn clear
151 syn match netrwMesgNote "^\*\*note\*\*"
152 syn match netrwMesgWarning "^\*\*warning\*\*"
153 syn match netrwMesgError "^\*\*error\*\*"
154 hi link netrwMesgWarning WarningMsg
155 hi link netrwMesgError Error
156 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100157" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200158 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200159
160 else
161 " (optional) netrw will show messages using echomsg. Even if the
162 " message doesn't appear, at least it'll be recallable via :messages
163" redraw!
164 if a:level == s:WARNING
165 echohl WarningMsg
166 elseif a:level == s:ERROR
167 echohl Error
168 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100169
170 if type(a:msg) == 3
171 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100172 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100173 endfor
174 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100175 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100176 endif
177
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100178" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200179 echohl None
180 endif
181
182" call Dret("netrw#ErrorMsg")
183endfun
184
185" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100186" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100187" Loosely, varname = value.
188fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100189" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100190 if !exists(a:varname)
191 if type(a:value) == 0
192 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200193 elseif type(a:value) == 1 && a:value =~ '^[{[]'
194 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100195 elseif type(a:value) == 1
196 exe "let ".a:varname."="."'".a:value."'"
197 else
198 exe "let ".a:varname."=".a:value
199 endif
200 endif
201endfun
202
203" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000204" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200205call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000206if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100207 call s:NetrwInit("s:THINLIST",0)
208 call s:NetrwInit("s:LONGLIST",1)
209 call s:NetrwInit("s:WIDELIST",2)
210 call s:NetrwInit("s:TREELIST",3)
211 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000212endif
213
214" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200215" Default option values: {{{2
216let g:netrw_localcopycmdopt = ""
217let g:netrw_localcopydircmdopt = ""
218let g:netrw_localmkdiropt = ""
219let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200220
221" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000222" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200223if (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")
224 call s:NetrwInit("g:netrw_use_errorwindow",2)
225else
226 call s:NetrwInit("g:netrw_use_errorwindow",1)
227endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200228
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000229if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100230 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000231 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100232 elseif executable("curl")
233 let g:netrw_dav_cmd = "curl"
234 else
235 let g:netrw_dav_cmd = ""
236 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000237endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000238if !exists("g:netrw_fetch_cmd")
239 if executable("fetch")
240 let g:netrw_fetch_cmd = "fetch -o"
241 else
242 let g:netrw_fetch_cmd = ""
243 endif
244endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100245if !exists("g:netrw_file_cmd")
246 if executable("elinks")
247 call s:NetrwInit("g:netrw_file_cmd","elinks")
248 elseif executable("links")
249 call s:NetrwInit("g:netrw_file_cmd","links")
250 endif
251endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000252if !exists("g:netrw_ftp_cmd")
253 let g:netrw_ftp_cmd = "ftp"
254endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200255let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200256if !exists("g:netrw_ftp_options")
257 let g:netrw_ftp_options= "-i -n"
258endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000259if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100260 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100261 let g:netrw_http_cmd = "wget"
262 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100263 elseif executable("curl")
264 let g:netrw_http_cmd = "curl"
265 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200266 elseif executable("elinks")
267 let g:netrw_http_cmd = "elinks"
268 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000269 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100270 let g:netrw_http_cmd = "fetch"
271 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200272 elseif executable("links")
273 let g:netrw_http_cmd = "links"
274 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000275 else
276 let g:netrw_http_cmd = ""
277 endif
278endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100279call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100280call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100281call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
282call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200283call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200284if !exists("g:netrw_scp_cmd")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200285 if executable("pscp")
286 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200287 else
288 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
289 endif
290endif
291
Bram Moolenaar5c736222010-01-06 20:54:52 +0100292call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
293call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000294
Nir Lichtman1e34b952024-05-08 19:19:34 +0200295if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000296 \ && exists("g:netrw_use_nt_rcp")
297 \ && g:netrw_use_nt_rcp
298 \ && executable( $SystemRoot .'/system32/rcp.exe')
299 let s:netrw_has_nt_rcp = 1
300 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000301else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000302 let s:netrw_has_nt_rcp = 0
303 let s:netrw_rcpmode = ''
304endif
305
306" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000307" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000308" Cygwin Detection ------- {{{3
309if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200310 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
311 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000312 else
313 let g:netrw_cygwin= 0
314 endif
315endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000316" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100317call s:NetrwInit("g:netrw_alto" , &sb)
318call s:NetrwInit("g:netrw_altv" , &spr)
319call s:NetrwInit("g:netrw_banner" , 1)
320call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200321call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100322call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200323call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100324call s:NetrwInit("g:netrw_compress" , "gzip")
325call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200326if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
327 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
328 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000329endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200330call s:NetrwInit("g:netrw_cursor" , 2)
331let s:netrw_usercul = &cursorline
332let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200333"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100334call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000335" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200336call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200337call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200338call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100339call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200340call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100341call s:NetrwInit("g:netrw_fastbrowse" , 1)
342call 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 +0000343if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000344 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
345 let g:netrw_ftp_list_cmd = "ls -lF"
346 let g:netrw_ftp_timelist_cmd = "ls -tlF"
347 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000348 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000349 let g:netrw_ftp_list_cmd = "dir"
350 let g:netrw_ftp_timelist_cmd = "dir"
351 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000352 endif
353endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100354call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000355" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100356call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000357if !exists("g:netrw_ignorenetrc")
358 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
359 let g:netrw_ignorenetrc= 1
360 else
361 let g:netrw_ignorenetrc= 0
362 endif
363endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100364call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000365if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000366 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100367 if exists("g:netrw_list_cmd_options")
368 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
369 else
370 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
371 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000372 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200373 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100374 if exists("g:netrw_list_cmd_options")
375 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
376 else
377 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
378 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000379 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100380" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000381 let g:netrw_list_cmd= ""
382 endif
383endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100384call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000385" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200386if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200387 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200388 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
389endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100390if !exists("g:netrw_localcmdshell")
391 let g:netrw_localcmdshell= ""
392endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000393if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200394 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000395 if g:netrw_cygwin
396 let g:netrw_localcopycmd= "cp"
397 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000398 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200399 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000400 endif
401 elseif has("unix") || has("macunix")
402 let g:netrw_localcopycmd= "cp"
403 else
404 let g:netrw_localcopycmd= ""
405 endif
406endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100407if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200408 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100409 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200410 let g:netrw_localcopydircmd = "cp"
411 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100412 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000413 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200414 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100415 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200416 elseif has("unix")
417 let g:netrw_localcopydircmd = "cp"
418 let g:netrw_localcopydircmdopt= " -R"
419 elseif has("macunix")
420 let g:netrw_localcopydircmd = "cp"
421 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100422 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200423 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100424 endif
425endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200426if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100427 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200428 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
429endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200430if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200431 if g:netrw_cygwin
432 call s:NetrwInit("g:netrw_localmkdir","mkdir")
433 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000434 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200435 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200436 endif
437else
438 call s:NetrwInit("g:netrw_localmkdir","mkdir")
439endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200440call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200441if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200442 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200443 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
444endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000445if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200446 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000447 if g:netrw_cygwin
448 let g:netrw_localmovecmd= "mv"
449 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000450 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200451 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000452 endif
453 elseif has("unix") || has("macunix")
454 let g:netrw_localmovecmd= "mv"
455 else
456 let g:netrw_localmovecmd= ""
457 endif
458endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100459" following serves as an example for how to insert a version&patch specific test
460"if v:version < 704 || (v:version == 704 && !has("patch1107"))
461"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100462call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
463" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000464if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000465 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000466endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000467if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000468 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
469endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000470" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100471call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
472call s:NetrwInit("g:netrw_maxfilenamelen", 32)
473call s:NetrwInit("g:netrw_menu" , 1)
474call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200475call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100476call s:NetrwInit("g:netrw_retmap" , 0)
477if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
478 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200479elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100480 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
481else
482 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000483endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100484call s:NetrwInit("g:netrw_preview" , 0)
485call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100486call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100487call s:NetrwInit("g:netrw_sshport" , "-p")
488call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
489call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
490call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100491call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
492" Default values - q-s ---------- {{{3
493call s:NetrwInit("g:netrw_quickhelp",0)
494let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100495 \ "(create new) %:file d:directory",
496 \ "(windows split&open) o:horz v:vert p:preview",
497 \ "i:style qf:file info O:obtain r:reverse",
498 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
499 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
500 \ "(history) qb:list u:go up U:go down",
501 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100502" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
503call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100504if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
505 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
506else
507 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
508endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100509call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
510call s:NetrwInit("g:netrw_sort_options" , "")
511call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000512if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100513 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200514 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100515 else
516 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000517 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000518endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100519call s:NetrwInit("g:netrw_special_syntax" , 0)
520call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200521call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100522call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100523call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000524" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100525call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200526if !exists("g:netrw_xstrlen")
527 if exists("g:Align_xstrlen")
528 let g:netrw_xstrlen= g:Align_xstrlen
529 elseif exists("g:drawit_xstrlen")
530 let g:netrw_xstrlen= g:drawit_xstrlen
531 elseif &enc == "latin1" || !has("multi_byte")
532 let g:netrw_xstrlen= 0
533 else
534 let g:netrw_xstrlen= 1
535 endif
536endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100537call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200538call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100539call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200540if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000541" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000542" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100543call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200544if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200545 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200546else
Bram Moolenaarff034192013-04-24 18:51:19 +0200547 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200548endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200549call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100550call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
551call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100552if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100553 let s:treedepthstring= "│ "
554else
555 let s:treedepthstring= "| "
556endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200557call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000558
559" BufEnter event ignored by decho when following variable is true
560" Has a side effect that doau BufReadPost doesn't work, so
561" files read by network transfer aren't appropriately highlighted.
562"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563
Bram Moolenaaradc21822011-04-01 18:03:16 +0200564" ======================
565" Netrw Initialization: {{{1
566" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200567if 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 +0100568" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100569 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200570" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100571 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100572 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
573 au VimEnter * let s:initbeval= &beval
574"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100575" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
576" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
577" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
578" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
579" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
580" 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 +0200581endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200582au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200583
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200584if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100585 com! -nargs=* NetrwKeepj keepj <args>
586else
587 let g:netrw_keepj= ""
588 com! -nargs=* NetrwKeepj <args>
589endif
590
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000591" ==============================
592" Netrw Utility Functions: {{{1
593" ==============================
594
Bram Moolenaaradc21822011-04-01 18:03:16 +0200595" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100596" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100597if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100598" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100599 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100600 if &ft != "netrw"
601 return ""
602 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200603 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
604 " popup error window is still showing
605 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
606 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
607 " text under mouse hasn't changed; only close window when it changes
608 call popup_close(s:popuperr_id)
609 unlet s:popuperr_text
610 else
611 let s:popuperr_text= v:beval_text
612 endif
613 let mesg= ""
614 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 +0100615 let mesg= ""
616 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
617 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
618 elseif getline(v:beval_lnum) =~ '^"\s*/'
619 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
620 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100621 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100622 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
623 let mesg = "S: edit sorting sequence"
624 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
625 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
626 elseif v:beval_text == "Quick" || v:beval_text == "Help"
627 let mesg = "Help: press <F1>"
628 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
629 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
630 else
631 let mesg= ""
632 endif
633 return mesg
634 endfun
635"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100636" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
637" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
638" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
639" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
640" 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 +0200641endif
642
Bram Moolenaar071d4272004-06-13 20:20:40 +0000643" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200644" netrw#Explore: launch the local browser in the directory of the current file {{{2
645" indx: == -1: Nexplore
646" == -2: Pexplore
647" == +: this is overloaded:
648" * If Nexplore/Pexplore is in use, then this refers to the
649" indx'th item in the w:netrw_explore_list[] of items which
650" matched the */pattern **/pattern *//pattern **//pattern
651" * If Hexplore or Vexplore, then this will override
652" g:netrw_winsize to specify the qty of rows or columns the
653" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100654" 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 +0200655" dosplit==1: the window will be split before running the local browser
656" style == 0: Explore style == 1: Explore!
657" == 2: Hexplore style == 3: Hexplore!
658" == 4: Vexplore style == 5: Vexplore!
659" == 6: Texplore
660fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100661" 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 +0100662" 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 +0200663 if !exists("b:netrw_curdir")
664 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100665" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200666 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100667
668 " record current file for Rexplore's benefit
669 if &ft != "netrw"
670 let w:netrw_rexfile= expand("%:p")
671 endif
672
673 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200674 let curdir = simplify(b:netrw_curdir)
675 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200676 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200677 let curdir= substitute(curdir,'\','/','g')
678 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100679" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100680
681 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
682 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
683 " try Explore again.
684 if a:0 > 0
685" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100686 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
687 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
688 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
689 \ '~'.expand("<slnum>"))
690 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
691" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100692 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
693" call Dret("netrw#Explore : returning from retry")
694 return
695" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100696" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100697 endif
698 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200699
700 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200701 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100702" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100703 sil! let keepregstar = @*
704 sil! let keepregplus = @+
705 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200706 sil! let keepregslash= @/
707
Bram Moolenaar8d043172014-01-23 14:24:41 +0100708 " if dosplit
709 " -or- file has been modified AND file not hidden when abandoned
710 " -or- Texplore used
711 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100712" 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 +0200713 call s:SaveWinVars()
714 let winsz= g:netrw_winsize
715 if a:indx > 0
716 let winsz= a:indx
717 endif
718
719 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100720" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200721 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200722 if winsz == 0|let winsz= ""|endif
723 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100724" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200725
726 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100727" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200728 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200729 if winsz == 0|let winsz= ""|endif
730 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100731" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200732
733 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100734" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200735 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200736 if winsz == 0|let winsz= ""|endif
737 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100738" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200739
740 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100741" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200742 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200743 if winsz == 0|let winsz= ""|endif
744 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100745" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200746
747 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100748" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200749 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200750 if winsz == 0|let winsz= ""|endif
751 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100752" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200753
754 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100755" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200756 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200757 if winsz == 0|let winsz= ""|endif
758 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100759" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200760
761 elseif a:style == 6 " Texplore
762 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100763" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200764 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100765" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200766 call s:RestoreBufVars()
767 endif
768 call s:RestoreWinVars()
769" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100770" 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 +0200771 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100772 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200773
774 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100775" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200776 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100777" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100779" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200780 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
783 if dirname !~ '/$'
784 let dirname= dirname."/"
785 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200791 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100796" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200797 let dirname= a:1
798 endif
799 else
800 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100801" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 call s:NetrwClearExplore()
803" call Dret("netrw#Explore : cleared list")
804 return
805 endif
806
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100807" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200808 if dirname =~ '\.\./\=$'
809 let dirname= simplify(fnamemodify(dirname,':p:h'))
810 elseif dirname =~ '\.\.' || dirname == '.'
811 let dirname= simplify(fnamemodify(dirname,':p'))
812 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100813" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200814
815 if dirname =~ '^\*//'
816 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100817" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200818 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
819 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100820" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200821 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
822
823 elseif dirname =~ '^\*\*//'
824 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100825" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200826 let pattern= substitute(dirname,'^\*\*//','','')
827 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100828" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200829
830 elseif dirname =~ '/\*\*/'
831 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100832" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200833 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200834 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200835 let b:netrw_curdir = prefixdir
836 else
837 let b:netrw_curdir= getcwd().'/'.prefixdir
838 endif
839 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
840 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100841" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
842" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200843
844 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200845 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200846 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100847" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200848
849 elseif dirname=~ '^\*\*/'
850 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
851 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100852" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200853
854 else
855 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100856" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200857 endif
858
859 if starpat == 0 && a:indx >= 0
860 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100861" 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 +0200862 if dirname == ""
863 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100864" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200865 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200866 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200867 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200868 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200869 if dirname == ""
870 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200871 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100872 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100873 " depending on whether backslashes have been converted to forward slashes by earlier code).
874 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200875 let dirname= b:netrw_curdir."/".dirname
876 endif
877 elseif dirname !~ '^/'
878 let dirname= b:netrw_curdir."/".dirname
879 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100880" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200881 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100882" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
883" 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 +0200884 endif
885 if exists("w:netrw_bannercnt")
886 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
887 " If one wants to return the same place in the netrw window, use :Rex instead.
888 exe w:netrw_bannercnt
889 endif
890
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100891" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200892 " ---------------------------------------------------------------------
893 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
894" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100895" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200896" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100897" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200898" endif
899 " ---------------------------------------------------------------------
900
901 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
902 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
903 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
904 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
905 elseif a:indx <= 0
906 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100907" 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 +0200908 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100909" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200910 let s:didstarstar= 1
911 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
912 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
913 endif
914
915 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100916" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200917 if !exists("w:netrw_explore_indx")
918 let w:netrw_explore_indx= 0
919 endif
920
921 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100922" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200923
924 if indx == -1
925 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100926" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200927 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100928 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 +0200929 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100930" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100931 if @* != keepregstar | sil! let @* = keepregstar | endif
932 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100933 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200934 sil! let @/ = keepregslash
935" call Dret("netrw#Explore")
936 return
937 endif
938 let indx= w:netrw_explore_indx
939 if indx < 0 | let indx= 0 | endif
940 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
941 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100942" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200943 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
944 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100945" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200946 endwhile
947 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100948" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200949
950 elseif indx == -2
951 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100952" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200953 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100954 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 +0200955 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100956" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100957 if @* != keepregstar | sil! let @* = keepregstar | endif
958 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100959 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200960 sil! let @/ = keepregslash
961" call Dret("netrw#Explore")
962 return
963 endif
964 let indx= w:netrw_explore_indx
965 if indx < 0 | let indx= 0 | endif
966 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
967 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100968" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200969 while indx >= 0 && curfile == w:netrw_explore_list[indx]
970 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100971" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200972 endwhile
973 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100974" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200975
976 else
977 " Explore -- initialize
978 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100979" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100980 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200981 let w:netrw_explore_indx= 0
982 if !exists("b:netrw_curdir")
983 let b:netrw_curdir= getcwd()
984 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100985" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200986
987 " switch on starpat to build the w:netrw_explore_list of files
988 if starpat == 1
989 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100990" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
991" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200992 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100993 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200994 catch /^Vim\%((\a\+)\)\=:E480/
995 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
996" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
997 return
998 endtry
999 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1000 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1001
1002 elseif starpat == 2
1003 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001004" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1005" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001006 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001007 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001008 catch /^Vim\%((\a\+)\)\=:E480/
1009 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1010 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001011 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001012" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001013 if @* != keepregstar | sil! let @* = keepregstar | endif
1014 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001015 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001016 sil! let @/ = keepregslash
1017" call Dret("netrw#Explore : no files matched pattern")
1018 return
1019 endtry
1020 let s:netrw_curdir = b:netrw_curdir
1021 let w:netrw_explore_list = getqflist()
1022 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1023 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1024
1025 elseif starpat == 3
1026 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001027" 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 +02001028 let filepat= substitute(dirname,'^\*/','','')
1029 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001030" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1031" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001032 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1033 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1034
1035 elseif starpat == 4
1036 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001037" 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 +02001038 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1039 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1040 endif " switch on starpat to build w:netrw_explore_list
1041
1042 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001043" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1044" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001045
1046 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001047 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001048 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001049" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001050 if @* != keepregstar | sil! let @* = keepregstar | endif
1051 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001052 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001053 sil! let @/ = keepregslash
1054" call Dret("netrw#Explore : no files matched")
1055 return
1056 endif
1057 endif " if indx ... endif
1058
1059 " NetrwStatusLine support - for exploring support
1060 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001061" 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 +02001062
1063 " wrap the indx around, but issue a note
1064 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001065" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001066 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1067 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001068 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001069 endif
1070
1071 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001072" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001073 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001074" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001075
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001076" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001077 call netrw#LocalBrowseCheck(newdir)
1078 if !exists("w:netrw_liststyle")
1079 let w:netrw_liststyle= g:netrw_liststyle
1080 endif
1081 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001082 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001083 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001084 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001085 endif
1086 let w:netrw_explore_mtchcnt = indx + 1
1087 let w:netrw_explore_bufnr = bufnr("%")
1088 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001089 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001090" 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 +02001091
1092 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001093" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001094 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001095 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 +02001096 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001097 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001098" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001099 if @* != keepregstar | sil! let @* = keepregstar | endif
1100 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001101 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001102 sil! let @/ = keepregslash
1103" call Dret("netrw#Explore : missing +path_extra")
1104 return
1105 endif
1106
1107 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001108" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001109 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1110 sil! unlet w:netrw_treedict
1111 sil! unlet w:netrw_treetop
1112 endif
1113 let newdir= dirname
1114 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001115 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001116 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001117 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001118 endif
1119 endif
1120
1121 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001122" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1123" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001124 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001125" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001126 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001127 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001128" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001129 let s:explore_prvdir = b:netrw_curdir
1130 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001131 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001132 if b:netrw_curdir !~ '/$'
1133 let dirlen= dirlen + 1
1134 endif
1135 let prvfname= ""
1136 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001137" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001138 if fname =~ '^'.b:netrw_curdir
1139 if s:explore_match == ""
1140 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1141 else
1142 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1143 endif
1144 elseif fname !~ '^/' && fname != prvfname
1145 if s:explore_match == ""
1146 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1147 else
1148 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1149 endif
1150 endif
1151 let prvfname= fname
1152 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001153" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001154 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1155 exe "2match netrwMarkFile /".s:explore_match."/"
1156 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001157 endif
1158 echo "<s-up>==Pexplore <s-down>==Nexplore"
1159 else
1160 2match none
1161 if exists("s:explore_match") | unlet s:explore_match | endif
1162 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001163" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001164 endif
1165
Bram Moolenaara6878372014-03-22 21:02:50 +01001166 " since Explore may be used to initialize netrw's browser,
1167 " there's no danger of a late FocusGained event on initialization.
1168 " Consequently, set s:netrw_events to 2.
1169 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001170 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001171" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001172 if @* != keepregstar | sil! let @* = keepregstar | endif
1173 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001174 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001175 sil! let @/ = keepregslash
1176" call Dret("netrw#Explore : @/<".@/.">")
1177endfun
1178
1179" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001180" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001181" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1182" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1183" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1184" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1185" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001186fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001187" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001188 let curwin= winnr()
1189
Bram Moolenaara6878372014-03-22 21:02:50 +01001190 if a:0 > 0 && a:1 != ""
1191 " if a netrw window is already on the left-side of the tab
1192 " and a directory has been specified, explore with that
1193 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001194" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001195 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001196" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001197 exe "1wincmd w"
1198 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001199" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001200 exe "Explore ".fnameescape(a1)
1201 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001202 let s:lexplore_win= curwin
1203 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001204 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001205" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001206 unlet t:netrw_lexposn
1207 endif
1208" call Dret("netrw#Lexplore")
1209 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001210 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001211 exe curwin."wincmd w"
1212 else
1213 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001214" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001215 endif
1216
Bram Moolenaar8d043172014-01-23 14:24:41 +01001217 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001218 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001219 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001220" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001221 else
1222 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001223" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001224 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001225" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001226
1227 if lexwinnr > 0
1228 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001229" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001230 exe lexwinnr."wincmd w"
1231 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001232 let t:netrw_lexposn = winsaveview()
1233" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001234" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001235 close
1236 if lexwinnr < curwin
1237 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001238 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001239 if lexwinnr != curwin
1240 exe curwin."wincmd w"
1241 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001242 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001243" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001244
1245 else
1246 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001247" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001248 exe "1wincmd w"
1249 let keep_altv = g:netrw_altv
1250 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001251 if a:count != 0
1252 let netrw_winsize = g:netrw_winsize
1253 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001254 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001255 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001256" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001257 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 +02001258" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001259 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001260" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001261 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001262 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001263 elseif curfile =~ '^\a\{3,}://'
1264" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001265 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001267" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001268 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001269 endif
1270 if a:count != 0
1271 let g:netrw_winsize = netrw_winsize
1272 endif
1273 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001274 let g:netrw_altv = keep_altv
1275 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001276 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1277 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001278 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001279 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001280" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1281" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001282 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001283" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001284" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1285 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001286 unlet t:netrw_lexposn
1287 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001288 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001289
1290 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001291 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001292 if a:rightside
1293 let g:netrw_chgwin= 1
1294 else
1295 let g:netrw_chgwin= 2
1296 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001297" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001298 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001299
Bram Moolenaar8d043172014-01-23 14:24:41 +01001300" call Dret("netrw#Lexplore")
1301endfun
1302
1303" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001304" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001305" supports :NetrwClean -- remove netrw from first directory on runtimepath
1306" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001307fun! netrw#Clean(sys)
1308" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001309
1310 if a:sys
1311 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1312 else
1313 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1314 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001315" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001316 let diddel= 0
1317 let diddir= ""
1318
1319 if choice == 1
1320 for dir in split(&rtp,',')
1321 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001322" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001323 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1324 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1325 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1326 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1327 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1328 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 +00001329 let diddir= dir
1330 let diddel= diddel + 1
1331 if !a:sys|break|endif
1332 endif
1333 endfor
1334 endif
1335
1336 echohl WarningMsg
1337 if diddel == 0
1338 echomsg "netrw is either not installed or not removable"
1339 elseif diddel == 1
1340 echomsg "removed one copy of netrw from <".diddir.">"
1341 else
1342 echomsg "removed ".diddel." copies of netrw"
1343 endif
1344 echohl None
1345
Bram Moolenaara6878372014-03-22 21:02:50 +01001346" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001347endfun
1348
Bram Moolenaar5c736222010-01-06 20:54:52 +01001349" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001350" netrw#MakeTgt: make a target out of the directory name provided {{{2
1351fun! netrw#MakeTgt(dname)
1352" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1353 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001354 let svpos = winsaveview()
1355" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001356 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1357" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001358 if s:netrwmftgt_islocal
1359 let netrwmftgt= simplify(a:dname)
1360 else
1361 let netrwmftgt= a:dname
1362 endif
1363 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1364 " re-selected target, so just clear it
1365 unlet s:netrwmftgt s:netrwmftgt_islocal
1366 else
1367 let s:netrwmftgt= netrwmftgt
1368 endif
1369 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001370 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001371 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001372" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1373 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001374" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001375endfun
1376
Bram Moolenaara6878372014-03-22 21:02:50 +01001377" ---------------------------------------------------------------------
1378" netrw#Obtain: {{{2
1379" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001380" islocal=0 obtain from remote source
1381" =1 obtain from local source
1382" fname : a filename or a list of filenames
1383" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001384fun! netrw#Obtain(islocal,fname,...)
1385" 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 +02001386 " NetrwStatusLine support - for obtaining support
1387
1388 if type(a:fname) == 1
1389 let fnamelist= [ a:fname ]
1390 elseif type(a:fname) == 3
1391 let fnamelist= a:fname
1392 else
1393 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 +01001394" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001395 return
1396 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001397" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001398 if a:0 > 0
1399 let tgtdir= a:1
1400 else
1401 let tgtdir= getcwd()
1402 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001403" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001404
1405 if exists("b:netrw_islocal") && b:netrw_islocal
1406 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001407" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001408 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1409 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001410 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001411 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001412" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001413 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001414" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001415 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001416 if v:shell_error != 0
1417 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 +01001418" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001419 return
1420 endif
1421 endfor
1422 else
1423 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001424" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1425 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1426" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001427 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".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." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001431 return
1432 endif
1433 endif
1434 elseif !exists("b:netrw_curdir")
1435 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1436 else
1437 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1438 endif
1439
1440 else
1441 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001442" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001443 if type(a:fname) == 1
1444 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1445 endif
1446 call s:NetrwMethod(b:netrw_curdir)
1447
1448 if b:netrw_method == 4
1449 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001450" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001451 if exists("g:netrw_port") && g:netrw_port != ""
1452 let useport= " ".g:netrw_scpport." ".g:netrw_port
1453 else
1454 let useport= ""
1455 endif
1456 if b:netrw_fname =~ '/'
1457 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1458 else
1459 let path= ""
1460 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001461 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001462 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 +02001463
1464 elseif b:netrw_method == 2
1465 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001466" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001467 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001468 let tmpbufnr= bufnr("%")
1469 setl ff=unix
1470 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001471 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001472" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001473 endif
1474
1475 if exists("b:netrw_fname") && b:netrw_fname != ""
1476 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001477" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001478 endif
1479
1480 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001481 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001482" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001483 endif
1484 for fname in fnamelist
1485 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001486" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001487 endfor
1488 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001489 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 +02001490 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001491 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001492 endif
1493 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1494 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1495 let debugkeep= &debug
1496 setl debug=msg
1497 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1498 let &debug= debugkeep
1499 endif
1500
1501 elseif b:netrw_method == 3
1502 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001503" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001504 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001505 let tmpbufnr= bufnr("%")
1506 setl ff=unix
1507
1508 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001509 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001510" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001511 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001512 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001513" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001514 endif
1515
1516 if exists("g:netrw_uid") && g:netrw_uid != ""
1517 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001518 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001519" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001520 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001521 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001522 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001523" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001524 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001525 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001526" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001527 endif
1528 endif
1529
1530 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001531 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001532" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001533 endif
1534
1535 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001536 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001537" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001538 endif
1539
1540 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001541 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001542" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001543 endif
1544
1545 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001546 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001547" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001548 endif
1549 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001550 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001551 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001552" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001553
1554 " perform ftp:
1555 " -i : turns off interactive prompting from ftp
1556 " -n unix : DON'T use <.netrc>, even though it exists
1557 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001558 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1559 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001560 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001561 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1562 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001563" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001564 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001565 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001566 endif
1567 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001568
1569 elseif b:netrw_method == 9
1570 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001571" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001572 if a:fname =~ '/'
1573 let localfile= substitute(a:fname,'^.*/','','')
1574 else
1575 let localfile= a:fname
1576 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001577 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 +02001578
Bram Moolenaarff034192013-04-24 18:51:19 +02001579 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001580 " probably a badly formed url; protocol not recognized
1581" call Dret("netrw#Obtain : unsupported method")
1582 return
1583
1584 else
1585 " protocol recognized but not supported for Obtain (yet?)
1586 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001587 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001588 endif
1589" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001590 return
1591 endif
1592
1593 " restore status line
1594 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001595 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001596 endif
1597
1598 endif
1599
1600 " cleanup
1601 if exists("tmpbufnr")
1602 if bufnr("%") != tmpbufnr
1603 exe tmpbufnr."bw!"
1604 else
1605 q!
1606 endif
1607 endif
1608
Bram Moolenaara6878372014-03-22 21:02:50 +01001609" call Dret("netrw#Obtain")
1610endfun
1611
1612" ---------------------------------------------------------------------
1613" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1614fun! netrw#Nread(mode,fname)
1615" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001616 let svpos= winsaveview()
1617" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001618 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001619" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1620 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001621
1622 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1623 if exists("w:netrw_bannercnt")
1624 " start with cursor just after the banner
1625 exe w:netrw_bannercnt
1626 endif
1627 endif
1628" call Dret("netrw#Nread")
1629endfun
1630
1631" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001632" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1633" Options get restored by s:NetrwOptionsRestore()
1634"
1635" Option handling:
1636" * save user's options (s:NetrwOptionsSave)
1637" * set netrw-safe options (s:NetrwOptionsSafe)
1638" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1639" * restore user's options (s:netrwOPtionsRestore)
1640" - restore a user option when != safe option (s:NetrwRestoreSetting)
1641" vt: (variable type) normally its either "w:" or "s:"
1642fun! s:NetrwOptionsSave(vt)
1643" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1644" 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 +02001645" 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>"))
1646" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001647
1648 if !exists("{a:vt}netrw_optionsave")
1649 let {a:vt}netrw_optionsave= 1
1650 else
1651" call Dret("s:NetrwOptionsSave : options already saved")
1652 return
1653 endif
1654" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1655
1656 " Save current settings and current directory
1657" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1658 let s:yykeep = @@
1659 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1660 let {a:vt}netrw_aikeep = &l:ai
1661 let {a:vt}netrw_awkeep = &l:aw
1662 let {a:vt}netrw_bhkeep = &l:bh
1663 let {a:vt}netrw_blkeep = &l:bl
1664 let {a:vt}netrw_btkeep = &l:bt
1665 let {a:vt}netrw_bombkeep = &l:bomb
1666 let {a:vt}netrw_cedit = &cedit
1667 let {a:vt}netrw_cikeep = &l:ci
1668 let {a:vt}netrw_cinkeep = &l:cin
1669 let {a:vt}netrw_cinokeep = &l:cino
1670 let {a:vt}netrw_comkeep = &l:com
1671 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001672 let {a:vt}netrw_cuckeep = &l:cuc
1673 let {a:vt}netrw_culkeep = &l:cul
1674" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001675 let {a:vt}netrw_diffkeep = &l:diff
1676 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001677 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1678 let {a:vt}netrw_ffkeep = &l:ff
1679 endif
1680 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1681 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001682 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001683 let {a:vt}netrw_hidkeep = &l:hidden
1684 let {a:vt}netrw_imkeep = &l:im
1685 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001686 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001687 let {a:vt}netrw_lskeep = &l:ls
1688 let {a:vt}netrw_makeep = &l:ma
1689 let {a:vt}netrw_magickeep = &l:magic
1690 let {a:vt}netrw_modkeep = &l:mod
1691 let {a:vt}netrw_nukeep = &l:nu
1692 let {a:vt}netrw_rnukeep = &l:rnu
1693 let {a:vt}netrw_repkeep = &l:report
1694 let {a:vt}netrw_rokeep = &l:ro
1695 let {a:vt}netrw_selkeep = &l:sel
1696 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001697 if !g:netrw_use_noswf
1698 let {a:vt}netrw_swfkeep = &l:swf
1699 endif
1700 let {a:vt}netrw_tskeep = &l:ts
1701 let {a:vt}netrw_twkeep = &l:tw " textwidth
1702 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1703 let {a:vt}netrw_wrapkeep = &l:wrap
1704 let {a:vt}netrw_writekeep = &l:write
1705
1706 " save a few selected netrw-related variables
1707" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1708 if g:netrw_keepdir
1709 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001710" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001711 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001712 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001713 sil! let {a:vt}netrw_starkeep = @*
1714 sil! let {a:vt}netrw_pluskeep = @+
1715 endif
1716 sil! let {a:vt}netrw_slashkeep= @/
1717
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001718" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001719" 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>"))
1720" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1721endfun
1722
1723" ---------------------------------------------------------------------
1724" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1725" Use s:NetrwSaveOptions() to save user settings
1726" Use s:NetrwOptionsRestore() to restore user settings
1727fun! s:NetrwOptionsSafe(islocal)
1728" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1729" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1730" 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>"))
1731 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1732 call s:NetrwSetSafeSetting("&l:ai",0)
1733 call s:NetrwSetSafeSetting("&l:aw",0)
1734 call s:NetrwSetSafeSetting("&l:bl",0)
1735 call s:NetrwSetSafeSetting("&l:bomb",0)
1736 if a:islocal
1737 call s:NetrwSetSafeSetting("&l:bt","nofile")
1738 else
1739 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1740 endif
1741 call s:NetrwSetSafeSetting("&l:ci",0)
1742 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001743 if g:netrw_fastbrowse > a:islocal
1744 call s:NetrwSetSafeSetting("&l:bh","hide")
1745 else
1746 call s:NetrwSetSafeSetting("&l:bh","delete")
1747 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001748 call s:NetrwSetSafeSetting("&l:cino","")
1749 call s:NetrwSetSafeSetting("&l:com","")
1750 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1751 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1752 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001753 if &go =~ 'a' | set go-=a | endif
1754 if &go =~ 'A' | set go-=A | endif
1755 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001756 call s:NetrwSetSafeSetting("&l:hid",0)
1757 call s:NetrwSetSafeSetting("&l:im",0)
1758 setl isk+=@ isk+=* isk+=/
1759 call s:NetrwSetSafeSetting("&l:magic",1)
1760 if g:netrw_use_noswf
1761 call s:NetrwSetSafeSetting("swf",0)
1762 endif
1763 call s:NetrwSetSafeSetting("&l:report",10000)
1764 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1765 call s:NetrwSetSafeSetting("&l:spell",0)
1766 call s:NetrwSetSafeSetting("&l:tw",0)
1767 call s:NetrwSetSafeSetting("&l:wig","")
1768 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001769
1770 " set up cuc and cul based on g:netrw_cursor and listing style
1771 " COMBAK -- cuc cul related
1772 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001773
1774 " allow the user to override safe options
1775" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1776 if &ft == "netrw"
1777" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1778 keepalt NetrwKeepj doau FileType netrw
1779 endif
1780
1781" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1782" 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>"))
1783" call Dret("s:NetrwOptionsSafe")
1784endfun
1785
1786" ---------------------------------------------------------------------
1787" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1788fun! s:NetrwOptionsRestore(vt)
1789" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001790" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001791" 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 +01001792 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001793" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001794
1795 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1796 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001797" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001798 filetype detect
1799" 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>"))
1800 else
1801 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001802 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001803" 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 +02001804" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001805 return
1806 endif
1807 unlet {a:vt}netrw_optionsave
1808
1809 if exists("+acd")
1810 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001811" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001812 let curdir = getcwd()
1813 let &l:acd = {a:vt}netrw_acdkeep
1814 unlet {a:vt}netrw_acdkeep
1815 if &l:acd
1816 call s:NetrwLcd(curdir)
1817 endif
1818 endif
1819 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001820" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001821 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1822 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1823 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1824 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1825 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001826" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001827 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1828 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1829 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1830 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1831 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001832" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001833 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1834 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1835 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1836 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1837 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001838 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001839" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1840 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1841 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001842 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001843 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1844" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1845 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1846 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1847" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1848 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1849" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1850 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1851 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001852 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001853 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1854 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1855" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1856 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1857 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1858 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1859 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1860" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001861 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001862 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1863 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1864 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001865 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001866" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001867 call s:NetrwRestoreSetting("s:yykeep","@@")
1868 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1869 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1870 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1871 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1872
Bram Moolenaara6878372014-03-22 21:02:50 +01001873 if exists("{a:vt}netrw_swfkeep")
1874 if &directory == ""
1875 " user hasn't specified a swapfile directory;
1876 " netrw will temporarily set the swapfile directory
1877 " to the current directory as returned by getcwd().
1878 let &l:directory= getcwd()
1879 sil! let &l:swf = {a:vt}netrw_swfkeep
1880 setl directory=
1881 unlet {a:vt}netrw_swfkeep
1882 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001883 if !g:netrw_use_noswf
1884 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1885 sil! let &l:swf= {a:vt}netrw_swfkeep
1886 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001887 unlet {a:vt}netrw_swfkeep
1888 endif
1889 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001890 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001891 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1892 if exists("{a:vt}netrw_dirkeep")
1893 call s:NetrwLcd(dirkeep)
1894 unlet {a:vt}netrw_dirkeep
1895 endif
1896 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001897 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001898" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001899 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1900 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001901 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001902 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001903
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001904" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1905" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1906" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1907" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1908" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001909 " Moved the filetype detect here from NetrwGetFile() because remote files
1910 " were having their filetype detect-generated settings overwritten by
1911 " NetrwOptionRestore.
1912 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001913" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1914 filetype detect
1915" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001916 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001917" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001918" 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 +02001919" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001920endfun
1921
1922" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001923" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1924" but only when the options' value and the safe setting differ
1925" Doing this means that netrw will not come up as having changed a
1926" setting last when it really didn't actually change it.
1927"
1928" Called from s:NetrwOptionsSafe
1929" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1930fun! s:NetrwSetSafeSetting(setting,safesetting)
1931" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001932
Bram Moolenaar85850f32019-07-19 22:05:51 +02001933 if a:setting =~ '^&'
1934" call Decho("fyi: a:setting starts with &")
1935 exe "let settingval= ".a:setting
1936" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001937
Bram Moolenaar85850f32019-07-19 22:05:51 +02001938 if settingval != a:safesetting
1939" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1940 if type(a:safesetting) == 0
1941 exe "let ".a:setting."=".a:safesetting
1942 elseif type(a:safesetting) == 1
1943 exe "let ".a:setting."= '".a:safesetting."'"
1944 else
1945 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1946 endif
1947 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001948 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001949
Bram Moolenaar85850f32019-07-19 22:05:51 +02001950" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001951endfun
1952
1953" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001954" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1955" but only if the setting value differs from the associated keepvar.
1956" Doing this means that netrw will not come up as having changed a
1957" setting last when it really didn't actually change it.
1958"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001959" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001960" keepvars are set up by s:NetrwOptionsSave
1961fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001962""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001963
Bram Moolenaar85850f32019-07-19 22:05:51 +02001964 " typically called from s:NetrwOptionsRestore
1965 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1966 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001967 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001968 if exists(a:keepvar)
1969 exe "let keepvarval= ".a:keepvar
1970 exe "let setting= ".a:setting
1971
1972"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1973"" call Decho("fyi: keepvarval=".keepvarval)
1974"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1975
1976 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001977"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001978 if type(a:setting) == 0
1979 exe "let ".a:setting."= ".keepvarval
1980 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001981 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001982 else
1983 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1984 endif
1985 endif
1986
1987 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001988 endif
1989
Bram Moolenaar85850f32019-07-19 22:05:51 +02001990"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001991endfun
1992
1993" ---------------------------------------------------------------------
1994" NetrwStatusLine: {{{2
1995fun! NetrwStatusLine()
1996
1997" vvv NetrwStatusLine() debugging vvv
1998" let g:stlmsg=""
1999" if !exists("w:netrw_explore_bufnr")
2000" let g:stlmsg="!X<explore_bufnr>"
2001" elseif w:netrw_explore_bufnr != bufnr("%")
2002" let g:stlmsg="explore_bufnr!=".bufnr("%")
2003" endif
2004" if !exists("w:netrw_explore_line")
2005" let g:stlmsg=" !X<explore_line>"
2006" elseif w:netrw_explore_line != line(".")
2007" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2008" endif
2009" if !exists("w:netrw_explore_list")
2010" let g:stlmsg=" !X<explore_list>"
2011" endif
2012" ^^^ NetrwStatusLine() debugging ^^^
2013
2014 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")
2015 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002016 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002017 let &laststatus = s:netrw_users_ls
2018 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2019 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2020 return ""
2021 else
2022 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2023 endif
2024endfun
2025
Bram Moolenaar85850f32019-07-19 22:05:51 +02002026" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002027" Netrw Transfer Functions: {{{1
2028" ===============================
2029
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002031" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002032" mode: =0 read remote file and insert before current line
2033" =1 read remote file and insert after current line
2034" =2 replace with remote file
2035" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002036fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002037" 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 +00002038
Bram Moolenaar5c736222010-01-06 20:54:52 +01002039 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002040 call s:NetrwOptionsSave("w:")
2041 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002042 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002043 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2044 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2045 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002046" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002047
Bram Moolenaar5c736222010-01-06 20:54:52 +01002048 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002049 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002050 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002051 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002052 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002053 elseif a:mode == 2 " replace with remote file
2054 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002055 elseif a:mode == 3 " skip read of file (leave as temporary)
2056 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002057 else
2058 exe a:mode
2059 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002060 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002061 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002062" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002063
Bram Moolenaar5c736222010-01-06 20:54:52 +01002064 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002065 let tmpfile= s:GetTempfile("")
2066 if tmpfile == ""
2067" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002068 return
2069 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002070
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002071 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002072
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002073 " attempt to repeat with previous host-file-etc
2074 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002075" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002076 let choice = b:netrw_lastfile
2077 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002078
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002079 else
2080 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002081" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002082
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002083 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002084 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002085 echomsg 'NetRead Usage:'
2086 echomsg ':Nread machine:path uses rcp'
2087 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2088 echomsg ':Nread "machine id password path" uses ftp'
2089 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2090 echomsg ':Nread fetch://machine/path uses fetch'
2091 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2092 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002093 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002094 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002095 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2096 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2097 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2098 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002099 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002100 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002101
Bram Moolenaar9964e462007-05-05 17:54:07 +00002102 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002103 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002104" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002105 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002106 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002107 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002108 else
2109 " case "... ... ..."
2110 let choice = strpart(choice,1,strlen(choice)-1)
2111 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002112
Bram Moolenaar9964e462007-05-05 17:54:07 +00002113 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002114 let wholechoice = wholechoice . " " . choice
2115 let ichoice = ichoice + 1
2116 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002117 if !exists("g:netrw_quiet")
2118 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2119 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002120" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002121 return
2122 endif
2123 let choice= a:{ichoice}
2124 endwhile
2125 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2126 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127 endif
2128 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002130" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002131 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002132
Bram Moolenaar5c736222010-01-06 20:54:52 +01002133 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002134 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002135 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002136" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002137 return
2138 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002139 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002140
Bram Moolenaar8d043172014-01-23 14:24:41 +01002141 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002142" 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 +02002143 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002144" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002145 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002146" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002147 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002148 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002149
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002150 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002151 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002152 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002153 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2154 echo "(netrw) Processing your read request..."
2155 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002156
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002157 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002158 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002159 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002160" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002161 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002162 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002163 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002164 " ER: the tmpfile is full path: rcp sees C:\... as host C
2165 if s:netrw_has_nt_rcp == 1
2166 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2167 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2168 else
2169 " Any way needed it machine contains a '.'
2170 let uid_machine = g:netrw_machine .'.'. $USERNAME
2171 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002173 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2174 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2175 else
2176 let uid_machine = g:netrw_machine
2177 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002178 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002179 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 +00002180 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002181 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002182
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002183 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002184 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002185 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002186" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002187 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002188 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002189 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002190 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002191 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002192" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002193 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002194 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002195" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002196 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002197 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002198" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002199 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002200 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 +00002201 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002202 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002203 endif
2204 " 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 +00002205 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002206 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002207 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002208 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002209 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002210 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002211 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002212 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002213 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2214 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002215 q!
2216 endif
2217 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002218 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002219 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002220
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002221 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002222 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002223 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2224 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002225" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002226 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002227 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002228 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002229 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002231 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002232" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002233 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002234 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002235" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002236 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002237
Bram Moolenaar97d62492012-11-15 21:28:22 +01002238 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002239 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002240 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002241" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002242 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002243 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002244 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002245" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002246 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002247 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002248" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002249 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002250 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002251
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002252 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002253 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002255 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002256 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002257 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002258" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002259 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002260 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002261" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002262
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002263 " perform ftp:
2264 " -i : turns off interactive prompting from ftp
2265 " -n unix : DON'T use <.netrc>, even though it exists
2266 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002267 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002268 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002269 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2270 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002271" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002272 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002273 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002274 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002275 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002276 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002277 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002278 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002279
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002280 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002281 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002283" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002285 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002286 else
2287 let useport= ""
2288 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002289 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2290 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002291 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002292 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2293 else
2294 let tmpfile_get = tmpfile
2295 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002296 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 +00002297 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002298 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002299
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002300 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002301 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002302 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002303" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002304 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002305 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002306 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002307 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002308" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002309 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002310 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002311
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002312 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2313 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002314" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002315 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002316 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 +00002317 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002318 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 +00002319 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002320 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002321
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002322 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002323 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002324" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002325 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2326 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002327" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2328" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2329 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 +00002330 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002331" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002332 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002333 endif
2334 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002335" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002336 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002337
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002338 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002339 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002340 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002341" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002342
Bram Moolenaar5c736222010-01-06 20:54:52 +01002343 if !executable(g:netrw_dav_cmd)
2344 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2345" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2346 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002347 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002348 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002349 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 +01002350 else
2351 " Construct execution string (four lines) which will be passed through filter
2352 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2353 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002354 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002355 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002356 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002357 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002358 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002359 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002360 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002361 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002362 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002363 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2364 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002365
Bram Moolenaar5c736222010-01-06 20:54:52 +01002366 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002367 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002368 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002369 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002370 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002371 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002372 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002373
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002374 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002375 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002376 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002377" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002378 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 +00002379 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002380 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002381
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002382 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002383 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002384 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002385 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002386" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002388 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002389 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002390 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002391" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002392 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002394 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002395 let netrw_option= "http"
2396 else
2397 let netrw_option= "ftp"
2398 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002399" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002400
Bram Moolenaar446cb832008-06-24 21:56:24 +00002401 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002402 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 +00002403 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002404 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 +00002405 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002406
Bram Moolenaar446cb832008-06-24 21:56:24 +00002407 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002408 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002409" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002410 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002411
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002412 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002413 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002414 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002415" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2416 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 +00002417 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002418 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002419
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002420 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002421 " NetRead: (file) NetRead Method #10 {{{3
2422 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002423" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2424 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002425 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2426 let b:netrw_lastfile = choice
2427
2428 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002429 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002430 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002431 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002432 endif
2433 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002434
Bram Moolenaar5c736222010-01-06 20:54:52 +01002435 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002436 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002437" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002438 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002439 unlet b:netrw_fname
2440 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002441 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 +01002442" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002443 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002444 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002445 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002446
Bram Moolenaar9964e462007-05-05 17:54:07 +00002447" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002448endfun
2449
2450" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002451" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002452fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002453" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002454
Bram Moolenaar5c736222010-01-06 20:54:52 +01002455 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002456 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002457 call s:NetrwOptionsSave("w:")
2458 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002459
Bram Moolenaar5c736222010-01-06 20:54:52 +01002460 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002461 let tmpfile= s:GetTempfile("")
2462 if tmpfile == ""
2463" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002464 return
2465 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002466
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002467 if a:0 == 0
2468 let ichoice = 0
2469 else
2470 let ichoice = 1
2471 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002472
Bram Moolenaar9964e462007-05-05 17:54:07 +00002473 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002474" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002475 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002476 " For binary writes, always write entire file.
2477 " (line numbers don't really make sense for that).
2478 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002479" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002480 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002481 elseif g:netrw_cygwin
2482 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002483 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002484" 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 +01002485 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002486 else
2487 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002488" 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 +01002489 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002490 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002491
Bram Moolenaar9964e462007-05-05 17:54:07 +00002492 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002493 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002494 " on the temporary file's name. Deletion of the temporary file during
2495 " cleanup then causes an error message.
2496 0file!
2497 endif
2498
Bram Moolenaar5c736222010-01-06 20:54:52 +01002499 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002500 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002501
Bram Moolenaar9964e462007-05-05 17:54:07 +00002502 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002503 " attempt to repeat with previous host-file-etc
2504 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002505" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002506 let choice = b:netrw_lastfile
2507 let ichoice= ichoice + 1
2508 else
2509 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002510
Bram Moolenaar8d043172014-01-23 14:24:41 +01002511 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002512 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002513 echomsg 'NetWrite Usage:"'
2514 echomsg ':Nwrite machine:path uses rcp'
2515 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2516 echomsg ':Nwrite "machine id password path" uses ftp'
2517 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2518 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2519 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2520 echomsg ':Nwrite rcp://machine/path uses rcp'
2521 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2522 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2523 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002524 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002525 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002526
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002527 elseif match(choice,"^\"") != -1
2528 if match(choice,"\"$") != -1
2529 " case "..."
2530 let choice=strpart(choice,1,strlen(choice)-2)
2531 else
2532 " case "... ... ..."
2533 let choice = strpart(choice,1,strlen(choice)-1)
2534 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002535
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002536 while match(choice,"\"$") == -1
2537 let wholechoice= wholechoice . " " . choice
2538 let ichoice = ichoice + 1
2539 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002540 if !exists("g:netrw_quiet")
2541 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2542 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002543" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002544 return
2545 endif
2546 let choice= a:{ichoice}
2547 endwhile
2548 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2549 endif
2550 endif
2551 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002552 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002553" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002554
Bram Moolenaar9964e462007-05-05 17:54:07 +00002555 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002556 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002557 if !exists("b:netrw_method") || b:netrw_method < 0
2558" call Dfunc("netrw#NetWrite : unsupported method")
2559 return
2560 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002561
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002562 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002563 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002564 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002565 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2566 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002567" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002568 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002569
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002570 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002571 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002572 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002573" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002574 if s:netrw_has_nt_rcp == 1
2575 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2576 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2577 else
2578 let uid_machine = g:netrw_machine .'.'. $USERNAME
2579 endif
2580 else
2581 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2582 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2583 else
2584 let uid_machine = g:netrw_machine
2585 endif
2586 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002587 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 +00002588 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002589
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002590 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002591 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002592 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002593" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002594 let netrw_fname = b:netrw_fname
2595
2596 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2597 let bhkeep = &l:bh
2598 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002599 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002600 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002601
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002602" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002603 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002604 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002605" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002606 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002607 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002608" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002609 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002610 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002612 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002613 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 +00002614 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002615" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2616 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 endif
2618 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2619 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002620 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002621 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002622 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002623 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002625
2626 " remove enew buffer (quietly)
2627 let filtbuf= bufnr("%")
2628 exe curbuf."b!"
2629 let &l:bh = bhkeep
2630 exe filtbuf."bw!"
2631
Bram Moolenaar071d4272004-06-13 20:20:40 +00002632 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002633
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002634 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002635 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002636 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002637 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002638" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002639 let netrw_fname = b:netrw_fname
2640 let bhkeep = &l:bh
2641
2642 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2643 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002644 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002645 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002646 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002647
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002648 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002649 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002650" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002651 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002652 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002653" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002654 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002655 if exists("g:netrw_uid") && g:netrw_uid != ""
2656 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002657 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002658" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002659 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002660 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002661 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002662" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002663 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002664 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002665" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002666 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002667 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002668 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002669" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002670 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002671 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002672" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002673 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002674 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002675" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002676 " save choice/id/password for future use
2677 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002678
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002679 " perform ftp:
2680 " -i : turns off interactive prompting from ftp
2681 " -n unix : DON'T use <.netrc>, even though it exists
2682 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002683 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002684 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002685 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2686 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002687 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002688 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002689 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002690 let mod=1
2691 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002692
2693 " remove enew buffer (quietly)
2694 let filtbuf= bufnr("%")
2695 exe curbuf."b!"
2696 let &l:bh= bhkeep
2697 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002698
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002699 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002700 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002701 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002702" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002703 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002704 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002705 else
2706 let useport= ""
2707 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002708 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 +00002709 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002710
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002711 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002712 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002713 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002714" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002715 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2716 if executable(curl)
2717 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002718 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 +01002719 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002720 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002721 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002722
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002723 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002724 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002725 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002726" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002727
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002728 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002729 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2730 let bhkeep = &l:bh
2731
2732 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2733 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002734 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002735 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002736
Bram Moolenaarff034192013-04-24 18:51:19 +02002737 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002738 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002739 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002740 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002741 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002742 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002743 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002744 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002745 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002746 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002747
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002748 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002749 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002750 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002751
2752 " remove enew buffer (quietly)
2753 let filtbuf= bufnr("%")
2754 exe curbuf."b!"
2755 let &l:bh = bhkeep
2756 exe filtbuf."bw!"
2757
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002758 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002759
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002760 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002761 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002762 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002763" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002764 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 +00002765 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002766
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002767 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002768 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002769 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002770" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002771 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2773 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2774 else
2775 let uid_machine = g:netrw_machine
2776 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002777
2778 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2779 let bhkeep = &l:bh
2780 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002781 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002782 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002783
Bram Moolenaarff034192013-04-24 18:51:19 +02002784 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002785 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002786" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002787 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002788 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002789 let filtbuf= bufnr("%")
2790 exe curbuf."b!"
2791 let &l:bh = bhkeep
2792 exe filtbuf."bw!"
2793 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002794
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002795 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002796 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002797 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002798 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002799 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002801 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002802
Bram Moolenaar5c736222010-01-06 20:54:52 +01002803 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002804" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002805 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002806" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002807 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002808 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002809 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002810
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002811 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002812 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002813 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002814" 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 +02002815 elseif !exists("leavemod")
2816 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002817" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002818 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002819" 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 +00002820 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002821
Bram Moolenaar9964e462007-05-05 17:54:07 +00002822" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002823endfun
2824
2825" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002826" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002827" uses NetRead to get a copy of the file into a temporarily file,
2828" then sources that file,
2829" then removes that file.
2830fun! netrw#NetSource(...)
2831" call Dfunc("netrw#NetSource() a:0=".a:0)
2832 if a:0 > 0 && a:1 == '?'
2833 " give help
2834 echomsg 'NetSource Usage:'
2835 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2836 echomsg ':Nsource fetch://machine/path uses fetch'
2837 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002838 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002839 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2840 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2841 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2842 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2843 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002844 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002845 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002846 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002847 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002848" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002849 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002850" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002851 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002852" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002853 if delete(s:netrw_tmpfile)
2854 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2855 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002856 unlet s:netrw_tmpfile
2857 else
2858 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2859 endif
2860 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002861 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002862 endif
2863" call Dret("netrw#NetSource")
2864endfun
2865
Bram Moolenaar8d043172014-01-23 14:24:41 +01002866" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002867" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2868" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002869fun! netrw#SetTreetop(iscmd,...)
2870" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2871" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002872
Bram Moolenaar85850f32019-07-19 22:05:51 +02002873 " iscmd==0: netrw#SetTreetop called using gn mapping
2874 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2875" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002876 " clear out the current tree
2877 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002878" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002879 let inittreetop= w:netrw_treetop
2880 unlet w:netrw_treetop
2881 endif
2882 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002883" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002884 unlet w:netrw_treedict
2885 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002886" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002887
Bram Moolenaar85850f32019-07-19 22:05:51 +02002888 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002889 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002890" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002891 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002892 if isdirectory(s:NetrwFile(a:1))
2893" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002894 let treedir = a:1
2895 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002896 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002897 let treedir = b:netrw_curdir."/".a:1
2898 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002899" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002900 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002901 " normally the cursor is left in the message window.
2902 " However, here this results in the directory being listed in the message window, which is not wanted.
2903 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002904 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002905 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002906 let treedir = "."
2907 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002908 endif
2909 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002910" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002911
2912 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002913 let islocal= expand("%") !~ '^\a\{3,}://'
2914" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002915
2916 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002917 if islocal
2918 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2919 else
2920 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2921 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002922
Bram Moolenaara6878372014-03-22 21:02:50 +01002923" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002924endfun
2925
Bram Moolenaar9964e462007-05-05 17:54:07 +00002926" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002927" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002928" readcmd == %r : replace buffer with newly read file
2929" == 0r : read file at top of buffer
2930" == r : read file after current line
2931" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002932fun! s:NetrwGetFile(readcmd, tfile, method)
2933" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002934
2935 " readcmd=='t': simply do nothing
2936 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002937" 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 +01002938" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002939 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002940 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002941
Bram Moolenaar9964e462007-05-05 17:54:07 +00002942 " get name of remote filename (ie. url and all)
2943 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002944" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002945
Bram Moolenaar9964e462007-05-05 17:54:07 +00002946 if exists("*NetReadFixup")
2947 " for the use of NetReadFixup (not otherwise used internally)
2948 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002949 endif
2950
Bram Moolenaar9964e462007-05-05 17:54:07 +00002951 if a:readcmd[0] == '%'
2952 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002953" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002954
2955 " rename the current buffer to the temp file (ie. tfile)
2956 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002957 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002958 else
2959 let tfile= a:tfile
2960 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002961 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002962
2963 " edit temporary file (ie. read the temporary file in)
2964 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002965" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002966 call zip#Browse(tfile)
2967 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002968" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002969 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002970 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002971" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002972 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002973 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002974" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002975 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002976 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002977" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002978 call tar#Browse(tfile)
2979 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002981 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002982 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002983" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002984 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002985 endif
2986
2987 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002988 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002989
Bram Moolenaar71badf92023-04-22 22:40:14 +01002990 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002991 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002992 " Note that isk must not include a "/" for scripts.vim
2993 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002994" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2995" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002996" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002997" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2998 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002999 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003000 filetype detect
3001" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003002 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003003" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003004 let line1 = 1
3005 let line2 = line("$")
3006
Bram Moolenaar8d043172014-01-23 14:24:41 +01003007 elseif !&ma
3008 " 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 +01003009 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003010" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003011 return
3012
Bram Moolenaar9964e462007-05-05 17:54:07 +00003013 elseif s:FileReadable(a:tfile)
3014 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003015" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003016 let curline = line(".")
3017 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003018" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003019 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003020 let line1= curline + 1
3021 let line2= line("$") - lastline + 1
3022
3023 else
3024 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003025" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3026" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003027 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003028" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003029 return
3030 endif
3031
3032 " User-provided (ie. optional) fix-it-up command
3033 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003034" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003035 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003036" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003037" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003038 endif
3039
Bram Moolenaaradc21822011-04-01 18:03:16 +02003040 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003041 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003042 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003043 endif
3044
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003045" 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 +00003046
3047 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003048" redraw!
3049
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003050" 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 +00003051" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003052endfun
3053
Bram Moolenaar9964e462007-05-05 17:54:07 +00003054" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003055" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003056" Input:
3057" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3058" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003059" b:netrw_method= 1: rcp
3060" 2: ftp + <.netrc>
3061" 3: ftp + machine, id, password, and [path]filename
3062" 4: scp
3063" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003064" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003065" 7: rsync
3066" 8: fetch
3067" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003068" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003069" g:netrw_machine= hostname
3070" b:netrw_fname = filename
3071" g:netrw_port = optional port number (for ftp)
3072" g:netrw_choice = copy of input url (choice)
3073fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003074" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003075
Bram Moolenaar251e1912011-06-19 05:09:16 +02003076 " sanity check: choice should have at least three slashes in it
3077 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3078 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3079 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003080" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003081 return
3082 endif
3083
Bram Moolenaar5c736222010-01-06 20:54:52 +01003084 " record current g:netrw_machine, if any
3085 " curmachine used if protocol == ftp and no .netrc
3086 if exists("g:netrw_machine")
3087 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003088" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003089 else
3090 let curmachine= "N O T A HOST"
3091 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003092 if exists("g:netrw_port")
3093 let netrw_port= g:netrw_port
3094 endif
3095
3096 " insure that netrw_ftp_cmd starts off every method determination
3097 " with the current g:netrw_ftp_cmd
3098 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003099
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003100 " initialization
3101 let b:netrw_method = 0
3102 let g:netrw_machine = ""
3103 let b:netrw_fname = ""
3104 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003105 let g:netrw_choice = a:choice
3106
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003107 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003108 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003109 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3110 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003111 " rcpurm : rcp://[user@]host/filename Use rcp
3112 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003113 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003114 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003115 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 " rsyncurm : rsync://host[:port]/path Use rsync
3117 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3118 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003119 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003120 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3121 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003122 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3123 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003124 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003125 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003126 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003127 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003128 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003129 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003130 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003131 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003132
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003133" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003135 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003136 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003137" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003138 let b:netrw_method = 1
3139 let userid = substitute(a:choice,rcpurm,'\1',"")
3140 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3141 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003142 if userid != ""
3143 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003145
Bram Moolenaaradc21822011-04-01 18:03:16 +02003146 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003147 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003148" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003149 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003150 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3151 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3152 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003153
Bram Moolenaar15146672011-10-20 22:22:38 +02003154 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003155 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003156" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003157 let b:netrw_method = 5
3158 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3159 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003160 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003161
Bram Moolenaaradc21822011-04-01 18:03:16 +02003162 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003163 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003164" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003165 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003166 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003167 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3168 else
3169 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3170 endif
3171 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003172
Bram Moolenaaradc21822011-04-01 18:03:16 +02003173 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003174 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003175" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003176 let b:netrw_method = 7
3177 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3178 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003179
Bram Moolenaaradc21822011-04-01 18:03:16 +02003180 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003181 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003182" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003183 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003184 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3185 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3186 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003187" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003188 if userid != ""
3189 let g:netrw_uid= userid
3190 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003191
Bram Moolenaaradc21822011-04-01 18:03:16 +02003192 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003193 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003194 call NetUserPass("ftp:".g:netrw_machine)
3195 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003196 " if there's a change in hostname, require password re-entry
3197 unlet s:netrw_passwd
3198 endif
3199 if exists("netrw_port")
3200 unlet netrw_port
3201 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003202 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003203
Bram Moolenaar446cb832008-06-24 21:56:24 +00003204 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003205 let b:netrw_method = 3
3206 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003207 let host= substitute(g:netrw_machine,'\..*$','','')
3208 if exists("s:netrw_hup[host]")
3209 call NetUserPass("ftp:".host)
3210
Nir Lichtman1e34b952024-05-08 19:19:34 +02003211 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003212" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3213" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003214 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003215 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003216" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003217 endif
3218 let b:netrw_method= 2
3219 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003220" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003221 let b:netrw_method= 2
3222 else
3223 if !exists("g:netrw_uid") || g:netrw_uid == ""
3224 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003225 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003226 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003227 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003228 endif
3229 let b:netrw_method= 3
3230 endif
3231 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003232
Bram Moolenaaradc21822011-04-01 18:03:16 +02003233 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003234 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003235" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003236 let b:netrw_method = 8
3237 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3238 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3239 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3240 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003241
Bram Moolenaaradc21822011-04-01 18:03:16 +02003242 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003243 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003244" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003245 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003246 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3247 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003248 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003249 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003250 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003251
Bram Moolenaaradc21822011-04-01 18:03:16 +02003252 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003253 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003254" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003255 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003256 let b:netrw_method = 3
3257 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3258 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003259
Bram Moolenaar9964e462007-05-05 17:54:07 +00003260 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003261 let b:netrw_method = 2
3262 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3263 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3264 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003265
Bram Moolenaaradc21822011-04-01 18:03:16 +02003266 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003267 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003268" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003269 let b:netrw_method = 9
3270 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3271 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003272
Bram Moolenaaradc21822011-04-01 18:03:16 +02003273 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003274 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003275" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003276 let b:netrw_method = 1
3277 let userid = substitute(a:choice,rcphf,'\2',"")
3278 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3279 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003280" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3281" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3282" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3283" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003284 if userid != ""
3285 let g:netrw_uid= userid
3286 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003287
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003288 " Method#10: file://user@hostname/...path-to-file {{{3
3289 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003290" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003291 let b:netrw_method = 10
3292 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003293" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003294
Bram Moolenaaradc21822011-04-01 18:03:16 +02003295 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003296 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003297 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003298 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003299 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003300 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003302 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003303
Bram Moolenaar81695252004-12-29 20:58:21 +00003304 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003305 " remove any leading [:#] from port number
3306 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3307 elseif exists("netrw_port")
3308 " retain port number as implicit for subsequent ftp operations
3309 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003310 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003311
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003312" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3313" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3314" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3315" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003316" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003317" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003318" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003319" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003320" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003321" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003322" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003323" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003324endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325
Bram Moolenaar9964e462007-05-05 17:54:07 +00003326" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003327" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003328" Usage: :call NetUserPass() -- will prompt for userid and password
3329" :call NetUserPass("uid") -- will prompt for password
3330" :call NetUserPass("uid","password") -- sets global userid and password
3331" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3332" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333fun! NetUserPass(...)
3334
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003335" call Dfunc("NetUserPass() a:0=".a:0)
3336
3337 if !exists('s:netrw_hup')
3338 let s:netrw_hup= {}
3339 endif
3340
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003342 " case: no input arguments
3343
3344 " change host and username if not previously entered; get new password
3345 if !exists("g:netrw_machine")
3346 let g:netrw_machine= input('Enter hostname: ')
3347 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003349 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350 let g:netrw_uid= input('Enter username: ')
3351 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003352 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003353 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003354
3355 " set up hup database
3356 let host = substitute(g:netrw_machine,'\..*$','','')
3357 if !exists('s:netrw_hup[host]')
3358 let s:netrw_hup[host]= {}
3359 endif
3360 let s:netrw_hup[host].uid = g:netrw_uid
3361 let s:netrw_hup[host].passwd = s:netrw_passwd
3362
3363 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003364 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003365
3366 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003367 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003368 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003369" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003370 let host = substitute(a:1,'^ftp:','','')
3371 let host = substitute(host,'\..*','','')
3372 if exists("s:netrw_hup[host]")
3373 let g:netrw_uid = s:netrw_hup[host].uid
3374 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003375" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3376" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003377 else
3378 let g:netrw_uid = input("Enter UserId: ")
3379 let s:netrw_passwd = inputsecret("Enter Password: ")
3380 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003381
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003382 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003383 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003384" 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 +02003385 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003386 if g:netrw_machine =~ '[0-9.]\+'
3387 let host= g:netrw_machine
3388 else
3389 let host= substitute(g:netrw_machine,'\..*$','','')
3390 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003391 else
3392 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003393 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003394 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003395" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003396 if exists("g:netrw_passwd")
3397 " ask for password if one not previously entered
3398 let s:netrw_passwd= g:netrw_passwd
3399 else
3400 let s:netrw_passwd = inputsecret("Enter Password: ")
3401 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003402 endif
3403
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003404" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003405 if exists("host")
3406 if !exists('s:netrw_hup[host]')
3407 let s:netrw_hup[host]= {}
3408 endif
3409 let s:netrw_hup[host].uid = g:netrw_uid
3410 let s:netrw_hup[host].passwd = s:netrw_passwd
3411 endif
3412
3413 elseif a:0 == 2
3414 let g:netrw_uid = a:1
3415 let s:netrw_passwd = a:2
3416
3417 elseif a:0 == 3
3418 " enter hostname, user-id, and password into the hup dictionary
3419 let host = substitute(a:1,'^\a\+:','','')
3420 let host = substitute(host,'\..*$','','')
3421 if !exists('s:netrw_hup[host]')
3422 let s:netrw_hup[host]= {}
3423 endif
3424 let s:netrw_hup[host].uid = a:2
3425 let s:netrw_hup[host].passwd = a:3
3426 let g:netrw_uid = s:netrw_hup[host].uid
3427 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003428" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3429" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003431
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003432" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003434
Bram Moolenaar85850f32019-07-19 22:05:51 +02003435" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003436" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003437" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003438
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003439" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003440" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3441fun! s:ExplorePatHls(pattern)
3442" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3443 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003444" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003445 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003446" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003447 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3448" call Dret("s:ExplorePatHls repat<".repat.">")
3449 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003450endfun
3451
3452" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003453" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003454" 0: (user: <mb>) bookmark current directory
3455" 1: (user: <gb>) change to the bookmarked directory
3456" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003457" 3: (browsing) records current directory history
3458" 4: (user: <u>) go up (previous) directory, using history
3459" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003460" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003461fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003462" 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 +02003463 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3464" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3465 return
3466 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003467
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003468 let ykeep = @@
3469 let curbufnr = bufnr("%")
3470
Bram Moolenaar9964e462007-05-05 17:54:07 +00003471 if a:chg == 0
3472 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003473" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003474 if exists("s:netrwmarkfilelist_{curbufnr}")
3475 call s:NetrwBookmark(0)
3476 echo "bookmarked marked files"
3477 else
3478 call s:MakeBookmark(a:curdir)
3479 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003480 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003481
KSR-Yasudaf4498252023-10-06 03:34:17 +09003482 try
3483 call s:NetrwBookHistSave()
3484 catch
3485 endtry
3486
Bram Moolenaar9964e462007-05-05 17:54:07 +00003487 elseif a:chg == 1
3488 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003489" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003490 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003491" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003492 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003493 else
3494 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3495 endif
3496
3497 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003498" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003499 let didwork= 0
3500 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003501" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003502 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003503" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003504 let cnt= 1
3505 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003506" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003507 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003508 let didwork = 1
3509 let cnt = cnt + 1
3510 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003511 endif
3512
3513 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003514 " Note: history is saved only when PerformListing is done;
3515 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3516 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003517 let first = 1
3518 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003519 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003520 while ( first || cnt != g:netrw_dirhistcnt )
3521" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003522 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003523" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003524 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003525 let didwork= 1
3526 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003527 let histcnt = histcnt + 1
3528 let first = 0
3529 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003530 if cnt < 0
3531 let cnt= cnt + g:netrw_dirhistmax
3532 endif
3533 endwhile
3534 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003535 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003536 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003537 if didwork
3538 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3539 endif
3540
3541 elseif a:chg == 3
3542 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003543" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003544 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 +02003545 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003546 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3547 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003548 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003549" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003550 endif
3551
3552 elseif a:chg == 4
3553 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003554" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003555 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003556 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3557 if g:netrw_dirhistcnt < 0
3558 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003559 endif
3560 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003561 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003562 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003563 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3564" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003565 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003566 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003567" call Decho("setl ma noro",'~'.expand("<slnum>"))
3568 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003569 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003570" call Decho("setl nomod",'~'.expand("<slnum>"))
3571" 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 +00003572 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003573" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3574 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003575 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003576 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003577 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003578 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003579 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003580 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003581 echo "Sorry, no predecessor directory exists yet"
3582 endif
3583
3584 elseif a:chg == 5
3585 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003586" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
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 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3590" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003591 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003592" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003593 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003594 sil! NetrwKeepj %d _
3595" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3596" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003597 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003598" 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 +02003599 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003600" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3601 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003602 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003603 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3604 if g:netrw_dirhistcnt < 0
3605 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003606 endif
3607 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003608 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003609 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003610 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003611 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003612 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003613
3614 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003615" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003616 if exists("s:netrwmarkfilelist_{curbufnr}")
3617 call s:NetrwBookmark(1)
3618 echo "removed marked files from bookmarks"
3619 else
3620 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003621 let iremove = v:count
3622 let dremove = g:netrw_bookmarklist[iremove - 1]
3623" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003624 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003625" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3626 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3627 echo "removed ".dremove." from g:netrw_bookmarklist"
3628" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003629 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003630" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003631
3632 try
3633 call s:NetrwBookHistSave()
3634 catch
3635 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003636 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003637 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003638 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003639 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003640" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003641endfun
3642
3643" ---------------------------------------------------------------------
3644" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003645" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003646" Sister function: s:NetrwBookHistSave()
3647fun! s:NetrwBookHistRead()
3648" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003649 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003650" call Dret("s:NetrwBookHistRead - nothing read (suppressed due to dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a").")")
Bram Moolenaarff034192013-04-24 18:51:19 +02003651 return
3652 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003653 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003654
3655 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003656 if !exists("s:netrw_initbookhist")
3657 let home = s:NetrwHome()
3658 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003659 if filereadable(s:NetrwFile(savefile))
3660" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003661 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003662 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003663
3664 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003665 if g:netrw_dirhistmax > 0
3666 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003667 if filereadable(s:NetrwFile(savefile))
3668" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003669 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003670 endif
3671 let s:netrw_initbookhist= 1
3672 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003673 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003674 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003675
Bram Moolenaar97d62492012-11-15 21:28:22 +01003676 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003677" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3678" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003679" call Dret("s:NetrwBookHistRead")
3680endfun
3681
3682" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003683" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003684" Sister function: s:NetrwBookHistRead()
3685" I used to do this via viminfo but that appears to
3686" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003687" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3688" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003689" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003690fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003691" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003692 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003693" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003694 return
3695 endif
3696
Bram Moolenaar5c736222010-01-06 20:54:52 +01003697 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003698" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003699 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003700
3701 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003702 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003703" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003704 if g:netrw_use_noswf
3705 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3706 else
3707 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3708 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003709 setl nocin noai noci magic nospell nohid wig= noaw
3710 setl ma noro write
3711 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003712 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003713
Bram Moolenaar85850f32019-07-19 22:05:51 +02003714 " rename enew'd file: .netrwhist -- no attempt to merge
3715 " record dirhistmax and current dirhistcnt
3716 " save history
3717" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003718 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003719 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003720 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3721 if g:netrw_dirhistmax > 0
3722 let lastline = line("$")
3723 let cnt = g:netrw_dirhistcnt
3724 let first = 1
3725 while ( first || cnt != g:netrw_dirhistcnt )
3726 let lastline= lastline + 1
3727 if exists("g:netrw_dirhist_{cnt}")
3728 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3729" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3730 endif
3731 let first = 0
3732 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3733 if cnt < 0
3734 let cnt= cnt + g:netrw_dirhistmax
3735 endif
3736 endwhile
3737 exe "sil! w! ".savefile
3738" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3739 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003740
Bram Moolenaar85850f32019-07-19 22:05:51 +02003741 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003742 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003743 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003744" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003745 " merge and write .netrwbook
3746 let savefile= s:NetrwHome()."/.netrwbook"
3747
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003748 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003749 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003750 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003751 for bdm in booklist
3752 if index(g:netrw_bookmarklist,bdm) == -1
3753 call add(g:netrw_bookmarklist,bdm)
3754 endif
3755 endfor
3756 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003757 endif
3758
3759 " construct and save .netrwbook
3760 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003761 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003762" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003763 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003764
3765 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003766 let bgone= bufnr("%")
3767 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003768 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003769
3770" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003771endfun
3772
3773" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003774" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3775" list of the contents of a local or remote directory. It is assumed that the
3776" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3777" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003778" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003779fun! s:NetrwBrowse(islocal,dirname)
3780 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003781" 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 +02003782" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3783" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3784" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003785
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003786 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3787 " This is useful when one edits a local file, then :e ., then :Rex
3788 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3789 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003790" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003791 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003792
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003793 " s:NetrwBrowse : initialize history {{{3
3794 if !exists("s:netrw_initbookhist")
3795 NetrwKeepj call s:NetrwBookHistRead()
3796 endif
3797
3798 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003799 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003800 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003801" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003802 else
3803 let dirname= a:dirname
3804 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003805
Bram Moolenaar85850f32019-07-19 22:05:51 +02003806 " repoint t:netrw_lexbufnr if appropriate
3807 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3808" call Decho("set repointlexbufnr to true!")
3809 let repointlexbufnr= 1
3810 endif
3811
3812 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003813 if exists("s:netrw_skipbrowse")
3814 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003815" 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 +01003816" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003817 return
3818 endif
3819 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003820 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003821" call Dret("s:NetrwBrowse : missing shellescape()")
3822 return
3823 endif
3824 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003825 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003826" call Dret("s:NetrwBrowse : missing fnameescape()")
3827 return
3828 endif
3829
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003830 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003831 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003832
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003833 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003834 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3835 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3836" call Decho("clearing marked files",'~'.expand("<slnum>"))
3837 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3838 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003839 endif
3840
3841 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003842 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003843" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3844" 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 +02003845 if s:NetrwLcd(dirname)
3846" call Dret("s:NetrwBrowse : lcd failure")
3847 return
3848 endif
3849 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003850" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003851
Bram Moolenaar5c736222010-01-06 20:54:52 +01003852 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003853 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003854" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003855 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003856" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003857 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003858 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003859 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003860" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003861
3862 " remove any filetype indicator from end of dirname, except for the
3863 " "this is a directory" indicator (/).
3864 " There shouldn't be one of those here, anyway.
3865 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003866" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003867 call s:RemotePathAnalysis(dirname)
3868
3869 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3870 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003871 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003872 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003873" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003874 let b:netrw_curdir = dirname
3875 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003876 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003877 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3878 sil call netrw#NetRead(2,url)
3879 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003880" call Decho("url<".url.">",'~'.expand("<slnum>"))
3881" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3882" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003883 if s:path =~ '.bz2'
3884 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3885 elseif s:path =~ '.gz'
3886 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3887 elseif s:path =~ '.gz'
3888 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3889 else
3890 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3891 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003892 endif
3893
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003894 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003895 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003896 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003897" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003898 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003899" 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 +00003900
Bram Moolenaar446cb832008-06-24 21:56:24 +00003901" call Dret("s:NetrwBrowse : file<".s:fname.">")
3902 return
3903 endif
3904
Bram Moolenaaradc21822011-04-01 18:03:16 +02003905 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003906 call s:UseBufWinVars()
3907
3908 " set up some variables {{{3
3909 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003910 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003911 let s:last_sort_by = g:netrw_sort_by
3912
3913 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003914 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003915
Bram Moolenaar97d62492012-11-15 21:28:22 +01003916 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003917" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003918 let svpos = winsaveview()
3919" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003920 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003921
Bram Moolenaar446cb832008-06-24 21:56:24 +00003922 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003923 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3924 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3925" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3926" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3927 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3928 else
3929" " call Decho("2match none",'~'.expand("<slnum>"))
3930 2match none
3931 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003932 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003933 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003934 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003935" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003936 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003937" 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 +01003938" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003939 return
3940 endif
3941
3942 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003943" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003944 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003945 if b:netrw_curdir =~ '[/\\]$'
3946 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3947 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003948 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003949 let b:netrw_curdir= b:netrw_curdir."/"
3950 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003951 if b:netrw_curdir == ''
3952 if has("amiga")
3953 " On the Amiga, the empty string connotes the current directory
3954 let b:netrw_curdir= getcwd()
3955 else
3956 " under unix, when the root directory is encountered, the result
3957 " from the preceding substitute is an empty string.
3958 let b:netrw_curdir= '/'
3959 endif
3960 endif
3961 if !a:islocal && b:netrw_curdir !~ '/$'
3962 let b:netrw_curdir= b:netrw_curdir.'/'
3963 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003964" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003965
3966 " ------------
3967 " (local only) {{{3
3968 " ------------
3969 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003970" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003971
3972 " Set up ShellCmdPost handling. Append current buffer to browselist
3973 call s:LocalFastBrowser()
3974
3975 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3976 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003977" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3978" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003979 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003980 if s:NetrwLcd(b:netrw_curdir)
3981" call Dret("s:NetrwBrowse : lcd failure")
3982 return
3983 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003984 endif
3985 endif
3986
3987 " --------------------------------
3988 " remote handling: {{{3
3989 " --------------------------------
3990 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003991" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003992
Bram Moolenaar97d62492012-11-15 21:28:22 +01003993 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003994" 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 +02003995 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003996 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003997" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003998 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3999 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4000 if dirname !~ '/$'
4001 let dirname= dirname.'/'
4002 endif
4003 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004004" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004005 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004006 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004007" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004008 endif
4009
4010 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4011 if dirname !~ dirpat
4012 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004013 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004014 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004015 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004016" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004017 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004018" 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 +00004019" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4020 return
4021 endif
4022 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004023" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004024 endif " (additional remote handling)
4025
Bram Moolenaar85850f32019-07-19 22:05:51 +02004026 " -------------------------------
4027 " Perform Directory Listing: {{{3
4028 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004029 NetrwKeepj call s:NetrwMaps(a:islocal)
4030 NetrwKeepj call s:NetrwCommands(a:islocal)
4031 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004032
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004033 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004034 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004035" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4036
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004037 " If there is a rexposn: restore position with rexposn
4038 " Otherwise : set rexposn
4039 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004040" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4041 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4042 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4043 NetrwKeepj exe w:netrw_bannercnt
4044 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004045 else
4046 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4047 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004048 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004049 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004050" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004051 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004052 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004053
Bram Moolenaar85850f32019-07-19 22:05:51 +02004054 " repoint t:netrw_lexbufnr if appropriate
4055 if exists("repointlexbufnr")
4056 let t:netrw_lexbufnr= bufnr("%")
4057" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4058 endif
4059
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004060 " restore position
4061 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004062" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4063 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004064 endif
4065
Bram Moolenaara6878372014-03-22 21:02:50 +01004066 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004067 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4068 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004069" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4070" 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 +02004071" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004072 return
4073endfun
4074
4075" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004076" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4077" may not apply correctly; ie. netrw's idea of the current directory may
4078" differ from vim's. This function insures that netrw's idea of the current
4079" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004080" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004081fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004082" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4083" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4084" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4085" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4086" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004087
4088 " clean up any leading treedepthstring
4089 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4090 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004091" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004092 else
4093 let fname= a:fname
4094 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004095
4096 if g:netrw_keepdir
4097 " vim's idea of the current directory possibly may differ from netrw's
4098 if !exists("b:netrw_curdir")
4099 let b:netrw_curdir= getcwd()
4100 endif
4101
Nir Lichtman1e34b952024-05-08 19:19:34 +02004102 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004103 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004104 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004105 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004106" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004107 else
4108 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004109 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004110" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004111 endif
4112
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004113 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004114 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004115 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004116" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004117 else
4118 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004119 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004120" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004121 endif
4122 else
4123 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004124 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004125" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4126" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4127" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004128 endif
4129
Bram Moolenaar85850f32019-07-19 22:05:51 +02004130" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004131 return ret
4132endfun
4133
4134" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004135" s:NetrwFileInfo: supports qf (query for file information) {{{2
4136fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004137" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004138 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004139 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004140 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004141 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004142 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004143 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004144 let lsopt= "-lsadh --si"
4145 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004146" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004147 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004148
4149 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004150 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004151" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004152
Bram Moolenaara6878372014-03-22 21:02:50 +01004153 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004154 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004155" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004156
4157 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004158 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004159" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004160
Bram Moolenaar446cb832008-06-24 21:56:24 +00004161 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004162" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004163 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004165 endif
4166 else
4167 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004168" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4169 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004170 let fname= substitute(a:fname,".$","","")
4171 else
4172 let fname= a:fname
4173 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004174 let t = getftime(s:NetrwFile(fname))
4175 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004176 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004177 let sz= s:NetrwHumanReadable(sz)
4178 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004179 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4180" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004181 endif
4182 else
4183 echo "sorry, \"qf\" not supported yet for remote files"
4184 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004185 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004186" call Dret("s:NetrwFileInfo")
4187endfun
4188
4189" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004190" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4191fun! s:NetrwFullPath(filename)
4192" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4193 let filename= a:filename
4194 if filename !~ '^/'
4195 let filename= resolve(getcwd().'/'.filename)
4196 endif
4197 if filename != "/" && filename =~ '/$'
4198 let filename= substitute(filename,'/$','','')
4199 endif
4200" " call Dret("s:NetrwFullPath <".filename.">")
4201 return filename
4202endfun
4203
4204" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004205" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004206" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004207" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004208" 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 +00004209fun! s:NetrwGetBuffer(islocal,dirname)
4210" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004211" 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 +02004212" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4213" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004214 let dirname= a:dirname
4215
4216 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004217" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004218 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004219" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004220 let s:netrwbuf= {}
4221 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004222" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4223" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4224
4225 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4226 let bufnum = -1
4227
4228 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4229 if has_key(s:netrwbuf,"NetrwTreeListing")
4230 let bufnum= s:netrwbuf["NetrwTreeListing"]
4231 else
4232 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4233 endif
4234" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4235 if !bufexists(bufnum)
4236 call remove(s:netrwbuf,"NetrwTreeListing"])
4237 let bufnum= -1
4238 endif
4239 elseif bufnr("NetrwTreeListing") != -1
4240 let bufnum= bufnr("NetrwTreeListing")
4241" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4242 else
4243" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4244 let bufnum= -1
4245 endif
4246
4247 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004248 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004249" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004250 if !bufexists(bufnum)
4251 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4252 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004253 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004254
Bram Moolenaar446cb832008-06-24 21:56:24 +00004255 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004256" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004257 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004258 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004259" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4260
Bram Moolenaar71badf92023-04-22 22:40:14 +01004261 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004262 " IF the buffer already has the desired name
4263 " AND it is empty
4264 let curbuf = bufname("%")
4265 if curbuf == '.'
4266 let curbuf = getcwd()
4267 endif
4268" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004269" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004270" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4271" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4272" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4273" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4274 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004275" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4276 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004277 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004278" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004279 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004280 " 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 +00004281
4282 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004283 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004284" 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 +00004285 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004286" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004287 " name the buffer
4288 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4289 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004290" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004291 let w:netrw_treebufnr = bufnr("%")
4292 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004293 if g:netrw_use_noswf
4294 setl nobl bt=nofile noswf
4295 else
4296 setl nobl bt=nofile
4297 endif
4298 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4299 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4300 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4301 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004302" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004303 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004304 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004305 " enter the new buffer into the s:netrwbuf dictionary
4306 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4307" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4308" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004309 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004310" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004311
4312 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004313" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004314 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004315 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004316 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004317
4318 if &ft == "netrw"
4319" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4320 exe "sil! NetrwKeepj noswapfile b ".bufnum
4321" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004322 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004323" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4324 call s:NetrwEditBuf(bufnum)
4325" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004326 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004327" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004328 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004329 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004330 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004331
4332 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004333 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004334
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004335 if line("$") <= 1 && getline(1) == ""
4336 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004337 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004338" 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>"))
4339" 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 +01004340" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4341 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004342
Bram Moolenaar97d62492012-11-15 21:28:22 +01004343 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004344" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004345 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004346 sil NetrwKeepj %d _
4347" 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>"))
4348" 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 +01004349" 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 +00004350 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004351
Bram Moolenaar446cb832008-06-24 21:56:24 +00004352 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004353" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4354" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004355 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004356 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004357 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004358" 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>"))
4359" 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 +01004360" 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 +00004361 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004362
Bram Moolenaar446cb832008-06-24 21:56:24 +00004363 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004364" 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>"))
4365" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4366" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004367 return 1
4368 endif
4369 endif
4370
4371 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4372 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4373 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4374 " med 1 D H
4375 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004376" 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 +00004377 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004378 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004379 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004380
4381 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004382" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4383" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4384 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004385
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004386" 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>"))
4387" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4388" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004389 return 0
4390endfun
4391
4392" ---------------------------------------------------------------------
4393" s:NetrwGetcwd: get the current directory. {{{2
4394" Change backslashes to forward slashes, if any.
4395" If doesc is true, escape certain troublesome characters
4396fun! s:NetrwGetcwd(doesc)
4397" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4398 let curdir= substitute(getcwd(),'\\','/','ge')
4399 if curdir !~ '[\/]$'
4400 let curdir= curdir.'/'
4401 endif
4402 if a:doesc
4403 let curdir= fnameescape(curdir)
4404 endif
4405" call Dret("NetrwGetcwd <".curdir.">")
4406 return curdir
4407endfun
4408
4409" ---------------------------------------------------------------------
4410" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4411fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004412" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4413" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4414 let keepsol= &l:sol
4415 setl nosol
4416
Bram Moolenaar446cb832008-06-24 21:56:24 +00004417 call s:UseBufWinVars()
4418
4419 " insure that w:netrw_liststyle is set up
4420 if !exists("w:netrw_liststyle")
4421 if exists("g:netrw_liststyle")
4422 let w:netrw_liststyle= g:netrw_liststyle
4423 else
4424 let w:netrw_liststyle= s:THINLIST
4425 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004426" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004427 endif
4428
4429 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4430 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004431" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004432 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004433 let dirname= "./"
4434 let curline= getline('.')
4435
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004436 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004437 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004438 let s:netrw_skipbrowse= 1
4439 echo 'Pressing "s" also works'
4440
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004441 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004442 let s:netrw_skipbrowse= 1
4443 echo 'Press "S" to edit sorting sequence'
4444
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004445 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004446 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004447 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004448
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004449 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004450 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004451 let s:netrw_skipbrowse= 1
4452 echo 'Pressing "a" also works'
4453
4454 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004455 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004456 endif
4457
4458 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004459" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004460 NetrwKeepj norm! 0
4461 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004462
4463 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004464" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004465 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004466 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4467
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004468 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004469" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004470 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004471 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004472
4473 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004474" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004475 let dirname= getline('.')
4476
4477 if !exists("b:netrw_cpf")
4478 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004479 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 +01004480 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004481" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004482 endif
4483
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004484" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004485 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004486" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4487" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004488 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004489 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004490 else
4491 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004492 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004493 endif
4494 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004495 let eofname= filestart + b:netrw_cpf + 1
4496 if eofname <= col("$")
4497 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004498 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004499 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004500 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004501 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004502 let dirname = @a
4503 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004504" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004505 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004506" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004507 endif
4508
4509 " symlinks are indicated by a trailing "@". Remove it before further processing.
4510 let dirname= substitute(dirname,"@$","","")
4511
4512 " executables are indicated by a trailing "*". Remove it before further processing.
4513 let dirname= substitute(dirname,"\*$","","")
4514
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004515 let &l:sol= keepsol
4516
Bram Moolenaar446cb832008-06-24 21:56:24 +00004517" call Dret("s:NetrwGetWord <".dirname.">")
4518 return dirname
4519endfun
4520
4521" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004522" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4523" g:netrw_bufsettings will be used after the listing is produced.
4524" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004525fun! s:NetrwListSettings(islocal)
4526" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004527" 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 +00004528 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004529" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4530 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4531 setl bt=nofile nobl ma nonu nowrap noro nornu
4532 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004533 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004534 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004535 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004536" call Dredir("ls!","s:NetrwListSettings")
4537" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004538 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004539 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004540 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004541 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004542 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004543 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004544 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004545" 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 +00004546" call Dret("s:NetrwListSettings")
4547endfun
4548
4549" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004550" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004551" islocal=0: remote browsing
4552" =1: local browsing
4553fun! s:NetrwListStyle(islocal)
4554" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004555
Bram Moolenaar97d62492012-11-15 21:28:22 +01004556 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004557 let fname = s:NetrwGetWord()
4558 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004559 let svpos = winsaveview()
4560" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004561 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004562" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4563" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4564" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004565
Bram Moolenaar85850f32019-07-19 22:05:51 +02004566 " repoint t:netrw_lexbufnr if appropriate
4567 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4568" call Decho("set repointlexbufnr to true!")
4569 let repointlexbufnr= 1
4570 endif
4571
Bram Moolenaar446cb832008-06-24 21:56:24 +00004572 if w:netrw_liststyle == s:THINLIST
4573 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004574" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004575 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4576
4577 elseif w:netrw_liststyle == s:LONGLIST
4578 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004579" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004580 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4581
4582 elseif w:netrw_liststyle == s:WIDELIST
4583 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004584" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004585 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4586
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004587 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004588" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004589 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4590
4591 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004592 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004593 let g:netrw_liststyle = s:THINLIST
4594 let w:netrw_liststyle = g:netrw_liststyle
4595 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4596 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004597 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004598" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004599
4600 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004601" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4602 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004603 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004604" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004605 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004606" 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 +00004607
4608 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004609" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004610 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004611 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004612
Bram Moolenaar85850f32019-07-19 22:05:51 +02004613 " repoint t:netrw_lexbufnr if appropriate
4614 if exists("repointlexbufnr")
4615 let t:netrw_lexbufnr= bufnr("%")
4616" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4617 endif
4618
Bram Moolenaar13600302014-05-22 18:26:40 +02004619 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004620" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4621 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004622 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004623
4624" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4625endfun
4626
4627" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004628" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4629fun! s:NetrwBannerCtrl(islocal)
4630" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4631
Bram Moolenaar97d62492012-11-15 21:28:22 +01004632 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004633 " toggle the banner (enable/suppress)
4634 let g:netrw_banner= !g:netrw_banner
4635
4636 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004637 let svpos= winsaveview()
4638" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004639 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4640
4641 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004642 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4643 let fname= s:NetrwGetWord()
4644 sil NetrwKeepj $
4645 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4646" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4647 if result <= 0 && exists("w:netrw_bannercnt")
4648 exe "NetrwKeepj ".w:netrw_bannercnt
4649 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004650 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004651 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004652" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4653endfun
4654
4655" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004656" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4657"
4658" No bang: enters files/directories into Netrw's bookmark system
4659" No argument and in netrw buffer:
4660" if there are marked files: bookmark marked files
4661" otherwise : bookmark file/directory under cursor
4662" No argument and not in netrw buffer: bookmarks current open file
4663" Has arguments: globs them individually and bookmarks them
4664"
4665" With bang: deletes files/directories from Netrw's bookmark system
4666fun! s:NetrwBookmark(del,...)
4667" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4668 if a:0 == 0
4669 if &ft == "netrw"
4670 let curbufnr = bufnr("%")
4671
4672 if exists("s:netrwmarkfilelist_{curbufnr}")
4673 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004674" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004675 let svpos = winsaveview()
4676" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004677 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004678 for fname in s:netrwmarkfilelist_{curbufnr}
4679 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4680 endfor
4681 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4682 call s:NetrwUnmarkList(curbufnr,curdir)
4683 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004684" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4685 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004686 else
4687 let fname= s:NetrwGetWord()
4688 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4689 endif
4690
4691 else
4692 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004693" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004694 let fname= expand("%")
4695 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4696 endif
4697
4698 else
4699 " bookmark specified files
4700 " attempts to infer if working remote or local
4701 " by deciding if the current file begins with an url
4702 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004703 let islocal= expand("%") !~ '^\a\{3,}://'
4704" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004705 let i = 1
4706 while i <= a:0
4707 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004708 if v:version > 704 || (v:version == 704 && has("patch656"))
4709 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004710 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004711 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004712 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004713 else
4714 let mbfiles= [a:{i}]
4715 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004716" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004717 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004718" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004719 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4720 endfor
4721 let i= i + 1
4722 endwhile
4723 endif
4724
4725 " update the menu
4726 call s:NetrwBookmarkMenu()
4727
4728" call Dret("s:NetrwBookmark")
4729endfun
4730
4731" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004732" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4733" .2.[cnt] for bookmarks, and
4734" .3.[cnt] for history
4735" (see s:NetrwMenu())
4736fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004737 if !exists("s:netrw_menucnt")
4738 return
4739 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004740" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004741
4742 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004743 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004744 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004745" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004746 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4747 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004748 endif
4749 if !exists("s:netrw_initbookhist")
4750 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004751 endif
4752
4753 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004754 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004755 let cnt= 1
4756 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004757" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004758 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004759
4760 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004761 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004762
4763 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004764 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 +01004765 let cnt= cnt + 1
4766 endfor
4767
4768 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004769
4770 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004771 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004772 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004773 let first = 1
4774 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004775 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004776 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004777 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004778 if exists("g:netrw_dirhist_{cnt}")
4779 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004780" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004781 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4782 endif
4783 let first = 0
4784 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4785 if cnt < 0
4786 let cnt= cnt + g:netrw_dirhistmax
4787 endif
4788 endwhile
4789 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004790
Bram Moolenaar9964e462007-05-05 17:54:07 +00004791 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004792" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004793endfun
4794
4795" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004796" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4797" directory and a new directory name. Also, if the
4798" "new directory name" is actually a file,
4799" NetrwBrowseChgDir() edits the file.
4800fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004801" 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 +01004802" 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 +00004803
Bram Moolenaar97d62492012-11-15 21:28:22 +01004804 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004805 if !exists("b:netrw_curdir")
4806 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4807 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004808 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004809" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4810" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004811" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004812" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004813 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004814 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004815" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004816
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004817 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004818" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004819 call s:SavePosn(s:netrw_posn)
4820 NetrwKeepj call s:NetrwOptionsSave("s:")
4821 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004822 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004823 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004824 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004825 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004826 endif
4827 let newdir = a:newdir
4828 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004829 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004830" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004831" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004832" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004833
4834 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004835" 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 +01004836 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004837" 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 +01004838 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004839 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004840" 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 +01004841 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004842" 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 +02004843 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004844 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004845 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004846 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004847" 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 +01004848 endif
4849 endif
4850" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004851" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004852 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004853
Bram Moolenaar446cb832008-06-24 21:56:24 +00004854 " set up o/s-dependent directory recognition pattern
4855 if has("amiga")
4856 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004857 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004858 let dirpat= '[\/]$'
4859 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004860" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004861
4862 if dirname !~ dirpat
4863 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004864 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004865 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004866" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004867 endif
4868
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004869" 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 +01004870 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004871 " ------------------------------
4872 " NetrwBrowseChgDir: edit a file {{{3
4873 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004874" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004875
Bram Moolenaar97d62492012-11-15 21:28:22 +01004876 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004877 let s:rexposn_{bufnr("%")}= winsaveview()
4878" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004879" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4880" 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 +01004881
Bram Moolenaar446cb832008-06-24 21:56:24 +00004882 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004883" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4884" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004885" let newdir = s:NetrwTreePath(s:netrw_treetop)
4886" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004887 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004888 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4889" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4890 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004891 if dirname =~ '/$'
4892 let dirname= dirname.newdir
4893 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004894 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004895 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004896" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4897" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004898 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004899" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004900 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004901 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004902 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004903 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004904" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004905 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004907" 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 +02004908 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004909 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004910 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004911" " 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 +01004912 if type(g:netrw_browse_split) == 3
4913 " open file in server
4914 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004915" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004916 call s:NetrwServerEdit(a:islocal,dirname)
4917" call Dret("s:NetrwBrowseChgDir")
4918 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004919
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004920 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004921 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004922" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004923 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4924 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004925 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004926 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004927 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004928 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004929
Bram Moolenaar446cb832008-06-24 21:56:24 +00004930 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004931 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004932" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004933 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4934 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004935 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004936 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004937 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004938 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004939
Bram Moolenaar446cb832008-06-24 21:56:24 +00004940 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004941 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004942" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004943 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004944 if !exists("b:netrw_curdir")
4945 let b:netrw_curdir= getcwd()
4946 endif
4947 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004948
Bram Moolenaar446cb832008-06-24 21:56:24 +00004949 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004950 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004951" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004952 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004953 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004954" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004955 return
4956 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004957 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004958
Bram Moolenaar9964e462007-05-05 17:54:07 +00004959 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004960 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004961" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004962 call s:NetrwMenu(0)
4963 " optional change to window
4964 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004965" 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 +02004966 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004967 " if g:netrw_chgwin is set to one more than the last window, then
4968 " vertically split the last window to make that window available.
4969 let curwin= winnr()
4970 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4971 vs
4972 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004973 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004974 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004975 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004976 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004977 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004978
Bram Moolenaar9964e462007-05-05 17:54:07 +00004979 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004980
Bram Moolenaar446cb832008-06-24 21:56:24 +00004981 " the point where netrw actually edits the (local) file
4982 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004983 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004984 if !&mod
4985 " if e the new file would fail due to &mod, then don't change any of the flags
4986 let dolockout= 1
4987 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004988 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004989" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004990 " some like c-^ to return to the last edited file
4991 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004992 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4993 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004994 call s:NetrwEditFile("e","",dirname)
4995" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004996 " COMBAK -- cuc cul related
4997 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004998 if &hidden || &bufhidden == "hide"
4999 " file came from vim's hidden storage. Don't "restore" options with it.
5000 let dorestore= 0
5001 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005002 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005003" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005004 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005005
5006 " handle g:Netrw_funcref -- call external-to-netrw functions
5007 " This code will handle g:Netrw_funcref as an individual function reference
5008 " or as a list of function references. It will ignore anything that's not
5009 " a function reference. See :help Funcref for information about function references.
5010 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005011" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005012 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005013" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005014 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005015 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005016" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005017 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005018 if type(Fncref) == 2
5019 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005020 endif
5021 endfor
5022 endif
5023 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005024 endif
5025
5026 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005027 " ----------------------------------------------------
5028 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5029 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005030" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005031 let dirname = newdir
5032 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005033 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005034 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005035
5036 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005037 " ---------------------------------------------
5038 " NetrwBrowseChgDir: refresh the directory list {{{3
5039 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005040" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005041 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005042 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005043
5044 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005045 " --------------------------------------
5046 " NetrwBrowseChgDir: go up one directory {{{3
5047 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005048" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005049
5050 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5051 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005052" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5053" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005054 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005055 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005056 endif
5057
5058 if has("amiga")
5059 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005060" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005061 if a:islocal
5062 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5063 let dirname= substitute(dirname,'/$','','')
5064 else
5065 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5066 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005067" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005068
Nir Lichtman1e34b952024-05-08 19:19:34 +02005069 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005070 " windows
5071 if a:islocal
5072 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5073 if dirname == ""
5074 let dirname= '/'
5075 endif
5076 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005077 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005078 endif
5079 if dirname =~ '^\a:$'
5080 let dirname= dirname.'/'
5081 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005082" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005083
Bram Moolenaar446cb832008-06-24 21:56:24 +00005084 else
5085 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005086" 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 +00005087 if a:islocal
5088 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5089 if dirname == ""
5090 let dirname= '/'
5091 endif
5092 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005093 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005094 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005095" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005096 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005097 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005098 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005099
5100 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005101 " --------------------------------------
5102 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5103 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005104" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005105 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5106" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005107 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005108 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005109" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5110 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005111 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005112 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005113" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005114 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005115 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005116" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005117
5118 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005119" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005120 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005121" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005122 let haskey= 1
5123 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005124" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005125 endif
5126
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005127 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005128" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005129 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005130 if has_key(w:netrw_treedict,treedir."/")
5131 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005132" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005133 let haskey = 1
5134 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005135" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005136 endif
5137 endif
5138
5139 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005140" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005141 if !haskey && treedir =~ '/$'
5142 let treedir= substitute(treedir,'/$','','')
5143 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005144" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005145 let haskey = 1
5146 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005147" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005148 endif
5149 endif
5150
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005151" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005152 if haskey
5153 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005154" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005155 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005156" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5157" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005158 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005159 else
5160 " go down one directory
5161 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005162" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5163" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005165 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005166" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005167 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005168
5169 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005170 " ----------------------------------------
5171 " NetrwBrowseChgDir: Go down one directory {{{3
5172 " ----------------------------------------
5173 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005174" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005175 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005176 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005177 endif
5178
Bram Moolenaar97d62492012-11-15 21:28:22 +01005179 " --------------------------------------
5180 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5181 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005182 if dorestore
5183 " dorestore is zero'd when a local file was hidden or bufhidden;
5184 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005185" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005186 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005187" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005188" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005189 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005190 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005191" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005192 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005193" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5194" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005195 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005196" 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 +02005197 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005198" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5199" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005200 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005201" 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 +02005202 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005203 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005204 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005205 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005206
Bram Moolenaar446cb832008-06-24 21:56:24 +00005207" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5208 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005209endfun
5210
5211" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005212" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5213" for thin, long, and wide: cursor placed just after banner
5214" for tree, keeps cursor on current filename
5215fun! s:NetrwBrowseUpDir(islocal)
5216" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005217 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5218 " this test needed because occasionally this function seems to be incorrectly called
5219 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005220 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005221 " directories.
5222" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5223 return
5224 endif
5225
Bram Moolenaara6878372014-03-22 21:02:50 +01005226 norm! 0
5227 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005228" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005229 let curline= getline(".")
5230 let swwline= winline() - 1
5231 if exists("w:netrw_treetop")
5232 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005233 elseif exists("b:netrw_curdir")
5234 let w:netrw_treetop= b:netrw_curdir
5235 else
5236 let w:netrw_treetop= getcwd()
5237 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005238 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005239 let curfile = getline(".")
5240 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005241 if a:islocal
5242 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5243 else
5244 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5245 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005246" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5247" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5248 if w:netrw_treetop == '/'
5249 keepj call search('^\M'.curfile,"w")
5250 elseif curfile == '../'
5251 keepj call search('^\M'.curfile,"wb")
5252 else
5253" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5254 while 1
5255 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5256 let treepath= s:NetrwTreePath(w:netrw_treetop)
5257" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5258 if treepath == curpath
5259 break
5260 endif
5261 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005262 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005263
Bram Moolenaara6878372014-03-22 21:02:50 +01005264 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005265" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005266 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005267 if exists("b:netrw_curdir")
5268 let curdir= b:netrw_curdir
5269 else
5270 let curdir= expand(getcwd())
5271 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005272 if a:islocal
5273 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5274 else
5275 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5276 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005277 call s:RestorePosn(s:netrw_posn)
5278 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005279 let curdir= '\<'. escape(curdir, '~'). '/'
5280 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005281 endif
5282" call Dret("s:NetrwBrowseUpDir")
5283endfun
5284
5285" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005286" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005287" given filename; typically this means given their extension.
5288" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005289fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005290 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005291" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005292
Bram Moolenaar91359012019-11-30 17:57:03 +01005293 if a:remote == 0 && isdirectory(a:fname)
5294 " if its really just a local directory, then do a "gf" instead
5295" 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 +01005296" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5297 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005298" call Dret("netrw#BrowseX")
5299 return
5300 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5301 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5302" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5303" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5304" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5305" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5306 norm! gf
5307" call Dret("netrw#BrowseX")
5308 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005309 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005310" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005311
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005312 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5313 let remote = a:remote
5314 else
5315 let remote = 0
5316 endif
5317
Bram Moolenaar97d62492012-11-15 21:28:22 +01005318 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005319 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005320" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005321
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005322 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5323 let awkeep = &aw
5324 set noaw
5325
Bram Moolenaar5c736222010-01-06 20:54:52 +01005326 " special core dump handler
5327 if a:fname =~ '/core\(\.\d\+\)\=$'
5328 if exists("g:Netrw_corehandler")
5329 if type(g:Netrw_corehandler) == 2
5330 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005331" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005332 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005333 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005334 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005335" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005336 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005337 if type(Fncref) == 2
5338 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005339 endif
5340 endfor
5341 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005342" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005343 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005344 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005345 let &aw= awkeep
5346" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005347 return
5348 endif
5349 endif
5350
Bram Moolenaar446cb832008-06-24 21:56:24 +00005351 " set up the filename
5352 " (lower case the extension, make a local copy of a remote file)
5353 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005354 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005355 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005356 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005357 if exten =~ "[\\/]"
5358 let exten= ""
5359 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005360" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005361
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005362 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005363 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005364" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005365 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005366 call netrw#NetRead(3,a:fname)
5367 " attempt to rename tempfile
5368 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005369 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005370" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5371" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005372 if s:netrw_tmpfile != newname && newname != ""
5373 if rename(s:netrw_tmpfile,newname) == 0
5374 " renaming succeeded
5375" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5376 let fname= newname
5377 else
5378 " renaming failed
5379" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5380 let fname= s:netrw_tmpfile
5381 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005382 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005383 let fname= s:netrw_tmpfile
5384 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005385 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005386" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005387 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005388 " special ~ handler for local
5389 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005390" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5391 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005392 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005393 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005394" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5395" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005396
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005397 " set up redirection (avoids browser messages)
5398 " by default, g:netrw_suppress_gx_mesg is true
5399 if g:netrw_suppress_gx_mesg
5400 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005401 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005402 let redir= substitute(&srr,"%s","nul","")
5403 else
5404 let redir= substitute(&srr,"%s","/dev/null","")
5405 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005406 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005407 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005408 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005409 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005410 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005411 else
5412 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005413 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005414" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005415
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005416 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005417 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005418" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005419 if g:netrw_browsex_viewer =~ '\s'
5420 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5421 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5422 let oviewer = ''
5423 let cnt = 1
5424 while !executable(viewer) && viewer != oviewer
5425 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5426 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5427 let cnt = cnt + 1
5428 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005429" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005430 endwhile
5431 else
5432 let viewer = g:netrw_browsex_viewer
5433 let viewopt = ""
5434 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005435" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005436 endif
5437
5438 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005439" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005440 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005441" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005442 let ret= netrwFileHandlers#Invoke(exten,fname)
5443
5444 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005445" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005446 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005447 let ret= v:shell_error
5448
Nir Lichtman1e34b952024-05-08 19:19:34 +02005449 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005450" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005451 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005452 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005453 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005454 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005455 else
5456 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5457 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005458 let ret= v:shell_error
5459
Bram Moolenaar97d62492012-11-15 21:28:22 +01005460 elseif has("win32unix")
5461 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005462" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005463 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005464" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005465 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005466 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005467" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005468 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005469 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005470" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005471 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005472 else
5473 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5474 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005475 let ret= v:shell_error
5476
Bram Moolenaar85850f32019-07-19 22:05:51 +02005477 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005478" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5479 if a:fname =~ '^https\=://'
5480 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5481 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005482" call Decho("fname<".fname.">")
5483" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005484 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5485
5486 else
5487 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5488 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005489 let ret= v:shell_error
5490
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005491 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5492" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5493 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5494 let ret= v:shell_error
5495
5496 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5497" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5498 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5499 let ret= v:shell_error
5500
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005501 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005502" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005503 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005504 let ret= v:shell_error
5505
5506 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005507" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005508 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005509 let ret= v:shell_error
5510
5511 else
5512 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005513" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005514 let ret= netrwFileHandlers#Invoke(exten,fname)
5515 endif
5516
5517 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5518 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005519" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005520 let ret= netrwFileHandlers#Invoke(exten,fname)
5521 endif
5522
Bram Moolenaarc236c162008-07-13 17:41:49 +00005523 " restoring redraw! after external file handlers
5524 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005525
5526 " cleanup: remove temporary file,
5527 " delete current buffer if success with handler,
5528 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005529 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005530 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005531" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005532"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005533" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005534" endif
5535
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005536 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005537 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005538 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005539 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005540 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005541 if use_ctrlo
5542 exe "sil! NetrwKeepj norm! \<c-o>"
5543 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005544 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005545" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005546 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005547 let @@ = ykeep
5548 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005549
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005550" call Dret("netrw#BrowseX")
5551endfun
5552
5553" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005554" netrw#GX: gets word under cursor for gx support {{{2
5555" See also: netrw#BrowseXVis
5556" netrw#BrowseX
5557fun! netrw#GX()
5558" call Dfunc("netrw#GX()")
5559 if &ft == "netrw"
5560 let fname= s:NetrwGetWord()
5561 else
5562 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5563 endif
5564" call Dret("netrw#GX <".fname.">")
5565 return fname
5566endfun
5567
5568" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005569" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5570fun! netrw#BrowseXVis()
5571" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005572 let akeep = @a
5573 norm! gv"ay
5574 let gxfile= @a
5575 let @a = akeep
5576 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005577" call Dret("netrw#BrowseXVis")
5578endfun
5579
5580" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005581" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5582" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5583" to become an unlisted buffer, so in that case don't bwipe it.
5584fun! s:NetrwBufRename(newname)
5585" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5586" call Dredir("ls!","s:NetrwBufRename (before rename)")
5587 let oldbufname= bufname(bufnr("%"))
5588" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5589
5590 if oldbufname != a:newname
5591" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5592 let b:junk= 1
5593" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5594 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005595" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005596 let oldbufnr= bufnr(oldbufname)
5597" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5598" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5599 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5600" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5601 exe "bwipe! ".oldbufnr
5602" else " Decho
5603" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005604" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5605" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5606" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005607 endif
5608" call Dredir("ls!","s:NetrwBufRename (after rename)")
5609" else " Decho
5610" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5611 endif
5612
5613" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5614endfun
5615
5616" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005617" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005618fun! netrw#CheckIfRemote(...)
5619" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5620 if a:0 > 0
5621 let curfile= a:1
5622 else
5623 let curfile= expand("%")
5624 endif
5625" call Decho("curfile<".curfile.">")
5626 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005627" call Dret("netrw#CheckIfRemote 1")
5628 return 1
5629 else
5630" call Dret("netrw#CheckIfRemote 0")
5631 return 0
5632 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005633endfun
5634
5635" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005636" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5637fun! s:NetrwChgPerm(islocal,curdir)
5638" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005639 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005640 call inputsave()
5641 let newperm= input("Enter new permission: ")
5642 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005643 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5644 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5645" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005646 call system(chgperm)
5647 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005648 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005649 endif
5650 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005651 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005652 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005653 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005654" call Dret("s:NetrwChgPerm")
5655endfun
5656
5657" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005658" s:CheckIfKde: checks if kdeinit is running {{{2
5659" Returns 0: kdeinit not running
5660" 1: kdeinit is running
5661fun! s:CheckIfKde()
5662" call Dfunc("s:CheckIfKde()")
5663 " seems kde systems often have gnome-open due to dependencies, even though
5664 " gnome-open's subsidiary display tools are largely absent. Kde systems
5665 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5666 if !exists("s:haskdeinit")
5667 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005668 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005669 if v:shell_error
5670 let s:haskdeinit = 0
5671 endif
5672 else
5673 let s:haskdeinit= 0
5674 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005675" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005676 endif
5677
5678" call Dret("s:CheckIfKde ".s:haskdeinit)
5679 return s:haskdeinit
5680endfun
5681
5682" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005683" s:NetrwClearExplore: clear explore variables (if any) {{{2
5684fun! s:NetrwClearExplore()
5685" call Dfunc("s:NetrwClearExplore()")
5686 2match none
5687 if exists("s:explore_match") |unlet s:explore_match |endif
5688 if exists("s:explore_indx") |unlet s:explore_indx |endif
5689 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5690 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5691 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5692 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5693 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5694 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5695 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5696" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005697" call Dret("s:NetrwClearExplore")
5698endfun
5699
5700" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005701" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5702fun! s:NetrwEditBuf(bufnum)
5703" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5704 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5705" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5706 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5707 else
5708" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005709 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005710 endif
5711" call Dret("s:NetrwEditBuf")
5712endfun
5713
5714" ---------------------------------------------------------------------
5715" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5716" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5717fun! s:NetrwEditFile(cmd,opt,fname)
5718" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5719 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5720" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5721 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5722 else
5723" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5724 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5725 endif
5726" call Dret("s:NetrwEditFile")
5727endfun
5728
5729" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005730" s:NetrwExploreListUniq: {{{2
5731fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005732" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005733
5734 " this assumes that the list is already sorted
5735 let newexplist= []
5736 for member in a:explist
5737 if !exists("uniqmember") || member != uniqmember
5738 let uniqmember = member
5739 let newexplist = newexplist + [ member ]
5740 endif
5741 endfor
5742
Bram Moolenaar15146672011-10-20 22:22:38 +02005743" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005744 return newexplist
5745endfun
5746
5747" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005748" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5749fun! s:NetrwForceChgDir(islocal,newdir)
5750" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005751 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005752 if a:newdir !~ '/$'
5753 " ok, looks like force is needed to get directory-style treatment
5754 if a:newdir =~ '@$'
5755 let newdir= substitute(a:newdir,'@$','/','')
5756 elseif a:newdir =~ '[*=|\\]$'
5757 let newdir= substitute(a:newdir,'.$','/','')
5758 else
5759 let newdir= a:newdir.'/'
5760 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005761" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005762 else
5763 " should already be getting treatment as a directory
5764 let newdir= a:newdir
5765 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005766 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005767 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005768 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005769" call Dret("s:NetrwForceChgDir")
5770endfun
5771
5772" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005773" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005774" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5775" expr : this is the expression to follow the directory. Will use s:ComposePath()
5776" pare =1: remove the current directory from the resulting glob() filelist
5777" =0: leave the current directory in the resulting glob() filelist
5778fun! s:NetrwGlob(direntry,expr,pare)
5779" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005780 if netrw#CheckIfRemote()
5781 keepalt 1sp
5782 keepalt enew
5783 let keep_liststyle = w:netrw_liststyle
5784 let w:netrw_liststyle = s:THINLIST
5785 if s:NetrwRemoteListing() == 0
5786 keepj keepalt %s@/@@
5787 let filelist= getline(1,$)
5788 q!
5789 else
5790 " remote listing error -- leave treedict unchanged
5791 let filelist= w:netrw_treedict[a:direntry]
5792 endif
5793 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005794 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5795 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5796 if a:pare
5797 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5798 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005799 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005800 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5801 if a:pare
5802 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5803 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005804 endif
5805" call Dret("s:NetrwGlob ".string(filelist))
5806 return filelist
5807endfun
5808
5809" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005810" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5811fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005812" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005813 if a:newfile =~ '[/@*=|\\]$'
5814 let newfile= substitute(a:newfile,'.$','','')
5815 else
5816 let newfile= a:newfile
5817 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005818 if a:islocal
5819 call s:NetrwBrowseChgDir(a:islocal,newfile)
5820 else
5821 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5822 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005823" call Dret("s:NetrwForceFile")
5824endfun
5825
5826" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005827" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5828" and switches the hiding mode. The actual hiding is done by
5829" s:NetrwListHide().
5830" g:netrw_hide= 0: show all
5831" 1: show not-hidden files
5832" 2: show hidden files only
5833fun! s:NetrwHide(islocal)
5834" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005835 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005836 let svpos= winsaveview()
5837" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005838
5839 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005840" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5841" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005842
5843 " hide the files in the markfile list
5844 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005845" 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 +00005846 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5847 " remove fname from hiding list
5848 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5849 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5850 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005851" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005852 else
5853 " append fname to hiding list
5854 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5855 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5856 else
5857 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5858 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005859" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005860 endif
5861 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005862 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005863 let g:netrw_hide= 1
5864
5865 else
5866
5867 " switch between show-all/show-not-hidden/show-hidden
5868 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005869 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005870 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005871 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005872 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005873" call Dret("NetrwHide")
5874 return
5875 endif
5876 endif
5877
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005878 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005879" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5880 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005881 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005882" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005883endfun
5884
5885" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005886" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5887fun! s:NetrwHideEdit(islocal)
5888" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5889
5890 let ykeep= @@
5891 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005892 let svpos= winsaveview()
5893" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005894
5895 " get new hiding list from user
5896 call inputsave()
5897 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5898 call inputrestore()
5899 let g:netrw_list_hide= newhide
5900" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5901
5902 " refresh the listing
5903 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5904
5905 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005906" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5907 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005908 let @@= ykeep
5909
5910" call Dret("NetrwHideEdit")
5911endfun
5912
5913" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005914" s:NetrwHidden: invoked by "gh" {{{2
5915fun! s:NetrwHidden(islocal)
5916" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005917 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005918 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005919 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005920" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005921
5922 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005923 " remove .file pattern from hiding list
5924" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005925 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005926 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005927" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005928 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5929 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005930" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005931 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5932 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005933 if g:netrw_list_hide =~ '^,'
5934 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5935 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005936
5937 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005938 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005939" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5940 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005941 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005942" call Dret("s:NetrwHidden")
5943endfun
5944
5945" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005946" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5947fun! s:NetrwHome()
5948 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005949 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005950 else
5951 " go to vim plugin home
5952 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005953 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005954 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005955 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005956 let home= basehome."/.vim"
5957 break
5958 endif
5959 endfor
5960 if home == ""
5961 " just pick the first directory
5962 let home= substitute(&rtp,',.*$','','')
5963 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005964 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005965 let home= substitute(home,'/','\\','g')
5966 endif
5967 endif
5968 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005969 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005970" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005971 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005972" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005973 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005974 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005975" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005976 call mkdir(home)
5977 endif
5978 endif
5979 let g:netrw_home= home
5980 return home
5981endfun
5982
5983" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005984" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5985fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005986 if exists("s:netrwdrag")
5987 return
5988 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005989 if &ft != "netrw"
5990 return
5991 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005992" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005993
Bram Moolenaar97d62492012-11-15 21:28:22 +01005994 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005995 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005996 while getchar(0) != 0
5997 "clear the input stream
5998 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005999 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006000 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006001 let mouse_lnum = v:mouse_lnum
6002 let wlastline = line('w$')
6003 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006004" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6005" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006006 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6007 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006008 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006009" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6010 return
6011 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006012 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006013 " 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 +01006014 " without this test when its disabled.
6015 " 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 +01006016" 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 +01006017 if v:mouse_col > virtcol('.')
6018 let @@= ykeep
6019" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6020 return
6021 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006022
Bram Moolenaar446cb832008-06-24 21:56:24 +00006023 if a:islocal
6024 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006025 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006026 endif
6027 else
6028 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006029 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006030 endif
6031 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006032 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006033" call Dret("s:NetrwLeftmouse")
6034endfun
6035
6036" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006037" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6038fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006039 if &ft != "netrw"
6040 return
6041 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006042" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6043 call s:NetrwMarkFileTgt(a:islocal)
6044" call Dret("s:NetrwCLeftmouse")
6045endfun
6046
6047" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006048" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6049" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006050" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006051" a:islocal=2 : <c-r> used, remote
6052" a:islocal=3 : <c-r> used, local
6053fun! s:NetrwServerEdit(islocal,fname)
6054" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6055 let islocal = a:islocal%2 " =0: remote =1: local
6056 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006057" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006058
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006059 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006060 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006061 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006062" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006063 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006064 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006065 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6066 unlet s:netrw_browse_split_{winnr()}
6067 endif
6068 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6069" call Dret("s:NetrwServerEdit")
6070 return
6071 endif
6072
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006073" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006074 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006075" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006076
6077 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006078" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006079 let srvrname = g:netrw_browse_split[0]
6080 let tabnum = g:netrw_browse_split[1]
6081 let winnum = g:netrw_browse_split[2]
6082
6083 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006084" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006085
6086 if !ctrlr
6087 " user must have closed the server window and the user did not use <c-r>, but
6088 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006089" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006090 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006091 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006092 endif
6093 let g:netrw_browse_split= 0
6094 if exists("s:netrw_browse_split_".winnr())
6095 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6096 endif
6097 call s:NetrwBrowseChgDir(islocal,a:fname)
6098" call Dret("s:NetrwServerEdit")
6099 return
6100
6101 elseif has("win32") && executable("start")
6102 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006103" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006104 call system("start gvim --servername ".srvrname)
6105
6106 else
6107 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006108" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006109 call system("gvim --servername ".srvrname)
6110 endif
6111 endif
6112
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006113" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006114 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6115 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006116 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006117
6118 else
6119
6120 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6121
6122 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006123" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006124 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006125 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006126 endif
6127 let g:netrw_browse_split= 0
6128 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6129" call Dret("s:NetrwServerEdit")
6130 return
6131
6132 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006133" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006134 if has("win32") && executable("start")
6135 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006136" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006137 call system("start gvim --servername ".g:netrw_servername)
6138 else
6139 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006140" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006141 call system("gvim --servername ".g:netrw_servername)
6142 endif
6143 endif
6144 endif
6145
6146 while 1
6147 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006148" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6149 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006150 break
6151 catch /^Vim\%((\a\+)\)\=:E241/
6152 sleep 200m
6153 endtry
6154 endwhile
6155
6156 if exists("g:netrw_browse_split")
6157 if type(g:netrw_browse_split) != 3
6158 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6159 endif
6160 unlet g:netrw_browse_split
6161 endif
6162 let g:netrw_browse_split= [g:netrw_servername,1,1]
6163 endif
6164
6165 else
6166 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6167 endif
6168
6169" call Dret("s:NetrwServerEdit")
6170endfun
6171
6172" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006173" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6174fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006175 if &ft != "netrw"
6176 return
6177 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006178" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006179
Bram Moolenaar8d043172014-01-23 14:24:41 +01006180 let s:ngw= s:NetrwGetWord()
6181 call s:NetrwMarkFile(a:islocal,s:ngw)
6182
6183" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006184endfun
6185
6186" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006187" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6188" Used to mark multiple files.
6189fun! s:NetrwSLeftdrag(islocal)
6190" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6191 if !exists("s:netrwdrag")
6192 let s:netrwdrag = winnr()
6193 if a:islocal
6194 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006195 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006196 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006197 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006198 endif
6199 let ngw = s:NetrwGetWord()
6200 if !exists("s:ngw") || s:ngw != ngw
6201 call s:NetrwMarkFile(a:islocal,ngw)
6202 endif
6203 let s:ngw= ngw
6204" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6205endfun
6206
6207" ---------------------------------------------------------------------
6208" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6209fun! s:NetrwSLeftrelease(islocal)
6210" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6211 if exists("s:netrwdrag")
6212 nunmap <s-leftrelease>
6213 let ngw = s:NetrwGetWord()
6214 if !exists("s:ngw") || s:ngw != ngw
6215 call s:NetrwMarkFile(a:islocal,ngw)
6216 endif
6217 if exists("s:ngw")
6218 unlet s:ngw
6219 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006220 unlet s:netrwdrag
6221 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006222" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006223endfun
6224
6225" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006226" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6227" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006228fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006229" 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 +02006230" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006231 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006232
6233 " 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 +02006234 " How-it-works: take the hiding command, convert it into a range.
6235 " Duplicate characters don't matter.
6236 " Remove all such characters from the '/~@#...890' string.
6237 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006238" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006239 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006240 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006241" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006242
6243 while listhide != ""
6244 if listhide =~ ','
6245 let hide = substitute(listhide,',.*$','','e')
6246 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6247 else
6248 let hide = listhide
6249 let listhide = ""
6250 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006251" 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 +01006252 if g:netrw_sort_by =~ '^[ts]'
6253 if hide =~ '^\^'
6254" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6255 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6256 elseif hide =~ '^\\(\^'
6257 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6258 endif
6259" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6260 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006261
6262 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006263" 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 +00006264 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006265" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006266 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006267 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006268" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006269 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006270 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006271" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006272 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006273
Bram Moolenaar446cb832008-06-24 21:56:24 +00006274 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006275 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006276" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006277 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006278" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006279 endif
6280
Bram Moolenaaradc21822011-04-01 18:03:16 +02006281 " remove any blank lines that have somehow remained.
6282 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006283 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006284
Bram Moolenaar97d62492012-11-15 21:28:22 +01006285 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006286" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006287endfun
6288
6289" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006290" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006291" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006292fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006293" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006294
Bram Moolenaar97d62492012-11-15 21:28:22 +01006295 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006296 " get name of new directory from user. A bare <CR> will skip.
6297 " if its currently a directory, also request will be skipped, but with
6298 " a message.
6299 call inputsave()
6300 let newdirname= input("Please give directory name: ")
6301 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006302" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006303
6304 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006305 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006306" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006307 return
6308 endif
6309
6310 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006311" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006312
6313 " Local mkdir:
6314 " sanity checks
6315 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006316" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6317 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006318 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006319 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006320 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006321 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006322" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006323 return
6324 endif
6325 if s:FileReadable(fullnewdir)
6326 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006327 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006328 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006329 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006330" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006331 return
6332 endif
6333
6334 " requested new local directory is neither a pre-existing file or
6335 " directory, so make it!
6336 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006337 if has("unix")
6338 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6339 else
6340 call mkdir(fullnewdir,"p")
6341 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006342 else
6343 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006344 if s:NetrwLcd(b:netrw_curdir)
6345" call Dret("s:NetrwMakeDir : lcd failure")
6346 return
6347 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006348" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006349 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006350 if v:shell_error != 0
6351 let @@= ykeep
6352 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 +01006353" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006354 return
6355 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006356 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006357" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006358 if s:NetrwLcd(netrw_origdir)
6359" call Dret("s:NetrwBrowse : lcd failure")
6360 return
6361 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006362 endif
6363 endif
6364
6365 if v:shell_error == 0
6366 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006367" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006368 let svpos= winsaveview()
6369" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006370 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006371" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6372 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006373 elseif !exists("g:netrw_quiet")
6374 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6375 endif
6376" redraw!
6377
6378 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006379 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006380" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006381 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6382 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006383 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006384 if v:shell_error == 0
6385 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006386 let svpos= winsaveview()
6387" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006388 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006389" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6390 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006391 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006392 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006393 endif
6394" redraw!
6395
6396 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006397 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006398 let svpos= winsaveview()
6399" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006400" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006401 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006402" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006403 let remotepath= b:netrw_fname
6404 else
6405 let remotepath= ""
6406 endif
6407 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006408 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006409" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6410 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006411
Bram Moolenaar446cb832008-06-24 21:56:24 +00006412 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006413 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006414 let svpos= winsaveview()
6415" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006416" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006417 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006418" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006419 let remotepath= b:netrw_fname
6420 else
6421 let remotepath= ""
6422 endif
6423 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006424 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006425" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6426 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006427 endif
6428
Bram Moolenaar97d62492012-11-15 21:28:22 +01006429 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006430" call Dret("s:NetrwMakeDir")
6431endfun
6432
6433" ---------------------------------------------------------------------
6434" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6435fun! s:TreeSqueezeDir(islocal)
6436" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6437 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6438 " its a tree-listing style
6439 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006440 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006441 let depth = strchars(substitute(curdepth,' ','','g'))
6442 let srch = -1
6443" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6444" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006445" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006446" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6447 if depth >= 2
6448 NetrwKeepj norm! 0
6449 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6450 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6451" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6452" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6453 elseif depth == 1
6454 NetrwKeepj norm! 0
6455 let treedepthchr= substitute(s:treedepthstring,' ','','')
6456 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6457" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6458 endif
6459 if srch > 0
6460" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6461 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6462 exe srch
6463 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006464 endif
6465" call Dret("s:TreeSqueezeDir")
6466endfun
6467
6468" ---------------------------------------------------------------------
6469" s:NetrwMaps: {{{2
6470fun! s:NetrwMaps(islocal)
6471" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6472
Bram Moolenaar85850f32019-07-19 22:05:51 +02006473 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006474 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006475" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006476 if !hasmapto("<Plug>NetrwReturn")
6477 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006478" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006479 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6480 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006481" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006482 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6483 endif
6484 endif
6485 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006486" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006487 endif
6488
Bram Moolenaar85850f32019-07-19 22:05:51 +02006489 " generate default <Plug> maps {{{3
6490 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006491 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006492 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6493 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6494 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6495 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6496 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6497 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6498 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6499 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6500 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6501 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6502" ---------------------------------------------------------------------
6503" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6504" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6505" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6506" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6507" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6508" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6509" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6510" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6511" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6512" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6513" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6514" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6515" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6516" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6517" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6518" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6519" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6520" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6521" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6522" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6523" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6524" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6525" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6526" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6527" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6528" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6529" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6530" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6531" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6532" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6533" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6534" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6535" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6536" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6537" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6538" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6539" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6540" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6541" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6542" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6543" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6544" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6545" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6546" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6547" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6548" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6549" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6550
Bram Moolenaara6878372014-03-22 21:02:50 +01006551 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006552" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006553 " local normal-mode maps {{{3
6554 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6555 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6556 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6557 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6558 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6559 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6560 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6561 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6562 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6563 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6564 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6565" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006566 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6567 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6568 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006569 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006570 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006571 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6572 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6573 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6574 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006575 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6576 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6577 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6578 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6579 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6580 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6581 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6582 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6583 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6584 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6585 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6586 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6587 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006588 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006589 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006590 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6591 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6592 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6593 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6594 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006595 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006596 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006597 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6598 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006599 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6600 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6601 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006602 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006603 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006604 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6605 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006606 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006607 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006608 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6609 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6610 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006611 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6612 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006613
6614 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 +01006615 if !hasmapto('<Plug>NetrwHideEdit')
6616 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006617 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006618 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006619 if !hasmapto('<Plug>NetrwRefresh')
6620 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006621 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006622 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 +01006623 if s:didstarstar || !mapcheck("<s-down>","n")
6624 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006625 endif
6626 if s:didstarstar || !mapcheck("<s-up>","n")
6627 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006628 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006629 if !hasmapto('<Plug>NetrwTreeSqueeze')
6630 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006631 endif
6632 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006633 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6634 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006635 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6636 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6637 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6638 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6639 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6640 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6641 imap <buffer> <leftmouse> <Plug>ILeftmouse
6642 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006643 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6644 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6645 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6646 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6647 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006648 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006649 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6650 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006651 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006652 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6653 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6654 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6655 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6656 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6657 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6658 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006659 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6660
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006661 " support user-specified maps
6662 call netrw#UserMaps(1)
6663
Bram Moolenaar85850f32019-07-19 22:05:51 +02006664 else
6665 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006666" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006667 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006668 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6669 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6670 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6671 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6672 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6673 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6674 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6675 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6676 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6677 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6678 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6679" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006680 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6681 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6682 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6683 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6684 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6685 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6686 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6687 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006688 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006689 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006690 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6691 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6692 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6693 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6694 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6695 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6696 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6697 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6698 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6699 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6700 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006701 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006702 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006703 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6704 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6705 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6706 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6707 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006708 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6709 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6710 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6711 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006712 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006713 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6714 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006715 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006716 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 +01006717 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6718 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6719 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6720 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6721 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6722 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6723 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6724 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6725 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006726 if !hasmapto('<Plug>NetrwHideEdit')
6727 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006728 endif
6729 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6730 if !hasmapto('<Plug>NetrwRefresh')
6731 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006732 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006733 if !hasmapto('<Plug>NetrwTreeSqueeze')
6734 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006735 endif
6736 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006737
6738 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006739 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006740
6741 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6742 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006743 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006744 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006745 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006746 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006747 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006748 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006749 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006750 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006751 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006752 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006753 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6754 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6755 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006756 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006757 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006758 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6759 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006760 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006761 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6762 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6763 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6764 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6765 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6766 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6767 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006768 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006769
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006770 " support user-specified maps
6771 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006772 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006773
6774" call Dret("s:NetrwMaps")
6775endfun
6776
6777" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006778" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006779" If -buffer, the command is only available from within netrw buffers
6780" Otherwise, the command is available from any window, so long as netrw
6781" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006782fun! s:NetrwCommands(islocal)
6783" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6784
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006785 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6786 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006787 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 +01006788 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006789 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006790 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006791 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006792 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006793 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006794
6795" call Dret("s:NetrwCommands")
6796endfun
6797
6798" ---------------------------------------------------------------------
6799" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6800" glob()ing only works with local files
6801fun! s:NetrwMarkFiles(islocal,...)
6802" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006803 let curdir = s:NetrwGetCurdir(a:islocal)
6804 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006805 while i <= a:0
6806 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006807 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006808 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006809 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006810 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006811 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006812 else
6813 let mffiles= [a:{i}]
6814 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006815" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006816 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006817" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006818 call s:NetrwMarkFile(a:islocal,mffile)
6819 endfor
6820 let i= i + 1
6821 endwhile
6822" call Dret("s:NetrwMarkFiles")
6823endfun
6824
6825" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006826" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006827fun! s:NetrwMarkTarget(...)
6828" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6829 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006830 let curdir = s:NetrwGetCurdir(1)
6831 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006832 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006833 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6834 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006835 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006836" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006837 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006838 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6839 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006840 let svpos = winsaveview()
6841" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006842 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006843" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6844 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006845" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006846endfun
6847
6848" ---------------------------------------------------------------------
6849" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6850" mark and unmark files. If a markfile list exists,
6851" then the rename and delete functions will use it instead
6852" of whatever may happen to be under the cursor at that
6853" moment. When the mouse and gui are available,
6854" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006855"
6856" Creates two lists
6857" s:netrwmarkfilelist -- holds complete paths to all marked files
6858" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6859"
6860" Creates a marked file match string
6861" s:netrwmarfilemtch_# -- used with 2match to display marked files
6862"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006863" Creates a buffer version of islocal
6864" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006865fun! s:NetrwMarkFile(islocal,fname)
6866" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006867" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006868
6869 " sanity check
6870 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006871" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006872 return
6873 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006874 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006875
Bram Moolenaar97d62492012-11-15 21:28:22 +01006876 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006877 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006878 if a:fname =~ '^\a'
6879 let leader= '\<'
6880 else
6881 let leader= ''
6882 endif
6883 if a:fname =~ '\a$'
6884 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6885 else
6886 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6887 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006888
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006889 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006890 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006891" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6892" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6893" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006894 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006895
6896 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006897 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006898" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006899 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006900 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006901
6902 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006903 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006904" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006905 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6906 if s:netrwmarkfilelist_{curbufnr} == []
6907 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006908" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006909 call s:NetrwUnmarkList(curbufnr,curdir)
6910 else
6911 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006912" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006913 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006914 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006915 for fname in s:netrwmarkfilelist_{curbufnr}
6916 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006917 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006918 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006919 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006920 endif
6921 let first= 0
6922 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006923" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006924 endif
6925 endif
6926
6927 else
6928 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006929" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006930
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006931" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006932 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006933 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6934" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006935
6936 " build initial markfile matching pattern
6937 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006938 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006939 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006940 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006941 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006942" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006943 endif
6944
6945 " handle global markfilelist
6946 if exists("s:netrwmarkfilelist")
6947 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6948 if index(s:netrwmarkfilelist,dname) == -1
6949 " append new filename to global markfilelist
6950 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006951" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006952 else
6953 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006954" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6955" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006956 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006957" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006958 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006959" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006960 unlet s:netrwmarkfilelist
6961 endif
6962 endif
6963 else
6964 " initialize new global-directory markfilelist
6965 let s:netrwmarkfilelist= []
6966 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006967" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006968 endif
6969
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006970 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006971 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6972 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6973" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6974 if exists("g:did_drchip_netrwlist_syntax")
6975 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6976 endif
6977 else
6978" " call Decho("2match none",'~'.expand("<slnum>"))
6979 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006980 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006981 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006982 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006983" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6984" 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 +00006985endfun
6986
6987" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006988" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6989" mA: move the argument list to marked file list (tomflist=1)
6990" Uses the global marked file list
6991fun! s:NetrwMarkFileArgList(islocal,tomflist)
6992" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6993
6994 let svpos = winsaveview()
6995" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6996 let curdir = s:NetrwGetCurdir(a:islocal)
6997 let curbufnr = bufnr("%")
6998
6999 if a:tomflist
7000 " mA: move argument list to marked file list
7001 while argc()
7002 let fname= argv(0)
7003" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7004 exe "argdel ".fnameescape(fname)
7005 call s:NetrwMarkFile(a:islocal,fname)
7006 endwhile
7007
7008 else
7009 " ma: move marked file list to argument list
7010 if exists("s:netrwmarkfilelist")
7011
7012 " for every filename in the marked list
7013 for fname in s:netrwmarkfilelist
7014" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7015 exe "argadd ".fnameescape(fname)
7016 endfor " for every file in the marked list
7017
7018 " unmark list and refresh
7019 call s:NetrwUnmarkList(curbufnr,curdir)
7020 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7021" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7022 NetrwKeepj call winrestview(svpos)
7023 endif
7024 endif
7025
7026" call Dret("s:NetrwMarkFileArgList")
7027endfun
7028
7029" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007030" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7031" compress/decompress files using the programs
7032" in g:netrw_compress and g:netrw_uncompress,
7033" using g:netrw_compress_suffix to know which to
7034" do. By default:
7035" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007036" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007037fun! s:NetrwMarkFileCompress(islocal)
7038" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007039 let svpos = winsaveview()
7040" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007041 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007042 let curbufnr = bufnr("%")
7043
Bram Moolenaarff034192013-04-24 18:51:19 +02007044 " sanity check
7045 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007046 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007047" call Dret("s:NetrwMarkFileCompress")
7048 return
7049 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007050" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007051
Bram Moolenaar446cb832008-06-24 21:56:24 +00007052 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007053
7054 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007055 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007056 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007057" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007058 if exists("g:netrw_decompress['".sfx."']")
7059 " fname has a suffix indicating that its compressed; apply associated decompression routine
7060 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007061" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007062 let exe= netrw#WinPath(exe)
7063 if a:islocal
7064 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007065 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007066 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007067 call system(exe." ".fname)
7068 if v:shell_error
7069 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007070 endif
7071 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007072 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7073 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007074 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007075
Bram Moolenaarff034192013-04-24 18:51:19 +02007076 endif
7077 unlet sfx
7078
Bram Moolenaar446cb832008-06-24 21:56:24 +00007079 if exists("exe")
7080 unlet exe
7081 elseif a:islocal
7082 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007083 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007084 if v:shell_error
7085 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7086 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007087 else
7088 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007089 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007090 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007091 endfor " for every file in the marked list
7092
Bram Moolenaar446cb832008-06-24 21:56:24 +00007093 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007094 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007095" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7096 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007097 endif
7098" call Dret("s:NetrwMarkFileCompress")
7099endfun
7100
7101" ---------------------------------------------------------------------
7102" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7103" If no marked files, then set up directory as the
7104" target. Currently does not support copying entire
7105" directories. Uses the local-buffer marked file list.
7106" Returns 1=success (used by NetrwMarkFileMove())
7107" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007108fun! s:NetrwMarkFileCopy(islocal,...)
7109" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7110
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007111 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007112 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007113 if b:netrw_curdir !~ '/$'
7114 if !exists("b:netrw_curdir")
7115 let b:netrw_curdir= curdir
7116 endif
7117 let b:netrw_curdir= b:netrw_curdir."/"
7118 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007119
Bram Moolenaarff034192013-04-24 18:51:19 +02007120 " sanity check
7121 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007122 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007123" call Dret("s:NetrwMarkFileCopy")
7124 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007125 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007126" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007127
Bram Moolenaar446cb832008-06-24 21:56:24 +00007128 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007129 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007130" call Dret("s:NetrwMarkFileCopy 0")
7131 return 0
7132 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007133" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007134
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007135 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007136 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007137" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007138 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007139 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7140" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7141 return
7142 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007143
7144 " copy marked files while within the same directory (ie. allow renaming)
7145 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7146 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7147 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007148" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007149 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007150 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7151 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007152" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007153 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007154 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007155 let oldname = a:1
7156 else
7157 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007158" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007159 let s:recursive= 1
7160 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7161 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7162 if ret == 0
7163 break
7164 endif
7165 endfor
7166 unlet s:recursive
7167 call s:NetrwUnmarkList(curbufnr,curdir)
7168" call Dret("s:NetrwMarkFileCopy ".ret)
7169 return ret
7170 endif
7171
7172 call inputsave()
7173 let newname= input("Copy ".oldname." to : ",oldname,"file")
7174 call inputrestore()
7175 if newname == ""
7176" call Dret("s:NetrwMarkFileCopy 0")
7177 return 0
7178 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007179 let args= s:ShellEscape(oldname)
7180 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007181 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007182 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7183 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007184 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007185 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007186 let args= substitute(args,'/','\\','g')
7187 let tgt = substitute(tgt, '/','\\','g')
7188 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007189 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7190 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7191 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7192 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7193" call Decho("args <".args.">",'~'.expand("<slnum>"))
7194" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007195 if isdirectory(s:NetrwFile(args))
7196" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007197 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007198" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007199 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007200 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7201 " contents to a target. One must append the source directory name to the target to get xcopy to
7202 " do the right thing.
7203 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007204" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007205 endif
7206 else
7207 let copycmd= g:netrw_localcopycmd
7208 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007209 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007210 let copycmd = substitute(copycmd,'\s.*$','','')
7211 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007212 let copycmd = netrw#WinPath(copycmd).copycmdargs
7213 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007214 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007215 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007216" call Decho("args <".args.">",'~'.expand("<slnum>"))
7217" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7218" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7219" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007220 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007221 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007222 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007223 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 +01007224 else
7225 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7226 endif
7227" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007228 return 0
7229 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007230
7231 elseif a:islocal && !s:netrwmftgt_islocal
7232 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007233" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007234 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007235
7236 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007237 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007238" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007239 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007240
7241 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007242 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007243" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007244 let curdir = getcwd()
7245 let tmpdir = s:GetTempfile("")
7246 if tmpdir !~ '/'
7247 let tmpdir= curdir."/".tmpdir
7248 endif
7249 if exists("*mkdir")
7250 call mkdir(tmpdir)
7251 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007252 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007253 if v:shell_error != 0
7254 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 +01007255" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007256 return
7257 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007258 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007259 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007260 if s:NetrwLcd(tmpdir)
7261" call Dret("s:NetrwMarkFileCopy : lcd failure")
7262 return
7263 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007264 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007265 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007266 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007267 if getcwd() == tmpdir
7268 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007269 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007270 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007271 if s:NetrwLcd(curdir)
7272" call Dret("s:NetrwMarkFileCopy : lcd failure")
7273 return
7274 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007275 if delete(tmpdir,"d")
7276 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007277 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007278 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007279 if s:NetrwLcd(curdir)
7280" call Dret("s:NetrwMarkFileCopy : lcd failure")
7281 return
7282 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007283 endif
7284 endif
7285 endif
7286
7287 " -------
7288 " cleanup
7289 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007290" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007291 " remove markings from local buffer
7292 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007293" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7294" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7295" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7296" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7297" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7298" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7299 if exists("s:recursive")
7300" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7301 else
7302" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007303 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007304 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007305 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007306 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007307 else
7308 " refresh local and targets for fast browsing
7309 if !exists("s:recursive")
7310 " remove markings from local buffer
7311" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7312 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7313 endif
7314
7315 " refresh buffers
7316 if s:netrwmftgt_islocal
7317" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7318 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7319 endif
7320 if a:islocal && s:netrwmftgt != curdir
7321" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7322 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7323 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007324 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007325
Bram Moolenaar446cb832008-06-24 21:56:24 +00007326" call Dret("s:NetrwMarkFileCopy 1")
7327 return 1
7328endfun
7329
7330" ---------------------------------------------------------------------
7331" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7332" invoke vim's diff mode on the marked files.
7333" Either two or three files can be so handled.
7334" Uses the global marked file list.
7335fun! s:NetrwMarkFileDiff(islocal)
7336" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7337 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007338
Bram Moolenaarff034192013-04-24 18:51:19 +02007339 " sanity check
7340 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007341 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007342" call Dret("s:NetrwMarkFileDiff")
7343 return
7344 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007345 let curdir= s:NetrwGetCurdir(a:islocal)
7346" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007347
Bram Moolenaara6878372014-03-22 21:02:50 +01007348 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007349 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007350 for fname in s:netrwmarkfilelist
7351 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007352 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007353" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007354 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007355 diffthis
7356 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007357 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007358" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007359 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007360 diffthis
7361 else
7362 break
7363 endif
7364 endfor
7365 call s:NetrwUnmarkList(curbufnr,curdir)
7366 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007367
Bram Moolenaar446cb832008-06-24 21:56:24 +00007368" call Dret("s:NetrwMarkFileDiff")
7369endfun
7370
7371" ---------------------------------------------------------------------
7372" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7373" Uses global markfilelist
7374fun! s:NetrwMarkFileEdit(islocal)
7375" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7376
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007377 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007378 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007379
7380 " sanity check
7381 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007382 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007383" call Dret("s:NetrwMarkFileEdit")
7384 return
7385 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007386" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007387
Bram Moolenaar446cb832008-06-24 21:56:24 +00007388 if exists("s:netrwmarkfilelist_{curbufnr}")
7389 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007390 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007391 " unmark markedfile list
7392" call s:NetrwUnmarkList(curbufnr,curdir)
7393 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007394" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007395 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007396 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007397 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007398
Bram Moolenaar446cb832008-06-24 21:56:24 +00007399" call Dret("s:NetrwMarkFileEdit")
7400endfun
7401
7402" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007403" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007404fun! s:NetrwMarkFileQFEL(islocal,qfel)
7405" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7406 call s:NetrwUnmarkAll()
7407 let curbufnr= bufnr("%")
7408
7409 if !empty(a:qfel)
7410 for entry in a:qfel
7411 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007412" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007413 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007414" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007415 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7416 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7417 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7418 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007419" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007420 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7421 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007422" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007423 endif
7424 endfor
7425 echo "(use me to edit marked files)"
7426 else
7427 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7428 endif
7429
7430" call Dret("s:NetrwMarkFileQFEL")
7431endfun
7432
7433" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007434" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7435" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7436" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7437fun! s:NetrwMarkFileExe(islocal,enbloc)
7438" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007439 let svpos = winsaveview()
7440" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007441 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007442 let curbufnr = bufnr("%")
7443
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007444 if a:enbloc == 0
7445 " individually apply command to files, one at a time
7446 " sanity check
7447 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7448 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7449" call Dret("s:NetrwMarkFileExe")
7450 return
7451 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007452" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007453
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007454 if exists("s:netrwmarkfilelist_{curbufnr}")
7455 " get the command
7456 call inputsave()
7457 let cmd= input("Enter command: ","","file")
7458 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007459" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007460 if cmd == ""
7461" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7462 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007463 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007464
7465 " apply command to marked files, individually. Substitute: filename -> %
7466 " If no %, then append a space and the filename to the command
7467 for fname in s:netrwmarkfilelist_{curbufnr}
7468 if a:islocal
7469 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007470 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007471 endif
7472 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007473 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007474 endif
7475 if cmd =~ '%'
7476 let xcmd= substitute(cmd,'%',fname,'g')
7477 else
7478 let xcmd= cmd.' '.fname
7479 endif
7480 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007481" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007482 let ret= system(xcmd)
7483 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007484" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007485 let ret= s:RemoteSystem(xcmd)
7486 endif
7487 if v:shell_error < 0
7488 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7489 break
7490 else
7491 echo ret
7492 endif
7493 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007494
7495 " unmark marked file list
7496 call s:NetrwUnmarkList(curbufnr,curdir)
7497
7498 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007499 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007500" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7501 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007502 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007503 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007504 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007505
7506 else " apply command to global list of files, en bloc
7507
7508 call inputsave()
7509 let cmd= input("Enter command: ","","file")
7510 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007511" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007512 if cmd == ""
7513" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7514 return
7515 endif
7516 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007517 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007518 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007519 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007520 endif
7521 if a:islocal
7522 call system(cmd)
7523 if v:shell_error < 0
7524 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7525 endif
7526 else
7527 let ret= s:RemoteSystem(cmd)
7528 endif
7529 call s:NetrwUnmarkAll()
7530
7531 " refresh the listing
7532 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007533" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7534 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007535
7536 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007537
Bram Moolenaar446cb832008-06-24 21:56:24 +00007538" call Dret("s:NetrwMarkFileExe")
7539endfun
7540
7541" ---------------------------------------------------------------------
7542" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7543" as the marked file(s) (toggles suffix presence)
7544" Uses the local marked file list.
7545fun! s:NetrwMarkHideSfx(islocal)
7546" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007547 let svpos = winsaveview()
7548" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007549 let curbufnr = bufnr("%")
7550
7551 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7552 if exists("s:netrwmarkfilelist_{curbufnr}")
7553
7554 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007555" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007556 " construct suffix pattern
7557 if fname =~ '\.'
7558 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7559 else
7560 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7561 endif
7562 " determine if its in the hiding list or not
7563 let inhidelist= 0
7564 if g:netrw_list_hide != ""
7565 let itemnum = 0
7566 let hidelist= split(g:netrw_list_hide,',')
7567 for hidepat in hidelist
7568 if sfxpat == hidepat
7569 let inhidelist= 1
7570 break
7571 endif
7572 let itemnum= itemnum + 1
7573 endfor
7574 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007575" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007576 if inhidelist
7577 " remove sfxpat from list
7578 call remove(hidelist,itemnum)
7579 let g:netrw_list_hide= join(hidelist,",")
7580 elseif g:netrw_list_hide != ""
7581 " append sfxpat to non-empty list
7582 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7583 else
7584 " set hiding list to sfxpat
7585 let g:netrw_list_hide= sfxpat
7586 endif
7587 endfor
7588
7589 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007590 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007591" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7592 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007593 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007594 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007595 endif
7596
7597" call Dret("s:NetrwMarkHideSfx")
7598endfun
7599
7600" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007601" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007602" Uses the local marked-file list.
7603fun! s:NetrwMarkFileVimCmd(islocal)
7604" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007605 let svpos = winsaveview()
7606" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007607 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007608 let curbufnr = bufnr("%")
7609
Bram Moolenaarff034192013-04-24 18:51:19 +02007610 " sanity check
7611 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007612 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007613" call Dret("s:NetrwMarkFileVimCmd")
7614 return
7615 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007616" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007617
Bram Moolenaar15146672011-10-20 22:22:38 +02007618 if exists("s:netrwmarkfilelist_{curbufnr}")
7619 " get the command
7620 call inputsave()
7621 let cmd= input("Enter vim command: ","","file")
7622 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007623" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007624 if cmd == ""
7625" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7626 return
7627 endif
7628
7629 " apply command to marked files. Substitute: filename -> %
7630 " If no %, then append a space and the filename to the command
7631 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007632" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007633 if a:islocal
7634 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007635 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007636" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007637 exe cmd
7638 exe "sil! keepalt wq!"
7639 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007640" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007641 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007642 endif
7643 endfor
7644
7645 " unmark marked file list
7646 call s:NetrwUnmarkList(curbufnr,curdir)
7647
7648 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007649 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007650" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7651 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007652 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007653 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007654 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007655
Bram Moolenaar15146672011-10-20 22:22:38 +02007656" call Dret("s:NetrwMarkFileVimCmd")
7657endfun
7658
7659" ---------------------------------------------------------------------
7660" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7661" as the marked file(s) (toggles suffix presence)
7662" Uses the local marked file list.
7663fun! s:NetrwMarkHideSfx(islocal)
7664" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007665 let svpos = winsaveview()
7666" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007667 let curbufnr = bufnr("%")
7668
7669 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7670 if exists("s:netrwmarkfilelist_{curbufnr}")
7671
7672 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007673" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007674 " construct suffix pattern
7675 if fname =~ '\.'
7676 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7677 else
7678 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7679 endif
7680 " determine if its in the hiding list or not
7681 let inhidelist= 0
7682 if g:netrw_list_hide != ""
7683 let itemnum = 0
7684 let hidelist= split(g:netrw_list_hide,',')
7685 for hidepat in hidelist
7686 if sfxpat == hidepat
7687 let inhidelist= 1
7688 break
7689 endif
7690 let itemnum= itemnum + 1
7691 endfor
7692 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007693" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007694 if inhidelist
7695 " remove sfxpat from list
7696 call remove(hidelist,itemnum)
7697 let g:netrw_list_hide= join(hidelist,",")
7698 elseif g:netrw_list_hide != ""
7699 " append sfxpat to non-empty list
7700 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7701 else
7702 " set hiding list to sfxpat
7703 let g:netrw_list_hide= sfxpat
7704 endif
7705 endfor
7706
7707 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007708 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007709" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7710 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007711 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007712 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007713 endif
7714
7715" call Dret("s:NetrwMarkHideSfx")
7716endfun
7717
7718" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007719" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7720" Uses the global markfilelist
7721fun! s:NetrwMarkFileGrep(islocal)
7722" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007723 let svpos = winsaveview()
7724" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007725 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007726 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007727
7728 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007729" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007730 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007731" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007732 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007733 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007734" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007735 let netrwmarkfilelist= "*"
7736 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007737
Bram Moolenaarff034192013-04-24 18:51:19 +02007738 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007739" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007740 call inputsave()
7741 let pat= input("Enter pattern: ","")
7742 call inputrestore()
7743 let patbang = ""
7744 if pat =~ '^!'
7745 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007746 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007747 endif
7748 if pat =~ '^\i'
7749 let pat = escape(pat,'/')
7750 let pat = '/'.pat.'/'
7751 else
7752 let nonisi = pat[0]
7753 endif
7754
7755 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007756" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007757 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007758 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007759 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007760 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007761" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7762 return
7763 endtry
7764 echo "(use :cn, :cp to navigate, :Rex to return)"
7765
7766 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007767" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7768 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007769
7770 if exists("nonisi")
7771 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007772" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007773 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007774 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007775 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007776 endif
7777
7778" call Dret("s:NetrwMarkFileGrep")
7779endfun
7780
7781" ---------------------------------------------------------------------
7782" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7783" uses the global marked file list
7784" s:netrwmfloc= 0: target directory is remote
7785" = 1: target directory is local
7786fun! s:NetrwMarkFileMove(islocal)
7787" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007788 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007789 let curbufnr = bufnr("%")
7790
7791 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007792 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007793 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007794" call Dret("s:NetrwMarkFileMove")
7795 return
7796 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007797" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007798
Bram Moolenaar446cb832008-06-24 21:56:24 +00007799 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007800 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007801" call Dret("s:NetrwMarkFileCopy 0")
7802 return 0
7803 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007804" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007805
7806 if a:islocal && s:netrwmftgt_islocal
7807 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007808" call Decho("move from local to local",'~'.expand("<slnum>"))
7809" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007810 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007811 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7812" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7813 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007814 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007815 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007816" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007817 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007818 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007819" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007820 if g:netrw_localmovecmd =~ '\s'
7821 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7822 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7823 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007824" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007825 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007826 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007827" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007828 endif
7829 else
7830 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007831" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007832 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007833 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007834 if g:netrw_keepdir
7835 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7836 let fname= b:netrw_curdir."/".fname
7837 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007838 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007839 let fname= substitute(fname,'/','\\','g')
7840 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007841" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007842 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007843 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007844 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007845 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 +01007846 else
7847 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7848 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007849 break
7850 endif
7851 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007852
7853 elseif a:islocal && !s:netrwmftgt_islocal
7854 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007855" call Decho("move from local to remote",'~'.expand("<slnum>"))
7856" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007857 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007858 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007859" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007860 for fname in mflist
7861 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7862 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7863 endfor
7864 unlet mflist
7865
7866 elseif !a:islocal && s:netrwmftgt_islocal
7867 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007868" call Decho("move from remote to local",'~'.expand("<slnum>"))
7869" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007870 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007871 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007872" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007873 for fname in mflist
7874 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7875 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7876 endfor
7877 unlet mflist
7878
7879 elseif !a:islocal && !s:netrwmftgt_islocal
7880 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007881" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7882" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007883 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007884 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007885" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007886 for fname in mflist
7887 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7888 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7889 endfor
7890 unlet mflist
7891 endif
7892
7893 " -------
7894 " cleanup
7895 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007896" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007897
7898 " remove markings from local buffer
7899 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7900
7901 " refresh buffers
7902 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007903" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007904 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007905 endif
7906 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007907" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007908 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007909 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007910 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007911" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007912 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007913 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007914
Bram Moolenaar446cb832008-06-24 21:56:24 +00007915" call Dret("s:NetrwMarkFileMove")
7916endfun
7917
7918" ---------------------------------------------------------------------
7919" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7920" using the hardcopy command. Local marked-file list only.
7921fun! s:NetrwMarkFilePrint(islocal)
7922" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7923 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007924
7925 " sanity check
7926 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007927 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007928" call Dret("s:NetrwMarkFilePrint")
7929 return
7930 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007931" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7932 let curdir= s:NetrwGetCurdir(a:islocal)
7933
Bram Moolenaar446cb832008-06-24 21:56:24 +00007934 if exists("s:netrwmarkfilelist_{curbufnr}")
7935 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007936 call s:NetrwUnmarkList(curbufnr,curdir)
7937 for fname in netrwmarkfilelist
7938 if a:islocal
7939 if g:netrw_keepdir
7940 let fname= s:ComposePath(curdir,fname)
7941 endif
7942 else
7943 let fname= curdir.fname
7944 endif
7945 1split
7946 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007947" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007948 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007949" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007950 hardcopy
7951 q
7952 endfor
7953 2match none
7954 endif
7955" call Dret("s:NetrwMarkFilePrint")
7956endfun
7957
7958" ---------------------------------------------------------------------
7959" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7960" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007961" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007962fun! s:NetrwMarkFileRegexp(islocal)
7963" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7964
7965 " get the regular expression
7966 call inputsave()
7967 let regexp= input("Enter regexp: ","","file")
7968 call inputrestore()
7969
7970 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007971 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007972" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007973 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007974" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007975 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007976 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007977 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007978 else
7979 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007980 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007981 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007982" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007983
7984 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007985 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007986 if fname =~ '^'.fnameescape(curdir)
7987" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7988 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7989 else
7990" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7991 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7992 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007993 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007994
7995 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007996" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007997
7998 " convert displayed listing into a filelist
7999 let eikeep = &ei
8000 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008001 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008002 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008003" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008004 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008005 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008006 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008007 sil NetrwKeepj norm! "ap
8008 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008009 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008010 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008011 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008012 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008013 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008014 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008015 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008016 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008017 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008019 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8020 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008021 call histdel("/",-1)
8022 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008023 endif
8024 " convert regexp into the more usual glob-style format
8025 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008026" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008027 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008028 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008029 let filelist= getline(1,line("$"))
8030 q!
8031 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008032 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008033 endfor
8034 unlet filelist
8035 let @a = areg
8036 let &ei = eikeep
8037 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008038 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008039
8040" call Dret("s:NetrwMarkFileRegexp")
8041endfun
8042
8043" ---------------------------------------------------------------------
8044" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8045" Uses the local marked file list.
8046fun! s:NetrwMarkFileSource(islocal)
8047" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8048 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008049
8050 " sanity check
8051 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008052 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008053" call Dret("s:NetrwMarkFileSource")
8054 return
8055 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008056" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8057 let curdir= s:NetrwGetCurdir(a:islocal)
8058
Bram Moolenaar446cb832008-06-24 21:56:24 +00008059 if exists("s:netrwmarkfilelist_{curbufnr}")
8060 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008061 call s:NetrwUnmarkList(curbufnr,curdir)
8062 for fname in netrwmarkfilelist
8063 if a:islocal
8064 if g:netrw_keepdir
8065 let fname= s:ComposePath(curdir,fname)
8066 endif
8067 else
8068 let fname= curdir.fname
8069 endif
8070 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008071" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008072 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008073 endfor
8074 2match none
8075 endif
8076" call Dret("s:NetrwMarkFileSource")
8077endfun
8078
8079" ---------------------------------------------------------------------
8080" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8081" Uses the global markfilelist
8082fun! s:NetrwMarkFileTag(islocal)
8083" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008084 let svpos = winsaveview()
8085" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008086 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008087 let curbufnr = bufnr("%")
8088
Bram Moolenaarff034192013-04-24 18:51:19 +02008089 " sanity check
8090 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008091 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008092" call Dret("s:NetrwMarkFileTag")
8093 return
8094 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008095" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008096
Bram Moolenaar446cb832008-06-24 21:56:24 +00008097 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008098" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8099 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008100 call s:NetrwUnmarkAll()
8101
8102 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008103
8104" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8105 call system(g:netrw_ctags." ".netrwmarkfilelist)
8106 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008107 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8108 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008109
Bram Moolenaar446cb832008-06-24 21:56:24 +00008110 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008111 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008112 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008113 let curdir= b:netrw_curdir
8114 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008115 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008116 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008117" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008118 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008119 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008120 wq!
8121 endif
8122 2match none
8123 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008124" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8125 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008126 endif
8127
8128" call Dret("s:NetrwMarkFileTag")
8129endfun
8130
8131" ---------------------------------------------------------------------
8132" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008133" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008134" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008135" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008136" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008137fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008138" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8139 let svpos = winsaveview()
8140" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008141 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008142 let hadtgt = exists("s:netrwmftgt")
8143 if !exists("w:netrw_bannercnt")
8144 let w:netrw_bannercnt= b:netrw_bannercnt
8145 endif
8146
8147 " set up target
8148 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008149" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008150 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8151 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008152" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008153 unlet s:netrwmftgt s:netrwmftgt_islocal
8154 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008155 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008156 endif
8157 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008158" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8159 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008160" call Dret("s:NetrwMarkFileTgt : removed target")
8161 return
8162 else
8163 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008164" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008165 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008166
8167 else
8168 " get word under cursor.
8169 " * If directory, use it for the target.
8170 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008171" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008172 let curword= s:NetrwGetWord()
8173 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008174 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008175 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008176" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008177 elseif !a:islocal && tgtdir =~ '/$'
8178 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008179" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008180 else
8181 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008182" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008183 endif
8184 endif
8185 if a:islocal
8186 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8187 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008189 endif
8190 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008192 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8193 endif
8194 let s:netrwmftgt_islocal= a:islocal
8195
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008196 " need to do refresh so that the banner will be updated
8197 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008198 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008199" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008200 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008201 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008202" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008203 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008204 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8205 else
8206 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8207 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008208" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8209 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008210 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008211 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008212 endif
8213
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008214" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8215" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008216" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8217endfun
8218
8219" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008220" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8221fun! s:NetrwGetCurdir(islocal)
8222" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8223
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008224 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008225 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8226" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8227 elseif !exists("b:netrw_curdir")
8228 let b:netrw_curdir= getcwd()
8229" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8230 endif
8231
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008232" 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 +01008233 if b:netrw_curdir !~ '\<\a\{3,}://'
8234 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008235" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008236 if g:netrw_keepdir == 0
8237 call s:NetrwLcd(curdir)
8238 endif
8239 endif
8240
8241" call Dret("s:NetrwGetCurdir <".curdir.">")
8242 return b:netrw_curdir
8243endfun
8244
8245" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008246" s:NetrwOpenFile: query user for a filename and open it {{{2
8247fun! s:NetrwOpenFile(islocal)
8248" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008249 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008250 call inputsave()
8251 let fname= input("Enter filename: ")
8252 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008253" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8254
8255 " determine if Lexplore is in use
8256 if exists("t:netrw_lexbufnr")
8257 " check if t:netrw_lexbufnr refers to a netrw window
8258" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8259 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8260 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8261" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8262 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8263 exe "NetrwKeepj e ".fnameescape(fname)
8264 let @@= ykeep
8265" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8266 endif
8267 endif
8268
8269 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008270 if fname !~ '[/\\]'
8271 if exists("b:netrw_curdir")
8272 if exists("g:netrw_quiet")
8273 let netrw_quiet_keep = g:netrw_quiet
8274 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008275 let g:netrw_quiet = 1
8276 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008277 let s:rexposn_{bufnr("%")}= winsaveview()
8278" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008279 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008280 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008281 else
8282 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8283 endif
8284 if exists("netrw_quiet_keep")
8285 let g:netrw_quiet= netrw_quiet_keep
8286 else
8287 unlet g:netrw_quiet
8288 endif
8289 endif
8290 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008291 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008292 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008293 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008294" call Dret("s:NetrwOpenFile")
8295endfun
8296
8297" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008298" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8299" For the mapping to this function be made via
8300" netrwPlugin, you'll need to have had
8301" g:netrw_usetab set to non-zero.
8302fun! netrw#Shrink()
8303" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8304 let curwin = winnr()
8305 let wiwkeep = &wiw
8306 set wiw=1
8307
8308 if &ft == "netrw"
8309 if winwidth(0) > g:netrw_wiw
8310 let t:netrw_winwidth= winwidth(0)
8311 exe "vert resize ".g:netrw_wiw
8312 wincmd l
8313 if winnr() == curwin
8314 wincmd h
8315 endif
8316" call Decho("vert resize 0",'~'.expand("<slnum>"))
8317 else
8318 exe "vert resize ".t:netrw_winwidth
8319" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8320 endif
8321
8322 elseif exists("t:netrw_lexbufnr")
8323 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8324 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8325 let t:netrw_winwidth= winwidth(0)
8326 exe "vert resize ".g:netrw_wiw
8327 wincmd l
8328 if winnr() == curwin
8329 wincmd h
8330 endif
8331" call Decho("vert resize 0",'~'.expand("<slnum>"))
8332 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8333 exe "vert resize ".t:netrw_winwidth
8334" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8335 else
8336 call netrw#Lexplore(0,0)
8337 endif
8338
8339 else
8340 call netrw#Lexplore(0,0)
8341 endif
8342 let wiw= wiwkeep
8343
8344" call Dret("netrw#Shrink")
8345endfun
8346
8347" ---------------------------------------------------------------------
8348" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8349fun! s:NetSortSequence(islocal)
8350" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8351
8352 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008353 let svpos= winsaveview()
8354" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008355 call inputsave()
8356 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8357 call inputrestore()
8358
8359 " refresh the listing
8360 let g:netrw_sort_sequence= newsortseq
8361 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008362" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8363 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008364 let @@= ykeep
8365
8366" call Dret("NetSortSequence")
8367endfun
8368
8369" ---------------------------------------------------------------------
8370" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8371" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008372" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008373fun! s:NetrwUnmarkList(curbufnr,curdir)
8374" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8375
8376 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008377 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008378 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8379 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8380 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8381 call remove(s:netrwmarkfilelist,idx) " remove from global list
8382 endfor
8383 if s:netrwmarkfilelist == []
8384 unlet s:netrwmarkfilelist
8385 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008386
Bram Moolenaar446cb832008-06-24 21:56:24 +00008387 " getting rid of the local marked-file lists is easy
8388 unlet s:netrwmarkfilelist_{a:curbufnr}
8389 endif
8390 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8391 unlet s:netrwmarkfilemtch_{a:curbufnr}
8392 endif
8393 2match none
8394" call Dret("s:NetrwUnmarkList")
8395endfun
8396
8397" ---------------------------------------------------------------------
8398" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8399fun! s:NetrwUnmarkAll()
8400" call Dfunc("s:NetrwUnmarkAll()")
8401 if exists("s:netrwmarkfilelist")
8402 unlet s:netrwmarkfilelist
8403 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008404 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008405 2match none
8406" call Dret("s:NetrwUnmarkAll")
8407endfun
8408
8409" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008410" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008411fun! s:NetrwUnmarkAll2()
8412" call Dfunc("s:NetrwUnmarkAll2()")
8413 redir => netrwmarkfilelist_let
8414 let
8415 redir END
8416 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008417 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008418 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8419 for flist in netrwmarkfilelist_list
8420 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8421 unlet s:netrwmarkfilelist_{curbufnr}
8422 unlet s:netrwmarkfilemtch_{curbufnr}
8423 endfor
8424" call Dret("s:NetrwUnmarkAll2")
8425endfun
8426
8427" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008428" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8429"
8430" Marked files are in two types of lists:
8431" s:netrwmarkfilelist -- holds complete paths to all marked files
8432" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8433"
8434" Marked files suitable for use with 2match are in:
8435" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008436fun! s:NetrwUnMarkFile(islocal)
8437" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008438 let svpos = winsaveview()
8439" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008440 let curbufnr = bufnr("%")
8441
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008442 " unmark marked file list
8443 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8444 if exists("s:netrwmarkfilelist")
8445" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008446 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008447 endif
8448
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008449 let ibuf= 1
8450 while ibuf < bufnr("$")
8451 if exists("s:netrwmarkfilelist_".ibuf)
8452 unlet s:netrwmarkfilelist_{ibuf}
8453 unlet s:netrwmarkfilemtch_{ibuf}
8454 endif
8455 let ibuf = ibuf + 1
8456 endwhile
8457 2match none
8458
Bram Moolenaar446cb832008-06-24 21:56:24 +00008459" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008460"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8461call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008462" call Dret("s:NetrwUnMarkFile")
8463endfun
8464
8465" ---------------------------------------------------------------------
8466" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8467fun! s:NetrwMenu(domenu)
8468
8469 if !exists("g:NetrwMenuPriority")
8470 let g:NetrwMenuPriority= 80
8471 endif
8472
Bram Moolenaaradc21822011-04-01 18:03:16 +02008473 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008474" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8475
8476 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008477" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008478 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008479 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8480 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8481 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8482 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8483 if g:netrw_dirhistmax > 0
8484 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8485 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8486 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8487 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8488 else
8489 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8490 endif
8491 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8492 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8495 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8497 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8500 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8505 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 +01008506 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 +02008507 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8536 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>'
8537 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>'
8538 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>'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8540 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>'
8541 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>'
8542 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 +01008543 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 +02008544 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008546 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008547 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8548 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008549
8550 elseif !a:domenu
8551 let s:netrwcnt = 0
8552 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008553 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008554 exe curwin."wincmd w"
8555
8556 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008557" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008558 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008559" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008560 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008561 endif
8562 endif
8563" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008564 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008565 endif
8566
8567endfun
8568
8569" ---------------------------------------------------------------------
8570" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8571" Used by the O maps (as <SID>NetrwObtain())
8572fun! s:NetrwObtain(islocal)
8573" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8574
Bram Moolenaar97d62492012-11-15 21:28:22 +01008575 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008576 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008577 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008578 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008579 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8580 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008581 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008582 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008583 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008584
8585" call Dret("NetrwObtain")
8586endfun
8587
8588" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008589" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8590" If there's only one window, then the window will first be split.
8591" Returns:
8592" choice = 0 : didn't have to choose
8593" choice = 1 : saved modified file in window first
8594" choice = 2 : didn't save modified file, opened window
8595" choice = 3 : cancel open
8596fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008597" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008598
Bram Moolenaar97d62492012-11-15 21:28:22 +01008599 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008600 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008601 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008602" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008603
8604 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008605 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008606 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008607" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8608" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8609 let curword = s:NetrwGetWord()
8610 let choice = 0
8611 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8612" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008613 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008614" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008615 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008616" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008617" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008618" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008619
Bram Moolenaar8d043172014-01-23 14:24:41 +01008620 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008621 if lastwinnr == 1
8622 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008623" 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 +02008624 " g:netrw_preview=0: preview window shown in a horizontally split window
8625 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008626 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008627 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008628 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008629" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008630 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008631 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008632 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008633 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008634" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008635 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008636 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008637 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008638" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008639
8640 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008641" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008642 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008643" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008644 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008645" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008646 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008647" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008648 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008649" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008650" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008651" call Decho("COMBAK#12: mod=".&mod)
8652
8653 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8654 " whoops -- user trying to open file in the Lexplore window.
8655 " Use Lexplore's opening-file window instead.
8656" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8657" exe g:netrw_chgwin."wincmd w"
8658 wincmd p
8659 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8660 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008661
8662 " prevwinnr: the window number of the "prev" window
8663 " prevbufnr: the buffer number of the buffer in the "prev" window
8664 " bnrcnt : the qty of windows open on the "prev" buffer
8665 let prevwinnr = winnr()
8666 let prevbufnr = bufnr("%")
8667 let prevbufname = bufname("%")
8668 let prevmod = &mod
8669 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008670" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008671 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008672" 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 +01008673" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008674
8675 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008676 " and it doesn't appear in any other extant window, then ask the
8677 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008678 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008679" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008680 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008681" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008682 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008683" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008684
8685 if bnrcnt == 1 && &hidden == 0
8686 " only one copy of the modified buffer in a window, and
8687 " hidden not set, so overwriting will lose the modified file. Ask first...
8688 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008689" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008690 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008691" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008692
8693 if choice == 1
8694 " Yes -- write file & then browse
8695 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008696 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008697 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008698 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008699 exe origwin."wincmd w"
8700 let &ei = eikeep
8701 let @@ = ykeep
8702" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008703 return choice
8704 endif
8705
8706 elseif choice == 2
8707 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008708" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008709 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008710
8711 else
8712 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008713" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008714 exe origwin."wincmd w"
8715 let &ei= eikeep
8716 let @@ = ykeep
8717" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008718 return choice
8719 endif
8720 endif
8721 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008722 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008723 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008724" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008725
8726 " restore b:netrw_curdir (window split/enew may have lost it)
8727 let b:netrw_curdir= curdir
8728 if a:islocal < 2
8729 if a:islocal
8730 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8731 else
8732 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8733 endif
8734 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008735 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008736" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008737 return choice
8738endfun
8739
8740" ---------------------------------------------------------------------
8741" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8742" Always assumed to be local -> remote
8743" call s:NetrwUpload(filename, target)
8744" call s:NetrwUpload(filename, target, fromdirectory)
8745fun! s:NetrwUpload(fname,tgt,...)
8746" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8747
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008748 if a:tgt =~ '^\a\{3,}://'
8749 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008750 else
8751 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8752 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008753" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008754
8755 if a:0 > 0
8756 let fromdir= a:1
8757 else
8758 let fromdir= getcwd()
8759 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008760" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008761
8762 if type(a:fname) == 1
8763 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008764" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008765 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008766" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8767 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8768" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008769 if a:tgt =~ '/$'
8770 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008771" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008772 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008773 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008774" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008775 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008776" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008777 endif
8778 q!
8779
8780 elseif type(a:fname) == 3
8781 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008782" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008783 let curdir= getcwd()
8784 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008785 if s:NetrwLcd(fromdir)
8786" call Dret("s:NetrwUpload : lcd failure")
8787 return
8788 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008789 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008790 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008791 if exists("g:netrw_port") && g:netrw_port != ""
8792 let useport= " ".g:netrw_scpport." ".g:netrw_port
8793 else
8794 let useport= ""
8795 endif
8796 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8797 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008798 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 +02008799 if s:NetrwLcd(curdir)
8800" call Dret("s:NetrwUpload : lcd failure")
8801 return
8802 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008803
8804 elseif a:tgt =~ '^ftp:'
8805 call s:NetrwMethod(a:tgt)
8806
8807 if b:netrw_method == 2
8808 " handle uploading a list of files via ftp+.netrc
8809 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008810 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008811" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008812
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008813 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008814" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008815
8816 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008817 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008818" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008819 endif
8820
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008821 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008822" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008823
Bram Moolenaaradc21822011-04-01 18:03:16 +02008824 if tgtdir == ""
8825 let tgtdir= '/'
8826 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008827 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008828" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008829
8830 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008831 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8832" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008833 endfor
8834
8835 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008836 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 +00008837 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008838" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8839 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008840 endif
8841 " 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 +01008842 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008843 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008844 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8845 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8846 else
8847 bw!|q
8848 endif
8849
8850 elseif b:netrw_method == 3
8851 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8852 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008853 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008854 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008855 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856
8857 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008858 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008859" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008860 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008861 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008862" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008863 endif
8864
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008865 if exists("g:netrw_uid") && g:netrw_uid != ""
8866 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008867 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008868" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008869 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008870 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008871 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008872" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008873 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008874 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008875" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008876 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008877 endif
8878
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008879 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008880" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008881
8882 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008883 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008884" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008885 endif
8886
8887 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008888 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008889" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008890 endif
8891
8892 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008893 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008894" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008895 endfor
8896
8897 " perform ftp:
8898 " -i : turns off interactive prompting from ftp
8899 " -n unix : DON'T use <.netrc>, even though it exists
8900 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008901 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008902 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008903 " 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 +01008904 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008905 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008906 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8907 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008908 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008909 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8910 let &debug = debugkeep
8911 let mod = 1
8912 else
8913 bw!|q
8914 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008915 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008916" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008917 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008918 endif
8919 else
8920 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8921 endif
8922 endif
8923
8924" call Dret("s:NetrwUpload")
8925endfun
8926
8927" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008928" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008929fun! s:NetrwPreview(path) range
8930" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008931" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8932" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008933 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008934 NetrwKeepj call s:NetrwOptionsSave("s:")
8935 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8936 NetrwKeepj call s:NetrwOptionsSafe(1)
8937 else
8938 NetrwKeepj call s:NetrwOptionsSafe(0)
8939 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008940 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008941" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008942 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008943" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8944 if g:netrw_preview
8945 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008946 let pvhkeep = &pvh
8947 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8948 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008949" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8950 else
8951 " horizontal split
8952 let pvhkeep = &pvh
8953 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8954 let &pvh = winheight(0) - winsz
8955" 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 +02008956 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008957 " g:netrw_preview g:netrw_alto
8958 " 1 : vert 1: top -- preview window is vertically split off and on the left
8959 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8960 " 0 : 1: top -- preview window is horizontally split off and on the top
8961 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8962 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008963 " 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 +02008964 " the BufEnter event set up in netrwPlugin.vim
8965" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8966 let eikeep = &ei
8967 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008968 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008969 let &ei= eikeep
8970" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008971 if exists("pvhkeep")
8972 let &pvh= pvhkeep
8973 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008974 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008975 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008976 endif
8977 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008978 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 +00008979 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008980 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008981 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008982" call Dret("NetrwPreview")
8983endfun
8984
8985" ---------------------------------------------------------------------
8986" s:NetrwRefresh: {{{2
8987fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008988" 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 +00008989 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008990 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008991" call Decho("setl ma noro",'~'.expand("<slnum>"))
8992" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008993 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008994 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8995 if !exists("w:netrw_treetop")
8996 if exists("b:netrw_curdir")
8997 let w:netrw_treetop= b:netrw_curdir
8998 else
8999 let w:netrw_treetop= getcwd()
9000 endif
9001 endif
9002 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9003 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009004
9005 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009006 let screenposn = winsaveview()
9007" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009008
9009" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9010" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9011 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009012 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009013 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009014 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009015 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009016 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009017
9018 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009019" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9020 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009021
9022 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009023 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9024 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9025" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9026 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9027 else
9028" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9029 2match none
9030 endif
9031 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009032
Bram Moolenaar97d62492012-11-15 21:28:22 +01009033" restore
9034 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009035" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009036endfun
9037
9038" ---------------------------------------------------------------------
9039" s:NetrwRefreshDir: refreshes a directory by name {{{2
9040" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009041" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009042fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009043" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009044 if g:netrw_fastbrowse == 0
9045 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009046" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009047 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009048" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009049
9050 if tgtwin > 0
9051 " tgtwin is being displayed, so refresh it
9052 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009053" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009055 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009056 exe curwin."wincmd w"
9057
9058 elseif bufnr(a:dirname) > 0
9059 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009060" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9061 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009062 endif
9063
9064 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009065" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009066 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009067 endif
9068" call Dret("s:NetrwRefreshDir")
9069endfun
9070
9071" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009072" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9073" window number to do its editing in.
9074" Supports [count]C where the count, if present, is used to specify
9075" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009076fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009077" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009078 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009079" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009080 if a:1 == "" " :NetrwC win#
9081 let g:netrw_chgwin= winnr()
9082 else " :NetrwC
9083 let g:netrw_chgwin= a:1
9084 endif
9085 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009086 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009087 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009088 let g:netrw_chgwin= winnr()
9089 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009090 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009091" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009092endfun
9093
9094" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009095" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9096" What this function does is to compute a priority for the patterns
9097" in the g:netrw_sort_sequence. It applies a substitute to any
9098" "files" that satisfy each pattern, putting the priority / in
9099" front. An "*" pattern handles the default priority.
9100fun! s:NetrwSetSort()
9101" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009102 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009103 if w:netrw_liststyle == s:LONGLIST
9104 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9105 else
9106 let seqlist = g:netrw_sort_sequence
9107 endif
9108 " sanity check -- insure that * appears somewhere
9109 if seqlist == ""
9110 let seqlist= '*'
9111 elseif seqlist !~ '\*'
9112 let seqlist= seqlist.',*'
9113 endif
9114 let priority = 1
9115 while seqlist != ""
9116 if seqlist =~ ','
9117 let seq = substitute(seqlist,',.*$','','e')
9118 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9119 else
9120 let seq = seqlist
9121 let seqlist = ""
9122 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009123 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009124 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009125 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009126 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009127 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009128 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009129 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009130" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009131
9132 " sanity check
9133 if w:netrw_bannercnt > line("$")
9134 " apparently no files were left after a Hiding pattern was used
9135" call Dret("SetSort : no files left after hiding")
9136 return
9137 endif
9138 if seq == '*'
9139 let starpriority= spriority
9140 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009141 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009142 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009143 " sometimes multiple sorting patterns will match the same file or directory.
9144 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009145 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9146 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009147 endif
9148 let priority = priority + 1
9149 endwhile
9150 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009151 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9152 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009153 endif
9154
9155 " Following line associated with priority -- items that satisfy a priority
9156 " pattern get prefixed by ###/ which permits easy sorting by priority.
9157 " Sometimes files can satisfy multiple priority patterns -- only the latest
9158 " priority pattern needs to be retained. So, at this point, these excess
9159 " priority prefixes need to be removed, but not directories that happen to
9160 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009161 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9162 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009163 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009164
9165" call Dret("SetSort")
9166endfun
9167
Bram Moolenaarff034192013-04-24 18:51:19 +02009168" ---------------------------------------------------------------------
9169" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9170" Implements [count]Tb (bookhist<b>)
9171" [count]Th (bookhist<h>)
9172" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009173fun! s:NetrwSetTgt(islocal,bookhist,choice)
9174" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009175
9176 if a:bookhist == 'b'
9177 " supports choosing a bookmark as a target using a qb-generated list
9178 let choice= a:choice - 1
9179 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009180 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009181 else
9182 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9183 endif
9184
9185 elseif a:bookhist == 'h'
9186 " supports choosing a history stack entry as a target using a qb-generated list
9187 let choice= (a:choice % g:netrw_dirhistmax) + 1
9188 if exists("g:netrw_dirhist_".choice)
9189 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009190 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009191 else
9192 echomsg "Sorry, history#".a:choice." not available!"
9193 endif
9194 endif
9195
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009196 " refresh the display
9197 if !exists("b:netrw_curdir")
9198 let b:netrw_curdir= getcwd()
9199 endif
9200 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9201
Bram Moolenaarff034192013-04-24 18:51:19 +02009202" call Dret("s:NetrwSetTgt")
9203endfun
9204
Bram Moolenaar446cb832008-06-24 21:56:24 +00009205" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009206" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009207fun! s:NetrwSortStyle(islocal)
9208" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009209 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009210 let svpos= winsaveview()
9211" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009212
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009213 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 +01009214 NetrwKeepj norm! 0
9215 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009216" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9217 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009218
9219" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9220endfun
9221
9222" ---------------------------------------------------------------------
9223" s:NetrwSplit: mode {{{2
9224" =0 : net and o
9225" =1 : net and t
9226" =2 : net and v
9227" =3 : local and o
9228" =4 : local and t
9229" =5 : local and v
9230fun! s:NetrwSplit(mode)
9231" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9232
Bram Moolenaar97d62492012-11-15 21:28:22 +01009233 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009234 call s:SaveWinVars()
9235
9236 if a:mode == 0
9237 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009238 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009239 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009240" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009241 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009242 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009243 NetrwKeepj call s:RestoreWinVars()
9244 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009245 unlet s:didsplit
9246
9247 elseif a:mode == 1
9248 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009249 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009250" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009251 tabnew
9252 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009253 NetrwKeepj call s:RestoreWinVars()
9254 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009255 unlet s:didsplit
9256
9257 elseif a:mode == 2
9258 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009259 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009260 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009261" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009262 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009263 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009264 NetrwKeepj call s:RestoreWinVars()
9265 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009266 unlet s:didsplit
9267
9268 elseif a:mode == 3
9269 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009270 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009271 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009272" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009273 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009274 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009275 NetrwKeepj call s:RestoreWinVars()
9276 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009277 unlet s:didsplit
9278
9279 elseif a:mode == 4
9280 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009281 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009282 let eikeep = &ei
9283 let netrw_winnr = winnr()
9284 let netrw_line = line(".")
9285 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009286 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009287 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009288 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009289 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9290 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009291 let &ei = eikeep
9292 let netrw_curdir = s:NetrwTreeDir(0)
9293" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009294 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009295 let b:netrw_curdir = netrw_curdir
9296 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009297 NetrwKeepj call s:RestoreWinVars()
9298 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009299 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009300 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009301 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9302 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009303 let &ei= eikeep
9304 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009305 unlet s:didsplit
9306
9307 elseif a:mode == 5
9308 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009309 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009310 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009311" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009312 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009313 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009314 NetrwKeepj call s:RestoreWinVars()
9315 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009316 unlet s:didsplit
9317
9318 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009319 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009320 endif
9321
Bram Moolenaar97d62492012-11-15 21:28:22 +01009322 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009323" call Dret("s:NetrwSplit")
9324endfun
9325
9326" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009327" s:NetrwTgtMenu: {{{2
9328fun! s:NetrwTgtMenu()
9329 if !exists("s:netrw_menucnt")
9330 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009331 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009332" call Dfunc("s:NetrwTgtMenu()")
9333
9334 " the following test assures that gvim is running, has menus available, and has menus enabled.
9335 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9336 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009337" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009338 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9339 endif
9340 if !exists("s:netrw_initbookhist")
9341 call s:NetrwBookHistRead()
9342 endif
9343
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009344 " try to cull duplicate entries
9345 let tgtdict={}
9346
Bram Moolenaarff034192013-04-24 18:51:19 +02009347 " target bookmarked places
9348 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009349" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009350 let cnt= 1
9351 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009352 if has_key(tgtdict,bmd)
9353 let cnt= cnt + 1
9354 continue
9355 endif
9356 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009357 let ebmd= escape(bmd,g:netrw_menu_escape)
9358 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009359" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009360 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 +02009361 let cnt= cnt + 1
9362 endfor
9363 endif
9364
9365 " target directory browsing history
9366 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009367" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009368 let histcnt = 1
9369 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009370 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009371 if exists("g:netrw_dirhist_{histcnt}")
9372 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009373 if has_key(tgtdict,histentry)
9374 let histcnt = histcnt + 1
9375 continue
9376 endif
9377 let tgtdict[histentry] = histcnt
9378 let ehistentry = escape(histentry,g:netrw_menu_escape)
9379" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009380 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 +02009381 endif
9382 let histcnt = histcnt + 1
9383 endwhile
9384 endif
9385 endif
9386" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009387endfun
9388
9389" ---------------------------------------------------------------------
9390" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9391" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009392fun! s:NetrwTreeDir(islocal)
9393" 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 +02009394" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009395" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9396" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9397" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009398" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009399
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009400 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009401 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009402" 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 +01009403 let treedir= s:treedir
9404 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009405 unlet s:prevwinopen
9406" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009407 return treedir
9408 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009409 if exists("s:prevwinopen")
9410 unlet s:prevwinopen
9411 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009412" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009413
Bram Moolenaar8d043172014-01-23 14:24:41 +01009414 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9415 let b:netrw_curdir= getcwd()
9416 endif
9417 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009418" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009419" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009420
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009421 let s:treecurpos= winsaveview()
9422" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009423" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009424
9425 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009426" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9427" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009428" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009429
9430 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009431 let curline= substitute(getline('.'),"\t -->.*$",'','')
9432 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009433" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009434 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009435" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9436 elseif curline =~ '@$'
9437" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009438 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009439" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009440 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009441" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009442 let treedir= ""
9443 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009444" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009445
9446 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009447" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9448" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009449" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009450 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009451" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009452 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009453" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9454 sil! NetrwKeepj %d _
9455" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009456 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009457" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009458" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009459 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009460" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009461
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009462" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009463" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009464" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009465
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009466 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9467" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9468" let newdir = w:netrw_treetop.'/'.potentialdir
9469" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9470" let treedir = s:NetrwTreePath(newdir)
9471" let w:netrw_treetop = newdir
9472" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9473" else
9474" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009475 if a:islocal && curline =~ '@$'
9476 if isdirectory(s:NetrwFile(potentialdir))
9477 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9478 let w:netrw_treetop = treedir
9479 endif
9480 else
9481 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9482 let treedir = s:NetrwTreePath(w:netrw_treetop)
9483 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009484 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009485" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009486
9487 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009488 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009489" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009490" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009491
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009492" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009493 return treedir
9494endfun
9495
9496" ---------------------------------------------------------------------
9497" s:NetrwTreeDisplay: recursive tree display {{{2
9498fun! s:NetrwTreeDisplay(dir,depth)
9499" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9500
9501 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009502 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009503
9504 " install ../ and shortdir
9505 if a:depth == ""
9506 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009507" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009508 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009509 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009510 if a:dir == w:netrw_treetop
9511 let shortdir= a:dir
9512 else
9513 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9514 endif
9515 call setline(line("$")+1,a:depth.shortdir)
9516 else
9517 let shortdir= substitute(a:dir,'^.*/','','e')
9518 call setline(line("$")+1,a:depth.shortdir.'/')
9519 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009520" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009521 " append a / to dir if its missing one
9522 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009523
9524 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009525 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009526" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009527
Bram Moolenaar85850f32019-07-19 22:05:51 +02009528 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9529 if g:netrw_hide == 1
9530 " hide given patterns
9531 let listhide= split(g:netrw_list_hide,',')
9532" call Decho("listhide=".string(listhide))
9533 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009534 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009535 endfor
9536
9537 elseif g:netrw_hide == 2
9538 " show given patterns (only)
9539 let listhide= split(g:netrw_list_hide,',')
9540" call Decho("listhide=".string(listhide))
9541 let entries=[]
9542 for entry in w:netrw_treedict[dir]
9543 for pat in listhide
9544 if entry =~ pat
9545 call add(entries,entry)
9546 break
9547 endif
9548 endfor
9549 endfor
9550 let w:netrw_treedict[dir]= entries
9551 endif
9552 if depth != ""
9553 " always remove "." and ".." entries when there's depth
9554 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9555 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9556 endif
9557
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009558" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009559 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009560 if dir =~ '/$'
9561 let direntry= substitute(dir.entry,'[@/]$','','e')
9562 else
9563 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9564 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009565" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009566 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009567" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009568 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009569 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009570" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9571 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9572 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9573" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009574 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009575 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009576" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009577 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578 endif
9579 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009580" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009581
Bram Moolenaar446cb832008-06-24 21:56:24 +00009582" call Dret("NetrwTreeDisplay")
9583endfun
9584
9585" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009586" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9587fun! s:NetrwRefreshTreeDict(dir)
9588" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009589 if !exists("w:netrw_treedict")
9590" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9591 return
9592 endif
9593
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009594 for entry in w:netrw_treedict[a:dir]
9595 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9596" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9597
9598 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9599" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9600 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009601 let liststar = s:NetrwGlob(direntry,'*',1)
9602 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009603 let w:netrw_treedict[direntry] = liststar + listdotstar
9604" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9605
9606 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9607" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9608 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009609 let liststar = s:NetrwGlob(direntry.'/','*',1)
9610 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009611 let w:netrw_treedict[direntry]= liststar + listdotstar
9612" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9613
9614 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9615" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9616 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009617 let liststar = s:NetrwGlob(direntry.'/','*',1)
9618 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009619" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9620
9621 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009622" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009623 endif
9624 endfor
9625" call Dret("s:NetrwRefreshTreeDict")
9626endfun
9627
9628" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009629" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009630" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009631fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009632 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009633" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009634" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9635" 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>"))
9636" 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 +00009637
9638 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009639 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009640" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009641 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009642 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009643" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009644 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 +02009645" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009646 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009647 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009648" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009649 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009650 if exists("w:netrw_treetop")
9651 let s:netrw_treetop= w:netrw_treetop
9652 else
9653 let w:netrw_treetop= getcwd()
9654 let s:netrw_treetop= w:netrw_treetop
9655 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009656
Bram Moolenaar446cb832008-06-24 21:56:24 +00009657 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009658 " insure that we have a treedict, albeit empty
9659" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009660 let w:netrw_treedict= {}
9661 endif
9662
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009663 " update the dictionary for the current directory
9664" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009665" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009666 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009667 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009668" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009669 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009670
9671 " if past banner, record word
9672 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9673 let fname= expand("<cword>")
9674 else
9675 let fname= ""
9676 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009677" call Decho("fname<".fname.">",'~'.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 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009681" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009682 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009683" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009684
9685 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9686 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009687" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009688 1d
9689 endwhile
9690
Bram Moolenaar13600302014-05-22 18:26:40 +02009691 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009692
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009693" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009694 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009695 endif
9696endfun
9697
9698" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009699" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009700" Normally, treetop is w:netrw_treetop, but a
9701" user of the function ( netrw#SetTreetop() )
9702" wipes that out prior to calling this function
9703fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009704" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9705 if line(".") < w:netrw_bannercnt + 2
9706 let treedir= a:treetop
9707 if treedir !~ '/$'
9708 let treedir= treedir.'/'
9709 endif
9710" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9711 return treedir
9712 endif
9713
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009714 let svpos = winsaveview()
9715" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009716 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009717" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009718 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009719" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9720 let curline= getline('.')
9721" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9722 if curline =~ '/$'
9723" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9724 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9725" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9726 elseif curline =~ '@\s\+-->'
9727" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9728 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9729 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9730" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009731 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009732" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009733 let treedir= ""
9734 endif
9735 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009736" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9737" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009738 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9739 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9740 let treedir= dirname.treedir
9741 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009742" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009743 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009744" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009745 if a:treetop =~ '/$'
9746 let treedir= a:treetop.treedir
9747 else
9748 let treedir= a:treetop.'/'.treedir
9749 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009750" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009751 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009752" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009753" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9754 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009755" call Dret("s:NetrwTreePath <".treedir.">")
9756 return treedir
9757endfun
9758
9759" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009760" s:NetrwWideListing: {{{2
9761fun! s:NetrwWideListing()
9762
9763 if w:netrw_liststyle == s:WIDELIST
9764" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9765 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009766 " cpf: characters per filename
9767 " fpl: filenames per line
9768 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009769 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009770 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009771" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009772 let b:netrw_cpf= 0
9773 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009774 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009775 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9776 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009777 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009778 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009779" call Dret("NetrwWideListing")
9780 return
9781 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009782 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009783 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009784" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009785
9786 " determine qty files per line (fpl)
9787 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9788 if w:netrw_fpl <= 0
9789 let w:netrw_fpl= 1
9790 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009791" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009792
9793 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009794 " fpc: files per column of wide listing
9795 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009796 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009797 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9798 let newcolstart = w:netrw_bannercnt + fpc
9799 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009800" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009801 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009802" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009803 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009804 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009805 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009806 while line("$") >= newcolstart
9807 if newcolend > line("$") | let newcolend= line("$") | endif
9808 let newcolqty= newcolend - newcolstart
9809 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009810 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009811 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009812 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009813 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009814 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009815 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009816 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009817 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009818 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009819 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009820" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009821 if @* != keepregstar | sil! let @* = keepregstar | endif
9822 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009823 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009824 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9825 NetrwKeepj call histdel("/",-1)
9826 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9827 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009828" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009829 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009830 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009831" 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 +00009832" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009833 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009834 else
9835 if hasmapto("w","n")
9836 sil! nunmap <buffer> w
9837 endif
9838 if hasmapto("b","n")
9839 sil! nunmap <buffer> b
9840 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009841 endif
9842
9843endfun
9844
9845" ---------------------------------------------------------------------
9846" s:PerformListing: {{{2
9847fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009848" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9849" 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 +02009850" 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>"))
9851 sil! NetrwKeepj %d _
9852" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009853
Bram Moolenaar15146672011-10-20 22:22:38 +02009854 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009855" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009856 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009857
Bram Moolenaar85850f32019-07-19 22:05:51 +02009858 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009859 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009860" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009861
9862" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009863" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009864" endif " Decho
9865
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009866" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009867 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9868 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009869" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9870 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009871 endif
9872
9873 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009874 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009875
9876 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009877 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009878" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009879 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009880 if exists("g:netrw_pchk")
9881 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9882 " failure detections.
9883 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009884 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009885 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9886 endif
9887 if exists("g:netrw_pchk")
9888 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9889 else
9890 let curdir= b:netrw_curdir
9891 endif
9892 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9893 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9894 else
9895 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009896 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009897 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009898 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009899 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009900" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009901 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009902 let w:netrw_bannercnt= 1
9903 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009904" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9905" 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 +00009906
Bram Moolenaar85850f32019-07-19 22:05:51 +02009907 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009908 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009909 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009910 let sortby= sortby." reversed"
9911 endif
9912
9913 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009914 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009915" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009916 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009917" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009918 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009919 NetrwKeepj put ='\" Sorted by '.sortby
9920 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009921 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9922 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009923" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009924 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009925 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009926 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9927 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009928 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009929" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009930" 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 +00009931 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009932
Bram Moolenaar85850f32019-07-19 22:05:51 +02009933 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009934 if g:netrw_banner
9935 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009936" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009937 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009938 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009939 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009940 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009941 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009942 endif
9943 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009944 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009945" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009946 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009947 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009948 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009949
9950 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009951 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009952" 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 +01009953 if g:netrw_list_hide != "" && g:netrw_hide
9954 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009955 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009956 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009957 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009958 endif
9959 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009960 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009961 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009962
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009963" 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 +01009964 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009965" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009966 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009967" 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 +01009968 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009969 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009970" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009971" 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 +00009972 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009973
9974 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009975 if g:netrw_banner
9976 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009977 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009978" 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 +01009979" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009980" 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 +01009981 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009982
Bram Moolenaar446cb832008-06-24 21:56:24 +00009983 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009984" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009985 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009986 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009987 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009988 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009989 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009990" 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 +01009991" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9992 return
9993 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009994 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009995
9996 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009997 if !exists("w:netrw_bannercnt")
9998 let w:netrw_bannercnt= 0
9999 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010000" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10001" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10002" 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 +010010003
Bram Moolenaar5c736222010-01-06 20:54:52 +010010004 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010005" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010006" 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 +000010007 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010008 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010009 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010010 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010011" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010012
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010013 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010014 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010015" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010016 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010017
Bram Moolenaar5c736222010-01-06 20:54:52 +010010018 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010019" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010020 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010021 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010022 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010023 else
10024 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010025 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010026 endif
10027 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010028
Bram Moolenaar446cb832008-06-24 21:56:24 +000010029 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010030" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010031 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10032 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010033
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010034 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010035 " exten: sort by extension
10036 " The histdel(...,-1) calls remove the last search from the search history
10037" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010038 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10039 NetrwKeepj call histdel("/",-1)
10040 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10041 NetrwKeepj call histdel("/",-1)
10042 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10043 NetrwKeepj call histdel("/",-1)
10044 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10045" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010046 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010047 " normal direction sorting
10048 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10049 else
10050 " reverse direction sorting
10051 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10052 endif
10053 endif
10054 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10055 NetrwKeepj call histdel("/",-1)
10056
Bram Moolenaar446cb832008-06-24 21:56:24 +000010057 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010058 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010059" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010060 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010061" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010062 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010063 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010064" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010065 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010066 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010067" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010068 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10069 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010070 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010071 endif
10072
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010073 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010074" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010075 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010076 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010077 call histdel("/",-1)
10078 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010079 endif
10080 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010081" 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 +000010082
10083 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010084" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10085" 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 +010010086 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010087" 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 +010010088 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010089" 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 +000010090
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010091 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010092 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010093" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010094 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010095 endif
10096
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010097 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010098 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010099" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10100 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010101 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010102" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10103 else
10104" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10105" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10106" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10107" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010108 endif
10109
10110 " record previous current directory
10111 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010112" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010113
10114 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010115" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10116" 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 +010010117 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010118" 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 +020010119 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" 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 +000010121
10122 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010123" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010124 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010125" 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 +010010126 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010127" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010128 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10129 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010130" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010131" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010132
Bram Moolenaar8d043172014-01-23 14:24:41 +010010133 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010134" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10135" 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 +010010136" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10137 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010138 unlet s:treecurpos
10139 endif
10140
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010141" 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>"))
10142" 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 +000010143" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10144endfun
10145
10146" ---------------------------------------------------------------------
10147" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010148fun! s:SetupNetrwStatusLine(statline)
10149" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10150
10151 if !exists("s:netrw_setup_statline")
10152 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010153" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010154
10155 if !exists("s:netrw_users_stl")
10156 let s:netrw_users_stl= &stl
10157 endif
10158 if !exists("s:netrw_users_ls")
10159 let s:netrw_users_ls= &laststatus
10160 endif
10161
10162 " set up User9 highlighting as needed
10163 let keepa= @a
10164 redir @a
10165 try
10166 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010167 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010168 if &bg == "dark"
10169 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10170 else
10171 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10172 endif
10173 endtry
10174 redir END
10175 let @a= keepa
10176 endif
10177
10178 " set up status line (may use User9 highlighting)
10179 " insure that windows have a statusline
10180 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010181 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010182 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010183" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010184 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010185
10186" call Dret("SetupNetrwStatusLine : stl=".&stl)
10187endfun
10188
Bram Moolenaar85850f32019-07-19 22:05:51 +020010189" =========================================
10190" Remote Directory Browsing Support: {{{1
10191" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010192
10193" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010194" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10195" This function assumes that a long listing will be received. Size, time,
10196" and reverse sorts will be requested of the server but not otherwise
10197" enforced here.
10198fun! s:NetrwRemoteFtpCmd(path,listcmd)
10199" 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 +010010200" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010201 " sanity check: {{{3
10202 if !exists("w:netrw_method")
10203 if exists("b:netrw_method")
10204 let w:netrw_method= b:netrw_method
10205 else
10206 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10207" call Dret("NetrwRemoteFtpCmd")
10208 return
10209 endif
10210 endif
10211
10212 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10213 let ffkeep= &ff
10214 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010215" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010216
10217 " clear off any older non-banner lines " {{{3
10218 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010219" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10220 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010221
10222 ".........................................
10223 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10224 " ftp + <.netrc>: Method #2
10225 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010226 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010227 endif
10228 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010229 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010230" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010231 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010232 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010233" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010234 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010235" 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>"))
10236 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 +010010237 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010238" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10239 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 +010010240 endif
10241
10242 ".........................................
10243 elseif w:netrw_method == 3 " {{{3
10244 " ftp + machine,id,passwd,filename: Method #3
10245 setl ff=unix
10246 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010247 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010248 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010249 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010250 endif
10251
10252 " handle userid and password
10253 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010254" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010255 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10256 call NetUserPass("ftp:".host)
10257 endif
10258 if exists("g:netrw_uid") && g:netrw_uid != ""
10259 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010260 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010261 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010262 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010263 endif
10264 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010265 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010266 endif
10267 endif
10268
10269 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010270 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010271 endif
10272 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010273 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010274" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010275 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010276 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010277
10278 " perform ftp:
10279 " -i : turns off interactive prompting from ftp
10280 " -n unix : DON'T use <.netrc>, even though it exists
10281 " -n win32: quit being obnoxious about password
10282 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010283" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010284 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010285" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010286" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10287" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010288 endif
10289
10290 ".........................................
10291 elseif w:netrw_method == 9 " {{{3
10292 " sftp username@machine: Method #9
10293 " s:netrw_sftp_cmd
10294 setl ff=unix
10295
10296 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010297 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010298" call Dret("NetrwRemoteFtpCmd")
10299 return
10300
10301 ".........................................
10302 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010303 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010304 endif
10305
10306 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010307 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010308 sil! NetrwKeepj %s/\r$//e
10309 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010310 endif
10311 if a:listcmd == "dir"
10312 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010313 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10314 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10315 NetrwKeepj call histdel("/",-1)
10316 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010317 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 +010010318 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10319 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010320 endif
10321 endif
10322
10323 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10324 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010325 exe 'NetrwKeepj '.w:netrw_bannercnt
10326 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010327 endif
10328 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010329 exe 'NetrwKeepj '.w:netrw_bannercnt
10330 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010331 endif
10332
10333 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010334 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010335" call Dret("NetrwRemoteFtpCmd")
10336endfun
10337
10338" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010339" s:NetrwRemoteListing: {{{2
10340fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010341" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010342
Bram Moolenaara6878372014-03-22 21:02:50 +010010343 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10344 let w:netrw_bannercnt= s:bannercnt
10345 endif
10346 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010347 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010348 endif
10349
Bram Moolenaar446cb832008-06-24 21:56:24 +000010350 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010351
Bram Moolenaar446cb832008-06-24 21:56:24 +000010352 " sanity check:
10353 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010354" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010355 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010356" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010357 if !exists("g:netrw_quiet")
10358 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10359 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010360 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010361" call Dret("s:NetrwRemoteListing -1")
10362 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010363 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010364
Bram Moolenaar8d043172014-01-23 14:24:41 +010010365 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010366" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010367 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010368 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010369 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 +000010370 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010371 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 +000010372 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010373 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010374
Bram Moolenaar85850f32019-07-19 22:05:51 +020010375 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010376" call Dret("s:NetrwRemoteListing -1")
10377 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010378 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010379" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010380
Bram Moolenaar446cb832008-06-24 21:56:24 +000010381 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010382" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010383 let w:netrw_method= b:netrw_method
10384 endif
10385
Bram Moolenaar13600302014-05-22 18:26:40 +020010386 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010387 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010388" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010389 let s:method = "ftp"
10390 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010391 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010392 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010393 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010394 let listcmd= g:netrw_ftp_sizelist_cmd
10395 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010396" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010398" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010399
Bram Moolenaara6878372014-03-22 21:02:50 +010010400 " report on missing file or directory messages
10401 if search('[Nn]o such file or directory\|Failed to change directory')
10402 let mesg= getline(".")
10403 if exists("w:netrw_bannercnt")
10404 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010405 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010406 setl noma
10407 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010408 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010409 call netrw#ErrorMsg(s:WARNING,mesg,96)
10410" call Dret("s:NetrwRemoteListing : -1")
10411 return -1
10412 endif
10413
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010414 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 +000010415 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010416" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010417 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010418
10419 " cleanup
10420 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010421 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10422 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010423 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010424 sil! NetrwKeepj %s/\r$//e
10425 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010426
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010427 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010428 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010429 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010430 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010431" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010432 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010433" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010434 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010435 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010436 exe "sil! NetrwKeepj ".line1
10437 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010438
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010439" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010440 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010441" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010442 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10443 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010444 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010445" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010446 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10447 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10448 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10449 NetrwKeepj call histdel("/",-1)
10450 NetrwKeepj call histdel("/",-1)
10451 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010452 endif
10453 endif
10454
Bram Moolenaar13600302014-05-22 18:26:40 +020010455 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010456 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010457" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010458 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010459" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010460 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010461" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10462 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010463 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010464 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10465 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10466 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10467 NetrwKeepj call histdel("/",-1)
10468 NetrwKeepj call histdel("/",-1)
10469 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010470 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010471 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10472 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010473 endif
10474 else
10475 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010476" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010477 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010478 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010479" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10480 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10481" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010482 endif
10483 endif
10484
10485 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010486 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010487" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010488 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10489 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010490 endif
10491 endif
10492
10493 if w:netrw_liststyle == s:LONGLIST
10494 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010495" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010496
10497 if s:method == "ftp"
10498 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010499 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010500 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010501 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010502 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010503 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010504 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010505 sil! NetrwKeepj 1
10506 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010507 let line2= line(".")
10508 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010509 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010510 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010511 endif
10512 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010513 exe "sil! NetrwKeepj ".line1
10514 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010515 endif
10516
10517 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010518" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010519 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 +000010520 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010521" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010522 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010523 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010524 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10525 NetrwKeepj call histdel("/",-1)
10526 NetrwKeepj call histdel("/",-1)
10527 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010528 endif
10529 endif
10530
10531" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010532" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010533" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010534
10535" call Dret("s:NetrwRemoteListing 0")
10536 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010537endfun
10538
Bram Moolenaar446cb832008-06-24 21:56:24 +000010539" ---------------------------------------------------------------------
10540" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10541fun! s:NetrwRemoteRm(usrhost,path) range
10542" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010543" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010544 let svpos= winsaveview()
10545" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010546
10547 let all= 0
10548 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10549 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010550" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010551 for fname in s:netrwmarkfilelist_{bufnr("%")}
10552 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010553 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010554 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010555 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010556 let all= 1
10557 endif
10558 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010559 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010560
10561 else
10562 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010563" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010564
10565 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010566 let keepsol = &l:sol
10567 setl nosol
10568 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010569
10570 " remove multiple files and directories
10571 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010572 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010574 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010576 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010577 let all= 1
10578 endif
10579 let ctr= ctr + 1
10580 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010581 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010582 endif
10583
10584 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010585" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010586 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010587" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10588 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010589
10590" call Dret("s:NetrwRemoteRm")
10591endfun
10592
10593" ---------------------------------------------------------------------
10594" s:NetrwRemoteRmFile: {{{2
10595fun! s:NetrwRemoteRmFile(path,rmfile,all)
10596" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10597
10598 let all= a:all
10599 let ok = ""
10600
10601 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10602 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010603" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010604 if !all
10605 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010606" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010607 call inputsave()
10608 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10609 call inputrestore()
10610 echohl NONE
10611 if ok == ""
10612 let ok="no"
10613 endif
10614 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010615 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010616 let all= 1
10617 endif
10618 endif
10619
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010620 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010621" 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 +000010622 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010623" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010624 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010625 if path =~ '^\a\{3,}://'
10626 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010627 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010628 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010629 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10630 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010631" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010632 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010633" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010634 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010635 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010636 let ok="q"
10637 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010638 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010639" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10640" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10641" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010642 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010643 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010644 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010645 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010646 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010647" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010648 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010649 if v:shell_error != 0
10650 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010651 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 +010010652 else
10653 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10654 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010655 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010656 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010657 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010658" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010659 endif
10660 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010661 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010662" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010663 endif
10664
10665 else
10666 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010667" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010668 if !all
10669 call inputsave()
10670 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10671 call inputrestore()
10672 if ok == ""
10673 let ok="no"
10674 endif
10675 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010676 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010677 let all= 1
10678 endif
10679 endif
10680
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010681 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010682 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010683 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010684 else
10685 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010686 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10687" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010688 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010689" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010690
10691 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010692" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10693 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10694" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010695 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010696" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010697
10698 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010699 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010700 endif
10701 endif
10702 endif
10703
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010704 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010705" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010706 endif
10707 endif
10708
10709" call Dret("s:NetrwRemoteRmFile ".ok)
10710 return ok
10711endfun
10712
10713" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010714" s:NetrwRemoteRename: rename a remote file or directory {{{2
10715fun! s:NetrwRemoteRename(usrhost,path) range
10716" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10717
10718 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010719 let svpos = winsaveview()
10720" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010721 let ctr = a:firstline
10722 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10723
10724 " rename files given by the markfilelist
10725 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10726 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010727" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010728 if exists("subfrom")
10729 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010730" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010731 else
10732 call inputsave()
10733 let newname= input("Moving ".oldname." to : ",oldname)
10734 call inputrestore()
10735 if newname =~ '^s/'
10736 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10737 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10738 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010739" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010740 endif
10741 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010742
Bram Moolenaar446cb832008-06-24 21:56:24 +000010743 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010744 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010745 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010746 let oldname= s:ShellEscape(a:path.oldname)
10747 let newname= s:ShellEscape(a:path.newname)
10748" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010749 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010750 endif
10751
10752 endfor
10753 call s:NetrwUnMarkFile(1)
10754
10755 else
10756
10757 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010758 let keepsol= &l:sol
10759 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010760 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010761 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010762
10763 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010764" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010765
10766 call inputsave()
10767 let newname= input("Moving ".oldname." to : ",oldname)
10768 call inputrestore()
10769
10770 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10771 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10772 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010773 let oldname= s:ShellEscape(a:path.oldname)
10774 let newname= s:ShellEscape(a:path.newname)
10775" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010776 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010777 endif
10778
10779 let ctr= ctr + 1
10780 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010781 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010782 endif
10783
10784 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010785 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010786" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10787 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010788
10789" call Dret("NetrwRemoteRename")
10790endfun
10791
Bram Moolenaar85850f32019-07-19 22:05:51 +020010792" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010793" Local Directory Browsing Support: {{{1
10794" ==========================================
10795
10796" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010797" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010798" Should accept: file://localhost/etc/fstab
10799" file:///etc/fstab
10800" file:///c:/WINDOWS/clock.avi
10801" file:///c|/WINDOWS/clock.avi
10802" file://localhost/c:/WINDOWS/clock.avi
10803" file://localhost/c|/WINDOWS/clock.avi
10804" file://c:/foo.txt
10805" file:///c:/foo.txt
10806" 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 +020010807fun! netrw#FileUrlEdit(fname)
10808" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010809 let fname = a:fname
10810 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010811" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010812 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010813" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010814 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010815 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010816 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010817" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010818 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010819" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010820 endif
10821 endif
10822 let fname2396 = netrw#RFC2396(fname)
10823 let fname2396e= fnameescape(fname2396)
10824 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010825 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010826" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010827 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010828" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010829 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10830 endif
10831 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010832
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010833" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10834" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010835 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010836 exe 'NetrwKeepj keepalt edit '.plainfname
10837 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10838
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010839" 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 +020010840" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010841 exe "sil doau BufReadPost ".fname2396e
10842endfun
10843
10844" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010845" netrw#LocalBrowseCheck: {{{2
10846fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010847 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010848 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10849 "
10850 " unfortunate interaction -- split window debugging can't be used here, must use
10851 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10852 " another call to LocalBrowseCheck() when attempts to write
10853 " to the DBG buffer are made.
10854 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010855 " The &ft == "netrw" test was installed because the BufEnter event
10856 " would hit when re-entering netrw windows, creating unexpected
10857 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010858" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010859" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010860" 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 +010010861 " getting E930: Cannot use :redir inside execute
10862"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010863" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10864" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010865
Bram Moolenaar97d62492012-11-15 21:28:22 +010010866 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010867 if isdirectory(s:NetrwFile(a:dirname))
10868" 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 +010010869
Bram Moolenaar97d62492012-11-15 21:28:22 +010010870 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010871" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10872" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010873 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010874
Bram Moolenaar446cb832008-06-24 21:56:24 +000010875 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010876" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010877 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010878
Bram Moolenaar5c736222010-01-06 20:54:52 +010010879 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010880" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010881 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010882 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010883 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010884" 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 +010010885" call Dret("netrw#LocalBrowseCheck")
10886 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010887 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010888
Bram Moolenaar85850f32019-07-19 22:05:51 +020010889 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010890 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10891 " AND IF the listing style is not a tree listing
10892 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010893" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010894 let ibuf = 1
10895 let buflast = bufnr("$")
10896 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010897 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10898 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010899 endif
10900 let ibuf= ibuf + 1
10901 endwhile
10902 endif
10903 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010904" 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>"))
10905" 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 +000010906 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010907" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010908endfun
10909
10910" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010911" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010912" performed any shell command. The idea is to cause all local-browsing
10913" buffers to be refreshed after a user has executed some shell command,
10914" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010915fun! s:LocalBrowseRefresh()
10916" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010917" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10918" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010919
Bram Moolenaar446cb832008-06-24 21:56:24 +000010920 " determine which buffers currently reside in a tab
10921 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010922" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010923 return
10924 endif
10925 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010926" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010927 return
10928 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010929 if !empty(getcmdwintype())
10930 " cannot move away from cmdline window, see :h E11
10931 return
10932 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010933 if exists("s:netrw_events") && s:netrw_events == 1
10934 " s:LocalFastBrowser gets called (indirectly) from a
10935 let s:netrw_events= 2
10936" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10937 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010938 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010939 let itab = 1
10940 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010941 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010942 while itab <= tabpagenr("$")
10943 let buftablist = buftablist + tabpagebuflist()
10944 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010945 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010946 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010947" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10948" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010949 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10950 " | refresh any netrw window
10951 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010952 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010953 let ibl = 0
10954 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010955" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010956 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10957 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010958 " (ibuf not shown in a current window AND
10959 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010960" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10961 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010962 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010963" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010964 continue
10965 elseif index(tabpagebuflist(),ibuf) != -1
10966 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010967" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010968 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010969 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010970 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10971 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10972 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10973 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010974" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010975 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10976 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10977 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010978 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010979 endif
10980 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010981" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010982 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010983" call Decho("restore window: win_gotoid(".curwinid.")")
10984 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010985 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010986
Bram Moolenaara6878372014-03-22 21:02:50 +010010987" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010988endfun
10989
10990" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010991" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10992"
10993" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010994" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010995" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10996" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010997" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010998"
10999" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11000" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011001" (re-using a buffer may not be as accurate)
11002"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011003" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011004" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11005" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11006" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11007" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011008fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011009" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11010" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11011" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11012" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011013
11014 " initialize browselist, a list of buffer numbers that the local browser has used
11015 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011016" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011017 let s:netrw_browselist= []
11018 endif
11019
11020 " append current buffer to fastbrowse list
11021 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011022" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011023 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011024" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011025 endif
11026
11027 " enable autocmd events to handle refreshing/removing local browser buffers
11028 " If local browse buffer is currently showing: refresh it
11029 " If local browse buffer is currently hidden : wipe it
11030 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11031 " =1 : medium speed, re-use directory listing for remote only
11032 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011033 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11034 let s:netrw_events= 1
11035 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011036 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011037 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011038" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011039 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011040 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011041" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011042 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011043 endif
11044 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011045
11046 " user must have changed fastbrowse to its fast setting, so remove
11047 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011048 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011049" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011050 unlet s:netrw_events
11051 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011052 au!
11053 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011054 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011055 endif
11056
Bram Moolenaar85850f32019-07-19 22:05:51 +020011057" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011058endfun
11059
11060" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011061" s:LocalListing: does the job of "ls" for local directories {{{2
11062fun! s:LocalListing()
11063" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011064" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11065" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11066" 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 +010011067
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011068" 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
11069" 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
11070" 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 +010011071
11072 " get the list of files contained in the current directory
11073 let dirname = b:netrw_curdir
11074 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011075 let filelist = s:NetrwGlob(dirname,"*",0)
11076 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011077" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011078
Nir Lichtman1e34b952024-05-08 19:19:34 +020011079 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011080" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011081 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11082 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011083" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011084 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011085" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011086 endif
11087
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011088" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011089" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011090" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011091
11092 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11093 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11094 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011095" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11096" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011097 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011098" 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 +010011099
11100 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011101" call Decho(" ",'~'.expand("<slnum>"))
11102" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011103
11104 if getftype(filename) == "link"
11105 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011106" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011107 let pfile= filename."@"
11108
11109 elseif getftype(filename) == "socket"
11110 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011111" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011112 let pfile= filename."="
11113
11114 elseif getftype(filename) == "fifo"
11115 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011116" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011117 let pfile= filename."|"
11118
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011119 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011120 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011121" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011122 let pfile= filename."/"
11123
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011124 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011125 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011126 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11127 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011128" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011129 let pfile= filename."*"
11130 else
11131 " normal file
11132 let pfile= filename
11133 endif
11134 elseif executable(filename)
11135 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011136" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011137 let pfile= filename."*"
11138 else
11139 " normal file
11140 let pfile= filename
11141 endif
11142
11143 else
11144 " normal file
11145 let pfile= filename
11146 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011147" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011148
11149 if pfile =~ '//$'
11150 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011151" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011152 endif
11153 let pfile= strpart(pfile,dirnamelen)
11154 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011155" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11156" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011157
11158 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011159 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11160 let sz = getfsize(filename)
11161 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11162 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011163
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011164 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011165 let sz= s:NetrwHumanReadable(sz)
11166 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011167 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011168 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011169" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011170 endif
11171
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011172 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011173 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011174 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011175" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011176" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011177 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011178 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011179" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011180 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011181 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011182
11183 elseif g:netrw_sort_by =~ "^s"
11184 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011185" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011186" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011187 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011188 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011189" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011190 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011191 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011192
11193 else
11194 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011195" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011196" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011197 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011198 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011199" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011200 endfor
11201
11202 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011203 sil! NetrwKeepj g/^$/d
11204 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011205 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011206" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011207 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11208
11209" call Dret("s:LocalListing")
11210endfun
11211
11212" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011213" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11214fun! s:NetrwLocalExecute(cmd)
11215" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11216 let ykeep= @@
11217 " sanity check
11218 if !executable(a:cmd)
11219 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11220 let @@= ykeep
11221" call Dret("s:NetrwLocalExecute")
11222 return
11223 endif
11224
11225 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011226" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011227 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011228" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011229
11230 " strip any ansi escape sequences off
11231 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11232
11233 " show user the result(s)
11234 echomsg result
11235 let @@= ykeep
11236
11237" call Dret("s:NetrwLocalExecute")
11238endfun
11239
11240" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011241" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011242fun! s:NetrwLocalRename(path) range
11243" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11244
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011245 if !exists("w:netrw_bannercnt")
11246 let w:netrw_bannercnt= b:netrw_bannercnt
11247 endif
11248
Bram Moolenaar97d62492012-11-15 21:28:22 +010011249 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011250 let ykeep = @@
11251 let ctr = a:firstline
11252 let svpos = winsaveview()
11253 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011254" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011255
11256 " rename files given by the markfilelist
11257 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11258 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011259" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011260 if exists("subfrom")
11261 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011262" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011263 else
11264 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011265 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011266 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011267 if newname =~ ''
11268 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11269 let newname = substitute(newname,'^.*','','')
11270 elseif newname =~ ''
11271 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11272 let newname = substitute(newname,'[^/]*','','')
11273 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011274 if newname =~ '^s/'
11275 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11276 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011277" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011278 let newname = substitute(oldname,subfrom,subto,'')
11279 endif
11280 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011281 if !all && filereadable(newname)
11282 call inputsave()
11283 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11284 call inputrestore()
11285 if response == "all"
11286 let all= 1
11287 elseif response != "y" && response != "yes"
11288 " refresh the directory
11289" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11290 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11291" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11292 NetrwKeepj call winrestview(svpos)
11293 let @@= ykeep
11294" call Dret("NetrwLocalRename")
11295 return
11296 endif
11297 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011298 call rename(oldname,newname)
11299 endfor
11300 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011301
Bram Moolenaar97d62492012-11-15 21:28:22 +010011302 else
11303
11304 " attempt to rename files/directories
11305 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011306 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011307
11308 " sanity checks
11309 if line(".") < w:netrw_bannercnt
11310 let ctr= ctr + 1
11311 continue
11312 endif
11313 let curword= s:NetrwGetWord()
11314 if curword == "./" || curword == "../"
11315 let ctr= ctr + 1
11316 continue
11317 endif
11318
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011319 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011320 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011321" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011322
11323 call inputsave()
11324 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11325 call inputrestore()
11326
11327 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011328" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011329
11330 let ctr= ctr + 1
11331 endwhile
11332 endif
11333
11334 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011335" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011336 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011337" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11338 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011339 let @@= ykeep
11340
11341" call Dret("NetrwLocalRename")
11342endfun
11343
11344" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011345" s:NetrwLocalRm: {{{2
11346fun! s:NetrwLocalRm(path) range
11347" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011348" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011349
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011350 if !exists("w:netrw_bannercnt")
11351 let w:netrw_bannercnt= b:netrw_bannercnt
11352 endif
11353
Bram Moolenaar446cb832008-06-24 21:56:24 +000011354 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011355 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011356 let ret = 0
11357 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011358 let svpos = winsaveview()
11359" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011360
11361 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11362 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011363" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011364 for fname in s:netrwmarkfilelist_{bufnr("%")}
11365 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011366 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011367 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011368 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011369 let all= 1
11370 endif
11371 endfor
11372 call s:NetrwUnMarkFile(1)
11373
11374 else
11375 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011376" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011377
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011378 let keepsol= &l:sol
11379 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011380 let ctr = a:firstline
11381 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011382 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011383
11384 " sanity checks
11385 if line(".") < w:netrw_bannercnt
11386 let ctr= ctr + 1
11387 continue
11388 endif
11389 let curword= s:NetrwGetWord()
11390 if curword == "./" || curword == "../"
11391 let ctr= ctr + 1
11392 continue
11393 endif
11394 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011395 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011396 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011397 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011398 let all= 1
11399 endif
11400 let ctr= ctr + 1
11401 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011402 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011403 endif
11404
11405 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011406" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011407 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011408 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011409" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11410 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011411 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011412 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011413
11414" call Dret("s:NetrwLocalRm")
11415endfun
11416
11417" ---------------------------------------------------------------------
11418" s:NetrwLocalRmFile: remove file fname given the path {{{2
11419" Give confirmation prompt unless all==1
11420fun! s:NetrwLocalRmFile(path,fname,all)
11421" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011422
Bram Moolenaar446cb832008-06-24 21:56:24 +000011423 let all= a:all
11424 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011425 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011426 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11427" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011428
11429 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11430 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011431" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011432 if !all
11433 echohl Statement
11434 call inputsave()
11435 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11436 call inputrestore()
11437 echohl NONE
11438 if ok == ""
11439 let ok="no"
11440 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011441" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011442 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011443" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011444 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011445 let all= 1
11446 endif
11447 endif
11448
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011449 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011450 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011451" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011452 endif
11453
11454 else
11455 " attempt to remove directory
11456 if !all
11457 echohl Statement
11458 call inputsave()
11459 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11460 call inputrestore()
11461 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11462 if ok == ""
11463 let ok="no"
11464 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011465 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011466 let all= 1
11467 endif
11468 endif
11469 let rmfile= substitute(rmfile,'[\/]$','','e')
11470
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011471 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar71badf92023-04-22 22:40:14 +010011472 if delete(rmfile,"d")
11473 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011474 endif
11475 endif
11476 endif
11477
11478" call Dret("s:NetrwLocalRmFile ".ok)
11479 return ok
11480endfun
11481
Bram Moolenaar85850f32019-07-19 22:05:51 +020011482" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011483" Support Functions: {{{1
11484
Bram Moolenaar488c6512005-08-11 20:09:58 +000011485" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011486" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11487" 0: marked file list of current buffer
11488" 1: marked file target
11489fun! netrw#Access(ilist)
11490 if a:ilist == 0
11491 if exists("s:netrwmarkfilelist_".bufnr('%'))
11492 return s:netrwmarkfilelist_{bufnr('%')}
11493 else
11494 return "no-list-buf#".bufnr('%')
11495 endif
11496 elseif a:ilist == 1
11497 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011498 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011499endfun
11500
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011501" ---------------------------------------------------------------------
11502" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11503fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011504 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011505endfun
11506
Bram Moolenaara6878372014-03-22 21:02:50 +010011507" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011508" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11509" I expect this function to be used in
11510" :PChkAssert netrw#Expose("netrwmarkfilelist")
11511" for example.
11512fun! netrw#Expose(varname)
11513" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011514 if exists("s:".a:varname)
11515 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011516" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011517 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011518" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011519 if type(retval) == 3
11520 let retval = copy(retval)
11521 let i = 0
11522 while i < len(retval)
11523 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11524 let i = i + 1
11525 endwhile
11526 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011527" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011528 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011529 else
11530" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011531 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011532 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011533" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011534 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011535 endif
11536
11537" call Dret("netrw#Expose ".string(retval))
11538 return retval
11539endfun
11540
11541" ---------------------------------------------------------------------
11542" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11543fun! netrw#Modify(varname,newvalue)
11544" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11545 exe "let s:".a:varname."= ".string(a:newvalue)
11546" call Dret("netrw#Modify")
11547endfun
11548
11549" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011550" netrw#RFC2396: converts %xx into characters {{{2
11551fun! netrw#RFC2396(fname)
11552" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011553 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011554" call Dret("netrw#RFC2396 ".fname)
11555 return fname
11556endfun
11557
11558" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011559" netrw#UserMaps: supports user-specified maps {{{2
11560" see :help function()
11561"
11562" g:Netrw_UserMaps is a List with members such as:
11563" [[keymap sequence, function reference],...]
11564"
11565" The referenced function may return a string,
11566" refresh : refresh the display
11567" -other- : this string will be executed
11568" or it may return a List of strings.
11569"
11570" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011571" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011572" Related functions:
11573" netrw#Expose(varname) -- see s:varname variables
11574" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11575" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11576fun! netrw#UserMaps(islocal)
11577" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11578" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11579
11580 " set up usermaplist
11581 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11582" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11583 for umap in g:Netrw_UserMaps
11584" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11585" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11586 " if umap[0] is a string and umap[1] is a string holding a function name
11587 if type(umap[0]) == 1 && type(umap[1]) == 1
11588" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11589 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11590 else
11591 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11592 endif
11593 endfor
11594 endif
11595" call Dret("netrw#UserMaps")
11596endfun
11597
11598" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011599" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11600fun! netrw#WinPath(path)
11601" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011602 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011603 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011604 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011605 " remove trailing slash (Win95)
11606 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11607 " remove escaped spaces
11608 let path = substitute(path, '\ ', ' ', 'g')
11609 " convert slashes to backslashes
11610 let path = substitute(path, '/', '\', 'g')
11611 else
11612 let path= a:path
11613 endif
11614" call Dret("netrw#WinPath <".path.">")
11615 return path
11616endfun
11617
11618" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011619" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11620" cb : bl2mf=0 add marked files to buffer list
11621" cB : bl2mf=1 use bufferlist to mark files
11622" (mnemonic: cb = copy (marked files) to buffer list)
11623fun! s:NetrwBadd(islocal,bl2mf)
11624" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11625 if a:bl2mf
11626 " cB: add buffer list to marked files
11627 redir => bufl
11628 ls
11629 redir END
11630 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11631 for fname in bufl
11632 call s:NetrwMarkFile(a:islocal,fname)
11633 endfor
11634 else
11635 " cb: add marked files to buffer list
11636 for fname in s:netrwmarkfilelist_{bufnr("%")}
11637" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11638 exe "badd ".fnameescape(fname)
11639 endfor
11640 let curbufnr = bufnr("%")
11641 let curdir = s:NetrwGetCurdir(a:islocal)
11642 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11643 endif
11644" call Dret("s:NetrwBadd")
11645endfun
11646
11647" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011648" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11649fun! s:ComposePath(base,subdir)
11650" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11651
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011652 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011653" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011654 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011655 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011656 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011657 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011658 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011659 endif
11660
Bram Moolenaar85850f32019-07-19 22:05:51 +020011661 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011662 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011663" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011664 let ret= a:subdir
11665
Nir Lichtman1e34b952024-05-08 19:19:34 +020011666 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011667" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011668 if a:base =~ '[/\\]$'
11669 let ret= a:base.a:subdir
11670 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011671 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011672 endif
11673
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011674 elseif a:base =~ '^\a\{3,}://'
11675" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011676 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11677 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11678 if a:subdir == '../'
11679 if curpath =~ '[^/]/[^/]\+/$'
11680 let curpath= substitute(curpath,'[^/]\+/$','','')
11681 else
11682 let curpath=""
11683 endif
11684 let ret= urlbase.curpath
11685 else
11686 let ret= urlbase.curpath.a:subdir
11687 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011688" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11689" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11690" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011691
11692 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011693" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011694 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11695 if a:base =~ '^//'
11696 " keeping initial '//' for the benefit of network share listing support
11697 let ret= '/'.ret
11698 endif
11699 let ret= simplify(ret)
11700 endif
11701
11702" call Dret("s:ComposePath ".ret)
11703 return ret
11704endfun
11705
11706" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011707" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11708" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11709fun! s:DeleteBookmark(fname)
11710" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11711 call s:MergeBookmarks()
11712
11713 if exists("g:netrw_bookmarklist")
11714 let indx= index(g:netrw_bookmarklist,a:fname)
11715 if indx == -1
11716 let indx= 0
11717 while indx < len(g:netrw_bookmarklist)
11718 if g:netrw_bookmarklist[indx] =~ a:fname
11719 call remove(g:netrw_bookmarklist,indx)
11720 let indx= indx - 1
11721 endif
11722 let indx= indx + 1
11723 endwhile
11724 else
11725 " remove exact match
11726 call remove(g:netrw_bookmarklist,indx)
11727 endif
11728 endif
11729
11730" call Dret("s:DeleteBookmark")
11731endfun
11732
11733" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011734" s:FileReadable: o/s independent filereadable {{{2
11735fun! s:FileReadable(fname)
11736" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11737
11738 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011739 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011740 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011741 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011742 endif
11743
11744" call Dret("s:FileReadable ".ret)
11745 return ret
11746endfun
11747
11748" ---------------------------------------------------------------------
11749" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11750" Places correct suffix on end of temporary filename,
11751" using the suffix provided with fname
11752fun! s:GetTempfile(fname)
11753" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11754
11755 if !exists("b:netrw_tmpfile")
11756 " get a brand new temporary filename
11757 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011758" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011759
Bram Moolenaarc236c162008-07-13 17:41:49 +000011760 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011761" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011762
Bram Moolenaar9964e462007-05-05 17:54:07 +000011763 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011764 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11765" 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 +010011766 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011767" call Dret("s:GetTempfile getcwd<".getcwd().">")
11768 return ""
11769 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011770
Bram Moolenaar9964e462007-05-05 17:54:07 +000011771 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011772 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011773" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011774
Bram Moolenaar9964e462007-05-05 17:54:07 +000011775 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011776 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011777 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011778 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011779 if !exists("+shellslash") || !&ssl
11780 let tmpfile = substitute(tmpfile,'/','\','g')
11781 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011782 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011783 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011784 endif
11785 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011786" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011787 else
11788 " re-use temporary filename
11789 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011790" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011791 endif
11792
11793 " use fname's suffix for the temporary file
11794 if a:fname != ""
11795 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011796" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011797 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011798 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011799 elseif a:fname =~ '.txz$'
11800 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011801 else
11802 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11803 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011804" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011805 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011806" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011807 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011808" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011809 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11810 endif
11811 endif
11812
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011813" 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 +000011814" call Dret("s:GetTempfile <".tmpfile.">")
11815 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011816endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011817
11818" ---------------------------------------------------------------------
11819" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011820" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011821fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011822" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011823 if s:user == ""
11824 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11825 else
11826 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11827 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011828 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011829 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011830 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011831 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011832 else
11833 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11834 endif
11835" call Dret("s:MakeSshCmd <".sshcmd.">")
11836 return sshcmd
11837endfun
11838
11839" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011840" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11841fun! s:MakeBookmark(fname)
11842" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11843
11844 if !exists("g:netrw_bookmarklist")
11845 let g:netrw_bookmarklist= []
11846 endif
11847
11848 if index(g:netrw_bookmarklist,a:fname) == -1
11849 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011850 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011851 call add(g:netrw_bookmarklist,a:fname.'/')
11852 elseif a:fname !~ '/'
11853 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11854 else
11855 call add(g:netrw_bookmarklist,a:fname)
11856 endif
11857 call sort(g:netrw_bookmarklist)
11858 endif
11859
11860" call Dret("s:MakeBookmark")
11861endfun
11862
11863" ---------------------------------------------------------------------
11864" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11865fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011866" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011867 " get bookmarks from .netrwbook file
11868 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011869 if filereadable(s:NetrwFile(savefile))
11870" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011871 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011872" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011873 NetrwKeepj call delete(savefile)
11874 endif
11875" call Dret("s:MergeBookmarks")
11876endfun
11877
11878" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011879" s:NetrwBMShow: {{{2
11880fun! s:NetrwBMShow()
11881" call Dfunc("s:NetrwBMShow()")
11882 redir => bmshowraw
11883 menu
11884 redir END
11885 let bmshowlist = split(bmshowraw,'\n')
11886 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011887 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011888 if bmshowfuncs != []
11889 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011890 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011891 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011892 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011893 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011894 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011895" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11896endfun
11897
11898" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011899" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011900fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011901 if !exists("w:netrw_liststyle")
11902 let w:netrw_liststyle= g:netrw_liststyle
11903 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011904" 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 +020011905
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011906" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11907
Bram Moolenaaradc21822011-04-01 18:03:16 +020011908 if &ft != "netrw"
11909 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11910 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011911" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011912
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011913 elseif g:netrw_cursor == 8
11914 if w:netrw_liststyle == s:WIDELIST
11915 setl cursorline
11916 setl cursorcolumn
11917 else
11918 setl cursorline
11919 endif
11920 elseif g:netrw_cursor == 7
11921 setl cursorline
11922 elseif g:netrw_cursor == 6
11923 if w:netrw_liststyle == s:WIDELIST
11924 setl cursorline
11925 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011926 elseif g:netrw_cursor == 4
11927 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011928" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011929 setl cursorline
11930 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011931
11932 elseif g:netrw_cursor == 3
11933 " thin-long-tree: cursorline, user's cursorcolumn
11934 " wide : cursorline, cursorcolumn
11935 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011936" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011937 setl cursorline
11938 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011939 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011940" 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 +020011941 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011942 endif
11943
11944 elseif g:netrw_cursor == 2
11945 " thin-long-tree: cursorline, user's cursorcolumn
11946 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011947" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011948 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011949
11950 elseif g:netrw_cursor == 1
11951 " thin-long-tree: user's cursorline, user's cursorcolumn
11952 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011953 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011954" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011955 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011956 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011957" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011958 endif
11959
11960 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011961 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011962" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011963 let &l:cursorline = s:netrw_usercul
11964 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011965 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011966
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011967" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011968" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011969endfun
11970
11971" ---------------------------------------------------------------------
11972" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11973fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011974" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011975 if exists("s:netrw_usercul")
11976 let &l:cursorline = s:netrw_usercul
11977 endif
11978 if exists("s:netrw_usercuc")
11979 let &l:cursorcolumn = s:netrw_usercuc
11980 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011981" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011982" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11983endfun
11984
11985" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011986" s:NetrwDelete: Deletes a file. {{{2
11987" Uses Steve Hall's idea to insure that Windows paths stay
11988" acceptable. No effect on Unix paths.
11989" Examples of use: let result= s:NetrwDelete(path)
11990fun! s:NetrwDelete(path)
11991" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11992
Bram Moolenaar5c736222010-01-06 20:54:52 +010011993 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011994 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011995 if exists("+shellslash")
11996 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011997 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011998 let result = delete(path)
11999 let &shellslash = sskeep
12000 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012001" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012002 let result= delete(path)
12003 endif
12004 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012005" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012006 let result= delete(path)
12007 endif
12008 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012009 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012010 endif
12011
12012" call Dret("s:NetrwDelete ".result)
12013 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012014endfun
12015
12016" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012017" s:NetrwBufRemover: removes a buffer that: {{{2s
12018" has buffer-id > 1
12019" is unlisted
12020" is unnamed
12021" does not appear in any window
12022fun! s:NetrwBufRemover(bufid)
12023" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12024" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12025" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12026" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12027" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12028
yasuda4dbb2662023-10-04 20:50:35 +020012029 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012030" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012031 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012032 endif
12033
12034" call Dret("s:NetrwBufRemover")
12035endfun
12036
12037" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012038" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012039fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012040" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012041" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012042
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012043 " Clean out the last buffer:
12044 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12045 " If so, delete it.
12046 call s:NetrwBufRemover(bufnr("$"))
12047
Bram Moolenaar446cb832008-06-24 21:56:24 +000012048 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012049" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012050 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12051 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12052 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12053 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12054 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12055 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12056 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12057 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12058 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12059 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12060 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12061 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12062 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12063 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12064 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12065 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12066
Bram Moolenaar85850f32019-07-19 22:05:51 +020012067 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012068" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012069 " when tree listing uses file TreeListing... a new buffer is made.
12070 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012071 " COMBAK: this causes a problem, see P43
12072" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012073 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012074 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012075 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012076" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012077 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012078
Bram Moolenaar446cb832008-06-24 21:56:24 +000012079 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012080" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012081 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12082 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12083 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12084 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12085 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12086 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12087 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12088 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12089 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12090 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12091 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12092 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12093 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12094 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12095 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12096 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12097
Bram Moolenaar5c736222010-01-06 20:54:52 +010012098 if a:0 > 0
12099 let b:netrw_curdir= a:1
12100 if b:netrw_curdir =~ '/$'
12101 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012102 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012103 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012104 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012105 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12106 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012107 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012108 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012109 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012110 endif
12111 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012112 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12113 let &l:bexpr = "netrw#BalloonHelp()"
12114 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012115
Bram Moolenaar8d043172014-01-23 14:24:41 +010012116" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012117endfun
12118
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012119" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012120" s:NetrwExe: executes a string using "!" {{{2
12121fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012122" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012123 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012124" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012125 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12126 set shell& shellcmdflag& shellxquote& shellxescape&
12127 set shellquote& shellpipe& shellredir& shellslash&
12128 exe a:cmd
12129 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12130 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012131" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012132 exe a:cmd
12133 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012134 if v:shell_error
12135 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12136 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012137" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012138endfun
12139
12140" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012141" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12142fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012143 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012144" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012145 let curbuf = bufnr("%")
12146 let curwin = winnr()
12147 let iwin = 1
12148 while iwin <= winnr("$")
12149 exe iwin."wincmd w"
12150 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12151 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12152 let winvars= w:
12153 break
12154 endif
12155 let iwin= iwin + 1
12156 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012157 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012158 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012159" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012160 for k in keys(winvars)
12161 let w:{k}= winvars[k]
12162 endfor
12163 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012164" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012165 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012166endfun
12167
Bram Moolenaara6878372014-03-22 21:02:50 +010012168" ---------------------------------------------------------------------
12169" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012170" Returns: 0=success
12171" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012172fun! s:NetrwLcd(newdir)
12173" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012174" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012175
Bram Moolenaar85850f32019-07-19 22:05:51 +020012176 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012177 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012178 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012179 catch /^Vim\%((\a\+)\)\=:E344/
12180 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12181 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012182 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012183 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12184 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012185 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012186 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12187 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012188 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012189 endif
12190 endif
12191 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012192 let err472= 1
12193 endtry
12194
12195 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012196 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12197 if exists("w:netrw_prvdir")
12198 let a:newdir= w:netrw_prvdir
12199 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012200 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012201" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012202 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012203" 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 +010012204 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012205 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012206" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12207 return -1
12208 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012209
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012210" call Decho("getcwd <".getcwd().">")
12211" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012212" call Dret("s:NetrwLcd 0")
12213 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012214endfun
12215
Bram Moolenaar9964e462007-05-05 17:54:07 +000012216" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012217" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12218" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12219fun! s:NetrwSaveWordPosn()
12220" call Dfunc("NetrwSaveWordPosn()")
12221 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12222" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12223endfun
12224
12225" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012226" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12227" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12228fun! s:NetrwHumanReadable(sz)
12229" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12230
12231 if g:netrw_sizestyle == 'h'
12232 if a:sz >= 1000000000
12233 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12234 elseif a:sz >= 10000000
12235 let sz = printf("%d",a:sz/1000000)."m"
12236 elseif a:sz >= 1000000
12237 let sz = printf("%.1f",a:sz/1000000.0)."m"
12238 elseif a:sz >= 10000
12239 let sz = printf("%d",a:sz/1000)."k"
12240 elseif a:sz >= 1000
12241 let sz = printf("%.1f",a:sz/1000.0)."k"
12242 else
12243 let sz= a:sz
12244 endif
12245
12246 elseif g:netrw_sizestyle == 'H'
12247 if a:sz >= 1073741824
12248 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12249 elseif a:sz >= 10485760
12250 let sz = printf("%d",a:sz/1048576)."M"
12251 elseif a:sz >= 1048576
12252 let sz = printf("%.1f",a:sz/1048576.0)."M"
12253 elseif a:sz >= 10240
12254 let sz = printf("%d",a:sz/1024)."K"
12255 elseif a:sz >= 1024
12256 let sz = printf("%.1f",a:sz/1024.0)."K"
12257 else
12258 let sz= a:sz
12259 endif
12260
12261 else
12262 let sz= a:sz
12263 endif
12264
12265" call Dret("s:NetrwHumanReadable ".sz)
12266 return sz
12267endfun
12268
12269" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012270" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12271" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12272fun! s:NetrwRestoreWordPosn()
12273" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012274 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012275" call Dret("NetrwRestoreWordPosn")
12276endfun
12277
12278" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012279" s:RestoreBufVars: {{{2
12280fun! s:RestoreBufVars()
12281" call Dfunc("s:RestoreBufVars()")
12282
12283 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12284 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12285 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12286 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12287 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12288 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12289
12290" call Dret("s:RestoreBufVars")
12291endfun
12292
12293" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012294" s:RemotePathAnalysis: {{{2
12295fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012296" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012297
Bram Moolenaara6878372014-03-22 21:02:50 +010012298 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012299 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012300 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012301 let s:user = substitute(a:dirname,dirpat,'\3','')
12302 let s:machine = substitute(a:dirname,dirpat,'\4','')
12303 let s:port = substitute(a:dirname,dirpat,'\5','')
12304 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012305 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012306 if s:machine =~ '@'
12307 let dirpat = '^\(.*\)@\(.\{-}\)$'
12308 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12309 let s:machine = substitute(s:machine,dirpat,'\2','')
12310 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012311
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012312" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12313" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12314" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12315" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12316" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12317" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012318
12319" call Dret("s:RemotePathAnalysis")
12320endfun
12321
12322" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012323" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12324" Returns status
12325" Runs system() on
12326" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012327" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012328fun! s:RemoteSystem(cmd)
12329" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12330 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012331 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 +000012332 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012333 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012334 else
12335 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12336 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12337 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012338 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012339 else
12340 let cmd= cmd.' '
12341 endif
12342 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012343" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012344 let ret= system(cmd)
12345 endif
12346" call Dret("s:RemoteSystem ".ret)
12347 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012348endfun
12349
12350" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012351" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012352fun! s:RestoreWinVars()
12353" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012354 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012355 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12356 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12357 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12358 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12359 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12360 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12361 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12362 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12363 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12364 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12365 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12366 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012367 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12368 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012369 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12370 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12371 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12372" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012373endfun
12374
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012375" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012376" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12377"
12378" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12379" is true) and a command, :Rexplore, which call this function.
12380"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012381" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012382"
12383" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012384fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012385 if exists("s:netrwdrag")
12386 return
12387 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012388" 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 +010012389" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12390" 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 +010012391
12392 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012393 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012394" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012395 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012396 unlet w:netrw_rexfile
12397" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012398 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012399" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012400" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12401" 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 +020012402 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012403
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012404 " ---------------------------
12405 " :Rex issued while in a file
12406 " ---------------------------
12407
Bram Moolenaara6878372014-03-22 21:02:50 +010012408 " record current file so :Rex can return to it from netrw
12409 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012410" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012411
12412 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012413" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012414 return
12415 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012416" 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 +020012417 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012418 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012419 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012420 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012421 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012422 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012423 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012424 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012425 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012426" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12427 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012428" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12429 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012430 if exists("s:rexposn_".bufnr('%'))
12431 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012432 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012433 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012434" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012435 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012436
Bram Moolenaar85850f32019-07-19 22:05:51 +020012437 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12438 if exists("s:explore_match")
12439 exe "2match netrwMarkFile /".s:explore_match."/"
12440 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012441 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012442
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012443" 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 +010012444" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012445endfun
12446
12447" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012448" s:SaveBufVars: save selected b: variables to s: variables {{{2
12449" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012450fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012451" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012452
12453 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12454 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12455 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12456 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12457 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12458 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12459
12460" call Dret("s:SaveBufVars")
12461endfun
12462
12463" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012464" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12465fun! s:SavePosn(posndict)
12466" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12467
Bram Moolenaar85850f32019-07-19 22:05:51 +020012468 if !exists("a:posndict[bufnr('%')]")
12469 let a:posndict[bufnr("%")]= []
12470 endif
12471" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12472 call add(a:posndict[bufnr("%")],winsaveview())
12473" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012474
12475" call Dret("s:SavePosn posndict")
12476 return a:posndict
12477endfun
12478
12479" ---------------------------------------------------------------------
12480" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12481fun! s:RestorePosn(posndict)
12482" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012483 if exists("a:posndict")
12484 if has_key(a:posndict,bufnr("%"))
12485" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12486 let posnlen= len(a:posndict[bufnr("%")])
12487 if posnlen > 0
12488 let posnlen= posnlen - 1
12489" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12490 call winrestview(a:posndict[bufnr("%")][posnlen])
12491 call remove(a:posndict[bufnr("%")],posnlen)
12492" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12493 endif
12494 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012495 endif
12496" call Dret("s:RestorePosn")
12497endfun
12498
12499" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012500" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012501fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012502" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012503 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12504 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12505 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12506 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12507 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12508 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12509 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12510 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12511 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12512 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12513 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12514 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12515 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12516 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12517 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12518 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12519 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12520 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12521" call Dret("s:SaveWinVars")
12522endfun
12523
12524" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012525" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012526" To allow separate windows to have their own activities, such as
12527" Explore **/pattern, several variables have been made window-oriented.
12528" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012529" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012530" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012531fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012532" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012533 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12534 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12535 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12536 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12537 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12538 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12539 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12540 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12541 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12542 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12543" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012544endfun
12545
12546" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012547" s:SetRexDir: set directory for :Rexplore {{{2
12548fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012549" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012550 let w:netrw_rexdir = a:dirname
12551 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012552 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012553" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12554" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012555" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012556" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012557" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012558endfun
12559
12560" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012561" s:ShowLink: used to modify thin and tree listings to show links {{{2
12562fun! s:ShowLink()
12563" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012564" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12565" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012566 if exists("b:netrw_curdir")
12567 norm! $?\a
12568 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12569 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012570" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12571" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12572" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12573 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012574 let dirlen = strlen(b:netrw_curdir)
12575 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012576" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012577 endif
12578 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012579" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12580" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012581 setl noro ma
12582 call setline(".",modline)
12583 setl ro noma nomod
12584 endif
12585" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12586endfun
12587
12588" ---------------------------------------------------------------------
12589" s:ShowStyle: {{{2
12590fun! s:ShowStyle()
12591 if !exists("w:netrw_liststyle")
12592 let liststyle= g:netrw_liststyle
12593 else
12594 let liststyle= w:netrw_liststyle
12595 endif
12596 if liststyle == s:THINLIST
12597 return s:THINLIST.":thin"
12598 elseif liststyle == s:LONGLIST
12599 return s:LONGLIST.":long"
12600 elseif liststyle == s:WIDELIST
12601 return s:WIDELIST.":wide"
12602 elseif liststyle == s:TREELIST
12603 return s:TREELIST.":tree"
12604 else
12605 return 'n/a'
12606 endif
12607endfun
12608
12609" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012610" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12611" Solution from Nicolai Weibull, vim docs (:help strlen()),
12612" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012613fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012614" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12615
12616 if v:version >= 703 && exists("*strdisplaywidth")
12617 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012618
Bram Moolenaar8d043172014-01-23 14:24:41 +010012619 elseif type(g:Align_xstrlen) == 1
12620 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12621 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012622
Bram Moolenaar8d043172014-01-23 14:24:41 +010012623 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012624 " number of codepoints (Latin a + combining circumflex is two codepoints)
12625 " (comment from TM, solution from NW)
12626 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012627
Bram Moolenaar8d043172014-01-23 14:24:41 +010012628 elseif g:Align_xstrlen == 2
12629 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012630 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12631 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012632 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012633
Bram Moolenaar8d043172014-01-23 14:24:41 +010012634 elseif g:Align_xstrlen == 3
12635 " virtual length (counting, for instance, tabs as anything between 1 and
12636 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012637 " preceded by lam, one otherwise, etc.)
12638 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012639 let modkeep= &l:mod
12640 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012641 call setline(line("."),a:x)
12642 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012643 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012644 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012645 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012646
Bram Moolenaar446cb832008-06-24 21:56:24 +000012647 else
12648 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012649 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012650 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012651" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012652 return ret
12653endfun
12654
12655" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012656" s:ShellEscape: shellescape(), or special windows handling {{{2
12657fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012658 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012659 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12660 endif
12661 let f = a:0 > 0 ? a:1 : 0
12662 return shellescape(a:s, f)
12663endfun
12664
12665" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012666" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012667fun! s:TreeListMove(dir)
12668" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012669 let curline = getline('.')
12670 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12671 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12672 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12673 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12674 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12675 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12676" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12677" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12678" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12679" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12680" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12681 " COMBAK : need to handle when on a directory
12682 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012683 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012684 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012685 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012686 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012687" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012688 elseif a:dir == '[]' && nxtline != ''
12689 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012690" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012691 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12692 if nl != 0
12693 NetrwKeepj norm! k
12694 else
12695 NetrwKeepj norm! G
12696 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012697" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012698 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012699 endif
12700
12701" call Dret("s:TreeListMove")
12702endfun
12703
12704" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012705" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12706" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12707" can't be called except via emenu. But due to locale, that menu line may not be called
12708" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12709fun! s:UpdateBuffersMenu()
12710" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012711 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012712 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012713 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012714 catch /^Vim\%((\a\+)\)\=:E/
12715 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012716 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012717 endtry
12718 endif
12719" call Dret("s:UpdateBuffersMenu")
12720endfun
12721
12722" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012723" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012724" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012725fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012726" call Dfunc("s:UseBufWinVars()")
12727 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012728 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12729 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12730 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12731 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12732 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12733 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12734 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12735 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12736 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 +000012737" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012738endfun
12739
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012740" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012741" s:UserMaps: supports user-defined UserMaps {{{2
12742" * calls a user-supplied funcref(islocal,curdir)
12743" * interprets result
12744" See netrw#UserMaps()
12745fun! s:UserMaps(islocal,funcname)
12746" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12747
12748 if !exists("b:netrw_curdir")
12749 let b:netrw_curdir= getcwd()
12750 endif
12751 let Funcref = function(a:funcname)
12752 let result = Funcref(a:islocal)
12753
12754 if type(result) == 1
12755 " if result from user's funcref is a string...
12756" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12757 if result == "refresh"
12758" call Decho("refreshing display",'~'.expand("<slnum>"))
12759 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12760 elseif result != ""
12761" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12762 exe result
12763 endif
12764
12765 elseif type(result) == 3
12766 " if result from user's funcref is a List...
12767" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12768 for action in result
12769 if action == "refresh"
12770" call Decho("refreshing display",'~'.expand("<slnum>"))
12771 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12772 elseif action != ""
12773" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12774 exe action
12775 endif
12776 endfor
12777 endif
12778
12779" call Dret("s:UserMaps")
12780endfun
12781
Bram Moolenaar85850f32019-07-19 22:05:51 +020012782" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012783" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012784" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012785let &cpo= s:keepcpo
12786unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012787
Bram Moolenaar85850f32019-07-19 22:05:51 +020012788" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012789" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012790" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012791" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012792" doing autoload/netrw.vim version v172g ~57
12793" varname<g:netrw_dirhistcnt> value=0 ~1
12794" varname<s:THINLIST> value=0 ~1
12795" varname<s:LONGLIST> value=1 ~1
12796" varname<s:WIDELIST> value=2 ~1
12797" varname<s:TREELIST> value=3 ~1
12798" varname<s:MAXLIST> value=4 ~1
12799" varname<g:netrw_use_errorwindow> value=2 ~1
12800" varname<g:netrw_http_xcmd> value=-q -O ~1
12801" varname<g:netrw_http_put_cmd> value=curl -T ~1
12802" varname<g:netrw_keepj> value=keepj ~1
12803" varname<g:netrw_rcp_cmd> value=rcp ~1
12804" varname<g:netrw_rsync_cmd> value=rsync ~1
12805" varname<g:netrw_rsync_sep> value=/ ~1
12806" varname<g:netrw_scp_cmd> value=scp -q ~1
12807" varname<g:netrw_sftp_cmd> value=sftp ~1
12808" varname<g:netrw_ssh_cmd> value=ssh ~1
12809" varname<g:netrw_alto> value=0 ~1
12810" varname<g:netrw_altv> value=1 ~1
12811" varname<g:netrw_banner> value=1 ~1
12812" varname<g:netrw_browse_split> value=0 ~1
12813" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12814" varname<g:netrw_chgwin> value=-1 ~1
12815" varname<g:netrw_clipboard> value=1 ~1
12816" varname<g:netrw_compress> value=gzip ~1
12817" varname<g:netrw_ctags> value=ctags ~1
12818" varname<g:netrw_cursor> value=2 ~1
12819" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12820" varname<g:netrw_cygdrive> value=/cygdrive ~1
12821" varname<s:didstarstar> value=0 ~1
12822" varname<g:netrw_dirhistcnt> value=0 ~1
12823" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12824" varname<g:netrw_dirhistmax> value=10 ~1
12825" varname<g:netrw_errorlvl> value=0 ~1
12826" varname<g:netrw_fastbrowse> value=1 ~1
12827" 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
12828" varname<g:netrw_ftpmode> value=binary ~1
12829" varname<g:netrw_hide> value=1 ~1
12830" varname<g:netrw_keepdir> value=1 ~1
12831" varname<g:netrw_list_hide> value= ~1
12832" varname<g:netrw_localmkdir> value=mkdir ~1
12833" varname<g:netrw_remote_mkdir> value=mkdir ~1
12834" varname<g:netrw_liststyle> value=0 ~1
12835" varname<g:netrw_markfileesc> value=*./[\~ ~1
12836" varname<g:netrw_maxfilenamelen> value=32 ~1
12837" varname<g:netrw_menu> value=1 ~1
12838" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12839" varname<g:netrw_mousemaps> value=1 ~1
12840" varname<g:netrw_retmap> value=0 ~1
12841" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12842" varname<g:netrw_preview> value=0 ~1