blob: a9c88f0398e9a00a5607aa5f37617e6b0fe8584d [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
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandtf9ca1392024-02-19 20:37:11 +010016" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000017" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010018" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000019" Permission is hereby granted to use and distribute this code,
20" with or without modifications, provided that this copyright
21" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000022" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000023" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000024" expressed or implied. By using this plugin, you agree that
25" in no event will the copyright holder be liable for any damages
26" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010027"
28" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
29" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
30"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020031"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000032"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000033" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000034" (James 1:22 RSV)
35" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000036" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000037if &cp || exists("g:loaded_netrw")
38 finish
39endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020040
41" Check that vim has patches that netrw requires.
42" Patches needed for v7.4: 1557, and 213.
43" (netrw will benefit from vim's having patch#656, too)
44let s:needspatches=[1557,213]
45if exists("s:needspatches")
46 for ptch in s:needspatches
47 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
48 if !exists("s:needpatch{ptch}")
49 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
50 endif
51 let s:needpatch{ptch}= 1
52 finish
53 endif
54 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020055endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020056
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010057let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000058if !exists("s:NOTE")
59 let s:NOTE = 0
60 let s:WARNING = 1
61 let s:ERROR = 2
62endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000063
Bram Moolenaar1afcace2005-11-25 19:54:28 +000064let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010065setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020066"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010067"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010068"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000069
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000070" ======================
71" Netrw Variables: {{{1
72" ======================
73
Bram Moolenaar071d4272004-06-13 20:20:40 +000074" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020075" netrw#ErrorMsg: {{{2
76" 0=note = s:NOTE
77" 1=warning = s:WARNING
78" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010079" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
80" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
81" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010082" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020083fun! netrw#ErrorMsg(level,msg,errnum)
84" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
85
86 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020087" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020088 return
89 endif
90
91 if a:level == 1
92 let level= "**warning** (netrw) "
93 elseif a:level == 2
94 let level= "**error** (netrw) "
95 else
96 let level= "**note** (netrw) "
97 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010098" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020099
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200100 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
101 " use popup window
102 if type(a:msg) == 3
103 let msg = [level]+a:msg
104 else
105 let msg= level.a:msg
106 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200107 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200108 let s:popuperr_text= ""
109 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200110 " (default) netrw creates a one-line window to show error/warning
111 " messages (reliably displayed)
112
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100113 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200114 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100115" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200116
117 " getting messages out reliably is just plain difficult!
118 " This attempt splits the current window, creating a one line window.
119 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100120" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200121 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100122" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200123 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100124 if type(a:msg) == 3
125 for msg in a:msg
126 NetrwKeepj call setline(line("$")+1,level.msg)
127 endfor
128 else
129 NetrwKeepj call setline(line("$")+1,level.a:msg)
130 endif
131 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200132 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100133" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200134 bo 1split
135 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200136 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200137 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100138 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100139" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200140 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100141 if type(a:msg) == 3
142 for msg in a:msg
143 NetrwKeepj call setline(line("$")+1,level.msg)
144 endfor
145 else
146 NetrwKeepj call setline(line("$"),level.a:msg)
147 endif
148 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200149 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100150" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200151 if &fo !~ '[ta]'
152 syn clear
153 syn match netrwMesgNote "^\*\*note\*\*"
154 syn match netrwMesgWarning "^\*\*warning\*\*"
155 syn match netrwMesgError "^\*\*error\*\*"
156 hi link netrwMesgWarning WarningMsg
157 hi link netrwMesgError Error
158 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100159" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200160 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200161
162 else
163 " (optional) netrw will show messages using echomsg. Even if the
164 " message doesn't appear, at least it'll be recallable via :messages
165" redraw!
166 if a:level == s:WARNING
167 echohl WarningMsg
168 elseif a:level == s:ERROR
169 echohl Error
170 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100171
172 if type(a:msg) == 3
173 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100174 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100175 endfor
176 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100177 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100178 endif
179
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100180" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200181 echohl None
182 endif
183
184" call Dret("netrw#ErrorMsg")
185endfun
186
187" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100188" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100189" Loosely, varname = value.
190fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100191" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100192 if !exists(a:varname)
193 if type(a:value) == 0
194 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200195 elseif type(a:value) == 1 && a:value =~ '^[{[]'
196 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100197 elseif type(a:value) == 1
198 exe "let ".a:varname."="."'".a:value."'"
199 else
200 exe "let ".a:varname."=".a:value
201 endif
202 endif
203endfun
204
205" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000206" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200207call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000208if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100209 call s:NetrwInit("s:THINLIST",0)
210 call s:NetrwInit("s:LONGLIST",1)
211 call s:NetrwInit("s:WIDELIST",2)
212 call s:NetrwInit("s:TREELIST",3)
213 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000214endif
215
216" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200217" Default option values: {{{2
218let g:netrw_localcopycmdopt = ""
219let g:netrw_localcopydircmdopt = ""
220let g:netrw_localmkdiropt = ""
221let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200222
223" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000224" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200225if (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")
226 call s:NetrwInit("g:netrw_use_errorwindow",2)
227else
228 call s:NetrwInit("g:netrw_use_errorwindow",1)
229endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200230
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000231if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100232 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000233 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100234 elseif executable("curl")
235 let g:netrw_dav_cmd = "curl"
236 else
237 let g:netrw_dav_cmd = ""
238 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000239endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000240if !exists("g:netrw_fetch_cmd")
241 if executable("fetch")
242 let g:netrw_fetch_cmd = "fetch -o"
243 else
244 let g:netrw_fetch_cmd = ""
245 endif
246endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100247if !exists("g:netrw_file_cmd")
248 if executable("elinks")
249 call s:NetrwInit("g:netrw_file_cmd","elinks")
250 elseif executable("links")
251 call s:NetrwInit("g:netrw_file_cmd","links")
252 endif
253endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000254if !exists("g:netrw_ftp_cmd")
255 let g:netrw_ftp_cmd = "ftp"
256endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200257let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200258if !exists("g:netrw_ftp_options")
259 let g:netrw_ftp_options= "-i -n"
260endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000261if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100262 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100263 let g:netrw_http_cmd = "wget"
264 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100265 elseif executable("curl")
266 let g:netrw_http_cmd = "curl"
267 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200268 elseif executable("elinks")
269 let g:netrw_http_cmd = "elinks"
270 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000271 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100272 let g:netrw_http_cmd = "fetch"
273 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200274 elseif executable("links")
275 let g:netrw_http_cmd = "links"
276 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000277 else
278 let g:netrw_http_cmd = ""
279 endif
280endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100281call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100282call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100283call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
284call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200285call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200286if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200287 if executable("scp")
288 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
289 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200290 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200291 else
292 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
293 endif
294endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100295call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
296call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000297
Nir Lichtman1e34b952024-05-08 19:19:34 +0200298if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000299 \ && exists("g:netrw_use_nt_rcp")
300 \ && g:netrw_use_nt_rcp
301 \ && executable( $SystemRoot .'/system32/rcp.exe')
302 let s:netrw_has_nt_rcp = 1
303 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000304else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000305 let s:netrw_has_nt_rcp = 0
306 let s:netrw_rcpmode = ''
307endif
308
309" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000310" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000311" Cygwin Detection ------- {{{3
312if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200313 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
314 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000315 else
316 let g:netrw_cygwin= 0
317 endif
318endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000319" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100320call s:NetrwInit("g:netrw_alto" , &sb)
321call s:NetrwInit("g:netrw_altv" , &spr)
322call s:NetrwInit("g:netrw_banner" , 1)
323call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200324call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100325call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200326call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100327call s:NetrwInit("g:netrw_compress" , "gzip")
328call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200329if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
330 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
331 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000332endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200333call s:NetrwInit("g:netrw_cursor" , 2)
334let s:netrw_usercul = &cursorline
335let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200336"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100337call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000338" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200339call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200340call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200341call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100342call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200343call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100344call s:NetrwInit("g:netrw_fastbrowse" , 1)
345call 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 +0000346if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000347 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
348 let g:netrw_ftp_list_cmd = "ls -lF"
349 let g:netrw_ftp_timelist_cmd = "ls -tlF"
350 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000351 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000352 let g:netrw_ftp_list_cmd = "dir"
353 let g:netrw_ftp_timelist_cmd = "dir"
354 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000355 endif
356endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100357call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000358" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100359call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000360if !exists("g:netrw_ignorenetrc")
361 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
362 let g:netrw_ignorenetrc= 1
363 else
364 let g:netrw_ignorenetrc= 0
365 endif
366endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100367call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000368if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000369 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100370 if exists("g:netrw_list_cmd_options")
371 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
372 else
373 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
374 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000375 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200376 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100377 if exists("g:netrw_list_cmd_options")
378 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
379 else
380 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
381 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000382 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100383" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000384 let g:netrw_list_cmd= ""
385 endif
386endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100387call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000388" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200389if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200390 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200391 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
392endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100393if !exists("g:netrw_localcmdshell")
394 let g:netrw_localcmdshell= ""
395endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000396if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200397 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000398 if g:netrw_cygwin
399 let g:netrw_localcopycmd= "cp"
400 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000401 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200402 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000403 endif
404 elseif has("unix") || has("macunix")
405 let g:netrw_localcopycmd= "cp"
406 else
407 let g:netrw_localcopycmd= ""
408 endif
409endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100410if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200411 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100412 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200413 let g:netrw_localcopydircmd = "cp"
414 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100415 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000416 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200417 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100418 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200419 elseif has("unix")
420 let g:netrw_localcopydircmd = "cp"
421 let g:netrw_localcopydircmdopt= " -R"
422 elseif has("macunix")
423 let g:netrw_localcopydircmd = "cp"
424 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100425 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200426 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100427 endif
428endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200429if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100430 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200431 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
432endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200433if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200434 if g:netrw_cygwin
435 call s:NetrwInit("g:netrw_localmkdir","mkdir")
436 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000437 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200438 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200439 endif
440else
441 call s:NetrwInit("g:netrw_localmkdir","mkdir")
442endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200443call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200444if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200445 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200446 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
447endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000448if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200449 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000450 if g:netrw_cygwin
451 let g:netrw_localmovecmd= "mv"
452 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000453 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200454 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000455 endif
456 elseif has("unix") || has("macunix")
457 let g:netrw_localmovecmd= "mv"
458 else
459 let g:netrw_localmovecmd= ""
460 endif
461endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100462" following serves as an example for how to insert a version&patch specific test
463"if v:version < 704 || (v:version == 704 && !has("patch1107"))
464"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100465call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
466" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000467if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000468 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000469endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000470if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000471 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
472endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000473" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100474call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
475call s:NetrwInit("g:netrw_maxfilenamelen", 32)
476call s:NetrwInit("g:netrw_menu" , 1)
477call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200478call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100479call s:NetrwInit("g:netrw_retmap" , 0)
480if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
481 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200482elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100483 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
484else
485 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000486endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100487call s:NetrwInit("g:netrw_preview" , 0)
488call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100489call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100490call s:NetrwInit("g:netrw_sshport" , "-p")
491call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
492call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
493call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100494call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
495" Default values - q-s ---------- {{{3
496call s:NetrwInit("g:netrw_quickhelp",0)
497let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100498 \ "(create new) %:file d:directory",
499 \ "(windows split&open) o:horz v:vert p:preview",
500 \ "i:style qf:file info O:obtain r:reverse",
501 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
502 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
503 \ "(history) qb:list u:go up U:go down",
504 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100505" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
506call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100507if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
508 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
509else
510 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
511endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100512call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
513call s:NetrwInit("g:netrw_sort_options" , "")
514call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000515if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100516 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200517 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100518 else
519 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000520 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000521endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100522call s:NetrwInit("g:netrw_special_syntax" , 0)
523call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200524call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100525call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100526call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000527" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100528call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200529if !exists("g:netrw_xstrlen")
530 if exists("g:Align_xstrlen")
531 let g:netrw_xstrlen= g:Align_xstrlen
532 elseif exists("g:drawit_xstrlen")
533 let g:netrw_xstrlen= g:drawit_xstrlen
534 elseif &enc == "latin1" || !has("multi_byte")
535 let g:netrw_xstrlen= 0
536 else
537 let g:netrw_xstrlen= 1
538 endif
539endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100540call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200541call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100542call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200543if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000544" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000545" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100546call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200547if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200548 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200549else
Bram Moolenaarff034192013-04-24 18:51:19 +0200550 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200551endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200552call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100553call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
554call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100555if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100556 let s:treedepthstring= "│ "
557else
558 let s:treedepthstring= "| "
559endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200560call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000561
562" BufEnter event ignored by decho when following variable is true
563" Has a side effect that doau BufReadPost doesn't work, so
564" files read by network transfer aren't appropriately highlighted.
565"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566
Bram Moolenaaradc21822011-04-01 18:03:16 +0200567" ======================
568" Netrw Initialization: {{{1
569" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200570if 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 +0100571" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100572 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200573" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100574 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100575 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
576 au VimEnter * let s:initbeval= &beval
577"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100578" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
579" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
580" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
581" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
582" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
583" 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 +0200584endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200585au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200586
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200587if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100588 com! -nargs=* NetrwKeepj keepj <args>
589else
590 let g:netrw_keepj= ""
591 com! -nargs=* NetrwKeepj <args>
592endif
593
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000594" ==============================
595" Netrw Utility Functions: {{{1
596" ==============================
597
Bram Moolenaaradc21822011-04-01 18:03:16 +0200598" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100599" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100600if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100601" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100602 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100603 if &ft != "netrw"
604 return ""
605 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200606 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
607 " popup error window is still showing
608 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
609 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
610 " text under mouse hasn't changed; only close window when it changes
611 call popup_close(s:popuperr_id)
612 unlet s:popuperr_text
613 else
614 let s:popuperr_text= v:beval_text
615 endif
616 let mesg= ""
617 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 +0100618 let mesg= ""
619 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
620 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
621 elseif getline(v:beval_lnum) =~ '^"\s*/'
622 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
623 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100624 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100625 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
626 let mesg = "S: edit sorting sequence"
627 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
628 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
629 elseif v:beval_text == "Quick" || v:beval_text == "Help"
630 let mesg = "Help: press <F1>"
631 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
632 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
633 else
634 let mesg= ""
635 endif
636 return mesg
637 endfun
638"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100639" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
640" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
641" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
642" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
643" 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 +0200644endif
645
Bram Moolenaar071d4272004-06-13 20:20:40 +0000646" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200647" netrw#Explore: launch the local browser in the directory of the current file {{{2
648" indx: == -1: Nexplore
649" == -2: Pexplore
650" == +: this is overloaded:
651" * If Nexplore/Pexplore is in use, then this refers to the
652" indx'th item in the w:netrw_explore_list[] of items which
653" matched the */pattern **/pattern *//pattern **//pattern
654" * If Hexplore or Vexplore, then this will override
655" g:netrw_winsize to specify the qty of rows or columns the
656" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100657" 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 +0200658" dosplit==1: the window will be split before running the local browser
659" style == 0: Explore style == 1: Explore!
660" == 2: Hexplore style == 3: Hexplore!
661" == 4: Vexplore style == 5: Vexplore!
662" == 6: Texplore
663fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100664" 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 +0100665" 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 +0200666 if !exists("b:netrw_curdir")
667 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100668" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200669 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100670
671 " record current file for Rexplore's benefit
672 if &ft != "netrw"
673 let w:netrw_rexfile= expand("%:p")
674 endif
675
676 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200677 let curdir = simplify(b:netrw_curdir)
678 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200679 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200680 let curdir= substitute(curdir,'\','/','g')
681 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100682" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100683
684 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
685 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
686 " try Explore again.
687 if a:0 > 0
688" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100689 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
690 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
691 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
692 \ '~'.expand("<slnum>"))
693 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
694" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100695 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
696" call Dret("netrw#Explore : returning from retry")
697 return
698" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100699" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100700 endif
701 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200702
703 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200704 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100705" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100706 sil! let keepregstar = @*
707 sil! let keepregplus = @+
708 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200709 sil! let keepregslash= @/
710
Bram Moolenaar8d043172014-01-23 14:24:41 +0100711 " if dosplit
712 " -or- file has been modified AND file not hidden when abandoned
713 " -or- Texplore used
714 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100715" 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 +0200716 call s:SaveWinVars()
717 let winsz= g:netrw_winsize
718 if a:indx > 0
719 let winsz= a:indx
720 endif
721
722 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100723" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200724 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200725 if winsz == 0|let winsz= ""|endif
726 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100727" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200728
729 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100730" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200731 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200732 if winsz == 0|let winsz= ""|endif
733 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100734" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200735
736 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100737" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200738 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200739 if winsz == 0|let winsz= ""|endif
740 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100741" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200742
743 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100744" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200745 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200746 if winsz == 0|let winsz= ""|endif
747 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100748" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200749
750 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100751" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200752 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200753 if winsz == 0|let winsz= ""|endif
754 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100755" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200756
757 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100758" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200759 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200760 if winsz == 0|let winsz= ""|endif
761 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100762" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200763
764 elseif a:style == 6 " Texplore
765 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100766" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200767 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100768" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200769 call s:RestoreBufVars()
770 endif
771 call s:RestoreWinVars()
772" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100773" 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 +0200774 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100775 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200776
777 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100778" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200779 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100780" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200781 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100782" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100784" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
786 if dirname !~ '/$'
787 let dirname= dirname."/"
788 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100789" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200790 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100791" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200792 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100793" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200794 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100799" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200800 let dirname= a:1
801 endif
802 else
803 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100804" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200805 call s:NetrwClearExplore()
806" call Dret("netrw#Explore : cleared list")
807 return
808 endif
809
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100810" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200811 if dirname =~ '\.\./\=$'
812 let dirname= simplify(fnamemodify(dirname,':p:h'))
813 elseif dirname =~ '\.\.' || dirname == '.'
814 let dirname= simplify(fnamemodify(dirname,':p'))
815 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100816" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200817
818 if dirname =~ '^\*//'
819 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100820" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200821 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
822 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100823" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200824 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
825
826 elseif dirname =~ '^\*\*//'
827 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100828" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200829 let pattern= substitute(dirname,'^\*\*//','','')
830 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100831" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200832
833 elseif dirname =~ '/\*\*/'
834 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100835" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200836 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200837 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200838 let b:netrw_curdir = prefixdir
839 else
840 let b:netrw_curdir= getcwd().'/'.prefixdir
841 endif
842 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
843 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100844" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
845" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200846
847 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200848 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200849 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100850" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200851
852 elseif dirname=~ '^\*\*/'
853 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
854 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100855" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200856
857 else
858 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100859" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200860 endif
861
862 if starpat == 0 && a:indx >= 0
863 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100864" 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 +0200865 if dirname == ""
866 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100867" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200868 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200869 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200870 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200871 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200872 if dirname == ""
873 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200874 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100875 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100876 " depending on whether backslashes have been converted to forward slashes by earlier code).
877 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200878 let dirname= b:netrw_curdir."/".dirname
879 endif
880 elseif dirname !~ '^/'
881 let dirname= b:netrw_curdir."/".dirname
882 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100883" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200884 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100885" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
886" 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 +0200887 endif
888 if exists("w:netrw_bannercnt")
889 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
890 " If one wants to return the same place in the netrw window, use :Rex instead.
891 exe w:netrw_bannercnt
892 endif
893
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100894" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200895 " ---------------------------------------------------------------------
896 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
897" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100898" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200899" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100900" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200901" endif
902 " ---------------------------------------------------------------------
903
904 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
905 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
906 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
907 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
908 elseif a:indx <= 0
909 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100910" 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 +0200911 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100912" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200913 let s:didstarstar= 1
914 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
915 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
916 endif
917
918 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100919" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200920 if !exists("w:netrw_explore_indx")
921 let w:netrw_explore_indx= 0
922 endif
923
924 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100925" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200926
927 if indx == -1
928 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100929" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200930 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100931 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 +0200932 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100933" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100934 if @* != keepregstar | sil! let @* = keepregstar | endif
935 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100936 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200937 sil! let @/ = keepregslash
938" call Dret("netrw#Explore")
939 return
940 endif
941 let indx= w:netrw_explore_indx
942 if indx < 0 | let indx= 0 | endif
943 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
944 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100945" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200946 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
947 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100948" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200949 endwhile
950 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100951" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200952
953 elseif indx == -2
954 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100955" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200956 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100957 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 +0200958 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100959" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100960 if @* != keepregstar | sil! let @* = keepregstar | endif
961 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100962 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200963 sil! let @/ = keepregslash
964" call Dret("netrw#Explore")
965 return
966 endif
967 let indx= w:netrw_explore_indx
968 if indx < 0 | let indx= 0 | endif
969 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
970 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100971" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200972 while indx >= 0 && curfile == w:netrw_explore_list[indx]
973 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100974" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200975 endwhile
976 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100977" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200978
979 else
980 " Explore -- initialize
981 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100982" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100983 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200984 let w:netrw_explore_indx= 0
985 if !exists("b:netrw_curdir")
986 let b:netrw_curdir= getcwd()
987 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100988" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200989
990 " switch on starpat to build the w:netrw_explore_list of files
991 if starpat == 1
992 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100993" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
994" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200995 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100996 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200997 catch /^Vim\%((\a\+)\)\=:E480/
998 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
999" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1000 return
1001 endtry
1002 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1003 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1004
1005 elseif starpat == 2
1006 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001007" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1008" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001009 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001010 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001011 catch /^Vim\%((\a\+)\)\=:E480/
1012 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1013 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001014 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001015" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001016 if @* != keepregstar | sil! let @* = keepregstar | endif
1017 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001018 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001019 sil! let @/ = keepregslash
1020" call Dret("netrw#Explore : no files matched pattern")
1021 return
1022 endtry
1023 let s:netrw_curdir = b:netrw_curdir
1024 let w:netrw_explore_list = getqflist()
1025 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1026 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1027
1028 elseif starpat == 3
1029 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001030" 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 +02001031 let filepat= substitute(dirname,'^\*/','','')
1032 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001033" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1034" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001035 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1036 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1037
1038 elseif starpat == 4
1039 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001040" 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 +02001041 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1042 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1043 endif " switch on starpat to build w:netrw_explore_list
1044
1045 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001046" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1047" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001048
1049 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001050 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001051 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001052" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001053 if @* != keepregstar | sil! let @* = keepregstar | endif
1054 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001055 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001056 sil! let @/ = keepregslash
1057" call Dret("netrw#Explore : no files matched")
1058 return
1059 endif
1060 endif " if indx ... endif
1061
1062 " NetrwStatusLine support - for exploring support
1063 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001064" 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 +02001065
1066 " wrap the indx around, but issue a note
1067 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001068" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001069 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1070 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001071 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001072 endif
1073
1074 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001075" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001076 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001077" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001078
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001079" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001080 call netrw#LocalBrowseCheck(newdir)
1081 if !exists("w:netrw_liststyle")
1082 let w:netrw_liststyle= g:netrw_liststyle
1083 endif
1084 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001085 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001086 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001087 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001088 endif
1089 let w:netrw_explore_mtchcnt = indx + 1
1090 let w:netrw_explore_bufnr = bufnr("%")
1091 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001092 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001093" 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 +02001094
1095 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001096" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001097 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001098 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 +02001099 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001100 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001101" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001102 if @* != keepregstar | sil! let @* = keepregstar | endif
1103 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001104 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001105 sil! let @/ = keepregslash
1106" call Dret("netrw#Explore : missing +path_extra")
1107 return
1108 endif
1109
1110 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001111" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001112 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1113 sil! unlet w:netrw_treedict
1114 sil! unlet w:netrw_treetop
1115 endif
1116 let newdir= dirname
1117 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001118 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001119 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001120 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001121 endif
1122 endif
1123
1124 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001125" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1126" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001127 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001128" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001129 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001130 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001131" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001132 let s:explore_prvdir = b:netrw_curdir
1133 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001134 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001135 if b:netrw_curdir !~ '/$'
1136 let dirlen= dirlen + 1
1137 endif
1138 let prvfname= ""
1139 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001140" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001141 if fname =~ '^'.b:netrw_curdir
1142 if s:explore_match == ""
1143 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1144 else
1145 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1146 endif
1147 elseif fname !~ '^/' && fname != prvfname
1148 if s:explore_match == ""
1149 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1150 else
1151 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1152 endif
1153 endif
1154 let prvfname= fname
1155 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001156" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001157 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1158 exe "2match netrwMarkFile /".s:explore_match."/"
1159 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001160 endif
1161 echo "<s-up>==Pexplore <s-down>==Nexplore"
1162 else
1163 2match none
1164 if exists("s:explore_match") | unlet s:explore_match | endif
1165 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001166" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001167 endif
1168
Bram Moolenaara6878372014-03-22 21:02:50 +01001169 " since Explore may be used to initialize netrw's browser,
1170 " there's no danger of a late FocusGained event on initialization.
1171 " Consequently, set s:netrw_events to 2.
1172 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001173 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001174" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001175 if @* != keepregstar | sil! let @* = keepregstar | endif
1176 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001177 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001178 sil! let @/ = keepregslash
1179" call Dret("netrw#Explore : @/<".@/.">")
1180endfun
1181
1182" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001183" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001184" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1185" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1186" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1187" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1188" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001189fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001190" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001191 let curwin= winnr()
1192
Bram Moolenaara6878372014-03-22 21:02:50 +01001193 if a:0 > 0 && a:1 != ""
1194 " if a netrw window is already on the left-side of the tab
1195 " and a directory has been specified, explore with that
1196 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001197" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001198 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001199" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001200 exe "1wincmd w"
1201 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001202" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001203 exe "Explore ".fnameescape(a1)
1204 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001205 let s:lexplore_win= curwin
1206 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001208" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001209 unlet t:netrw_lexposn
1210 endif
1211" call Dret("netrw#Lexplore")
1212 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001213 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001214 exe curwin."wincmd w"
1215 else
1216 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001217" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001218 endif
1219
Bram Moolenaar8d043172014-01-23 14:24:41 +01001220 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001221 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001222 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001223" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001224 else
1225 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001226" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001227 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001228" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001229
1230 if lexwinnr > 0
1231 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001232" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001233 exe lexwinnr."wincmd w"
1234 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001235 let t:netrw_lexposn = winsaveview()
1236" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001237" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001238 close
1239 if lexwinnr < curwin
1240 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001241 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001242 if lexwinnr != curwin
1243 exe curwin."wincmd w"
1244 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001245 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001246" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001247
1248 else
1249 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001250" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001251 exe "1wincmd w"
1252 let keep_altv = g:netrw_altv
1253 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001254 if a:count != 0
1255 let netrw_winsize = g:netrw_winsize
1256 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001257 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001258 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001259" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001260 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 +02001261" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001262 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001263" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001264 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001265 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001266 elseif curfile =~ '^\a\{3,}://'
1267" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001268 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001269 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001270" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001271 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001272 endif
1273 if a:count != 0
1274 let g:netrw_winsize = netrw_winsize
1275 endif
1276 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001277 let g:netrw_altv = keep_altv
1278 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001279 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1280 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001281 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001282 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001283" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1284" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001285 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001286" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001287" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1288 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001289 unlet t:netrw_lexposn
1290 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001291 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001292
1293 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001294 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001295 if a:rightside
1296 let g:netrw_chgwin= 1
1297 else
1298 let g:netrw_chgwin= 2
1299 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001300" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001301 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001302
Bram Moolenaar8d043172014-01-23 14:24:41 +01001303" call Dret("netrw#Lexplore")
1304endfun
1305
1306" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001307" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001308" supports :NetrwClean -- remove netrw from first directory on runtimepath
1309" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001310fun! netrw#Clean(sys)
1311" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001312
1313 if a:sys
1314 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1315 else
1316 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1317 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001318" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001319 let diddel= 0
1320 let diddir= ""
1321
1322 if choice == 1
1323 for dir in split(&rtp,',')
1324 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001325" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001326 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1327 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1328 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1329 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1330 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1331 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 +00001332 let diddir= dir
1333 let diddel= diddel + 1
1334 if !a:sys|break|endif
1335 endif
1336 endfor
1337 endif
1338
1339 echohl WarningMsg
1340 if diddel == 0
1341 echomsg "netrw is either not installed or not removable"
1342 elseif diddel == 1
1343 echomsg "removed one copy of netrw from <".diddir.">"
1344 else
1345 echomsg "removed ".diddel." copies of netrw"
1346 endif
1347 echohl None
1348
Bram Moolenaara6878372014-03-22 21:02:50 +01001349" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001350endfun
1351
Bram Moolenaar5c736222010-01-06 20:54:52 +01001352" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001353" netrw#MakeTgt: make a target out of the directory name provided {{{2
1354fun! netrw#MakeTgt(dname)
1355" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1356 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001357 let svpos = winsaveview()
1358" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001359 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1360" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001361 if s:netrwmftgt_islocal
1362 let netrwmftgt= simplify(a:dname)
1363 else
1364 let netrwmftgt= a:dname
1365 endif
1366 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1367 " re-selected target, so just clear it
1368 unlet s:netrwmftgt s:netrwmftgt_islocal
1369 else
1370 let s:netrwmftgt= netrwmftgt
1371 endif
1372 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001373 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001374 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001375" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1376 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001377" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001378endfun
1379
Bram Moolenaara6878372014-03-22 21:02:50 +01001380" ---------------------------------------------------------------------
1381" netrw#Obtain: {{{2
1382" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001383" islocal=0 obtain from remote source
1384" =1 obtain from local source
1385" fname : a filename or a list of filenames
1386" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001387fun! netrw#Obtain(islocal,fname,...)
1388" 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 +02001389 " NetrwStatusLine support - for obtaining support
1390
1391 if type(a:fname) == 1
1392 let fnamelist= [ a:fname ]
1393 elseif type(a:fname) == 3
1394 let fnamelist= a:fname
1395 else
1396 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 +01001397" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001398 return
1399 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001400" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001401 if a:0 > 0
1402 let tgtdir= a:1
1403 else
1404 let tgtdir= getcwd()
1405 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001406" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001407
1408 if exists("b:netrw_islocal") && b:netrw_islocal
1409 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001410" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001411 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1412 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001413 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001414 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001415" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001416 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001417" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001418 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001419 if v:shell_error != 0
1420 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 +01001421" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001422 return
1423 endif
1424 endfor
1425 else
1426 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001427" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1428 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1429" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001430 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001431 if v:shell_error != 0
1432 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 +01001433" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001434 return
1435 endif
1436 endif
1437 elseif !exists("b:netrw_curdir")
1438 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1439 else
1440 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1441 endif
1442
1443 else
1444 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001445" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001446 if type(a:fname) == 1
1447 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1448 endif
1449 call s:NetrwMethod(b:netrw_curdir)
1450
1451 if b:netrw_method == 4
1452 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001453" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001454 if exists("g:netrw_port") && g:netrw_port != ""
1455 let useport= " ".g:netrw_scpport." ".g:netrw_port
1456 else
1457 let useport= ""
1458 endif
1459 if b:netrw_fname =~ '/'
1460 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1461 else
1462 let path= ""
1463 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001464 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001465 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 +02001466
1467 elseif b:netrw_method == 2
1468 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001469" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001470 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001471 let tmpbufnr= bufnr("%")
1472 setl ff=unix
1473 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001474 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001475" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001476 endif
1477
1478 if exists("b:netrw_fname") && b:netrw_fname != ""
1479 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001480" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001481 endif
1482
1483 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001484 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001485" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001486 endif
1487 for fname in fnamelist
1488 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001489" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001490 endfor
1491 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001492 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 +02001493 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001494 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001495 endif
1496 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1497 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1498 let debugkeep= &debug
1499 setl debug=msg
1500 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1501 let &debug= debugkeep
1502 endif
1503
1504 elseif b:netrw_method == 3
1505 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001506" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001507 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001508 let tmpbufnr= bufnr("%")
1509 setl ff=unix
1510
1511 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001512 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001513" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001514 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001515 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001516" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001517 endif
1518
1519 if exists("g:netrw_uid") && g:netrw_uid != ""
1520 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001521 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001522" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001523 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001524 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001525 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001526" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001527 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001528 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001529" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001530 endif
1531 endif
1532
1533 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001534 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001535" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001536 endif
1537
1538 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001539 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001540" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001541 endif
1542
1543 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001544 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001545" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001546 endif
1547
1548 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001549 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001550" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001551 endif
1552 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001553 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001554 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001555" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001556
1557 " perform ftp:
1558 " -i : turns off interactive prompting from ftp
1559 " -n unix : DON'T use <.netrc>, even though it exists
1560 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001561 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1562 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001563 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001564 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1565 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001566" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001567 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001568 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001569 endif
1570 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001571
1572 elseif b:netrw_method == 9
1573 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001574" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001575 if a:fname =~ '/'
1576 let localfile= substitute(a:fname,'^.*/','','')
1577 else
1578 let localfile= a:fname
1579 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001580 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 +02001581
Bram Moolenaarff034192013-04-24 18:51:19 +02001582 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001583 " probably a badly formed url; protocol not recognized
1584" call Dret("netrw#Obtain : unsupported method")
1585 return
1586
1587 else
1588 " protocol recognized but not supported for Obtain (yet?)
1589 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001590 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001591 endif
1592" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001593 return
1594 endif
1595
1596 " restore status line
1597 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001598 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001599 endif
1600
1601 endif
1602
1603 " cleanup
1604 if exists("tmpbufnr")
1605 if bufnr("%") != tmpbufnr
1606 exe tmpbufnr."bw!"
1607 else
1608 q!
1609 endif
1610 endif
1611
Bram Moolenaara6878372014-03-22 21:02:50 +01001612" call Dret("netrw#Obtain")
1613endfun
1614
1615" ---------------------------------------------------------------------
1616" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1617fun! netrw#Nread(mode,fname)
1618" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001619 let svpos= winsaveview()
1620" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001621 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001622" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1623 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001624
1625 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1626 if exists("w:netrw_bannercnt")
1627 " start with cursor just after the banner
1628 exe w:netrw_bannercnt
1629 endif
1630 endif
1631" call Dret("netrw#Nread")
1632endfun
1633
1634" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001635" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1636" Options get restored by s:NetrwOptionsRestore()
1637"
1638" Option handling:
1639" * save user's options (s:NetrwOptionsSave)
1640" * set netrw-safe options (s:NetrwOptionsSafe)
1641" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1642" * restore user's options (s:netrwOPtionsRestore)
1643" - restore a user option when != safe option (s:NetrwRestoreSetting)
1644" vt: (variable type) normally its either "w:" or "s:"
1645fun! s:NetrwOptionsSave(vt)
1646" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1647" 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 +02001648" 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>"))
1649" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001650
1651 if !exists("{a:vt}netrw_optionsave")
1652 let {a:vt}netrw_optionsave= 1
1653 else
1654" call Dret("s:NetrwOptionsSave : options already saved")
1655 return
1656 endif
1657" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1658
1659 " Save current settings and current directory
1660" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1661 let s:yykeep = @@
1662 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1663 let {a:vt}netrw_aikeep = &l:ai
1664 let {a:vt}netrw_awkeep = &l:aw
1665 let {a:vt}netrw_bhkeep = &l:bh
1666 let {a:vt}netrw_blkeep = &l:bl
1667 let {a:vt}netrw_btkeep = &l:bt
1668 let {a:vt}netrw_bombkeep = &l:bomb
1669 let {a:vt}netrw_cedit = &cedit
1670 let {a:vt}netrw_cikeep = &l:ci
1671 let {a:vt}netrw_cinkeep = &l:cin
1672 let {a:vt}netrw_cinokeep = &l:cino
1673 let {a:vt}netrw_comkeep = &l:com
1674 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001675 let {a:vt}netrw_cuckeep = &l:cuc
1676 let {a:vt}netrw_culkeep = &l:cul
1677" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001678 let {a:vt}netrw_diffkeep = &l:diff
1679 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001680 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1681 let {a:vt}netrw_ffkeep = &l:ff
1682 endif
1683 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1684 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001685 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001686 let {a:vt}netrw_hidkeep = &l:hidden
1687 let {a:vt}netrw_imkeep = &l:im
1688 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001689 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001690 let {a:vt}netrw_lskeep = &l:ls
1691 let {a:vt}netrw_makeep = &l:ma
1692 let {a:vt}netrw_magickeep = &l:magic
1693 let {a:vt}netrw_modkeep = &l:mod
1694 let {a:vt}netrw_nukeep = &l:nu
1695 let {a:vt}netrw_rnukeep = &l:rnu
1696 let {a:vt}netrw_repkeep = &l:report
1697 let {a:vt}netrw_rokeep = &l:ro
1698 let {a:vt}netrw_selkeep = &l:sel
1699 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001700 if !g:netrw_use_noswf
1701 let {a:vt}netrw_swfkeep = &l:swf
1702 endif
1703 let {a:vt}netrw_tskeep = &l:ts
1704 let {a:vt}netrw_twkeep = &l:tw " textwidth
1705 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1706 let {a:vt}netrw_wrapkeep = &l:wrap
1707 let {a:vt}netrw_writekeep = &l:write
1708
1709 " save a few selected netrw-related variables
1710" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1711 if g:netrw_keepdir
1712 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001713" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001714 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001715 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001716 sil! let {a:vt}netrw_starkeep = @*
1717 sil! let {a:vt}netrw_pluskeep = @+
1718 endif
1719 sil! let {a:vt}netrw_slashkeep= @/
1720
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001721" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001722" 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>"))
1723" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1724endfun
1725
1726" ---------------------------------------------------------------------
1727" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1728" Use s:NetrwSaveOptions() to save user settings
1729" Use s:NetrwOptionsRestore() to restore user settings
1730fun! s:NetrwOptionsSafe(islocal)
1731" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1732" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1733" 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>"))
1734 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1735 call s:NetrwSetSafeSetting("&l:ai",0)
1736 call s:NetrwSetSafeSetting("&l:aw",0)
1737 call s:NetrwSetSafeSetting("&l:bl",0)
1738 call s:NetrwSetSafeSetting("&l:bomb",0)
1739 if a:islocal
1740 call s:NetrwSetSafeSetting("&l:bt","nofile")
1741 else
1742 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1743 endif
1744 call s:NetrwSetSafeSetting("&l:ci",0)
1745 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001746 if g:netrw_fastbrowse > a:islocal
1747 call s:NetrwSetSafeSetting("&l:bh","hide")
1748 else
1749 call s:NetrwSetSafeSetting("&l:bh","delete")
1750 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001751 call s:NetrwSetSafeSetting("&l:cino","")
1752 call s:NetrwSetSafeSetting("&l:com","")
1753 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1754 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1755 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001756 if &go =~ 'a' | set go-=a | endif
1757 if &go =~ 'A' | set go-=A | endif
1758 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001759 call s:NetrwSetSafeSetting("&l:hid",0)
1760 call s:NetrwSetSafeSetting("&l:im",0)
1761 setl isk+=@ isk+=* isk+=/
1762 call s:NetrwSetSafeSetting("&l:magic",1)
1763 if g:netrw_use_noswf
1764 call s:NetrwSetSafeSetting("swf",0)
1765 endif
1766 call s:NetrwSetSafeSetting("&l:report",10000)
1767 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1768 call s:NetrwSetSafeSetting("&l:spell",0)
1769 call s:NetrwSetSafeSetting("&l:tw",0)
1770 call s:NetrwSetSafeSetting("&l:wig","")
1771 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001772
1773 " set up cuc and cul based on g:netrw_cursor and listing style
1774 " COMBAK -- cuc cul related
1775 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001776
1777 " allow the user to override safe options
1778" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1779 if &ft == "netrw"
1780" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1781 keepalt NetrwKeepj doau FileType netrw
1782 endif
1783
1784" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1785" 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>"))
1786" call Dret("s:NetrwOptionsSafe")
1787endfun
1788
1789" ---------------------------------------------------------------------
1790" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1791fun! s:NetrwOptionsRestore(vt)
1792" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001793" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001794" 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 +01001795 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001796" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001797
1798 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1799 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001800" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001801 filetype detect
1802" 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>"))
1803 else
1804 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001805 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001806" 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 +02001807" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001808 return
1809 endif
1810 unlet {a:vt}netrw_optionsave
1811
1812 if exists("+acd")
1813 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001814" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001815 let curdir = getcwd()
1816 let &l:acd = {a:vt}netrw_acdkeep
1817 unlet {a:vt}netrw_acdkeep
1818 if &l:acd
1819 call s:NetrwLcd(curdir)
1820 endif
1821 endif
1822 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001823" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001824 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1825 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1826 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1827 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1828 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001829" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001830 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1831 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1832 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1833 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1834 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001835" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001836 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1837 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1838 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1839 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1840 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001841 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001842" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1843 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1844 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001845 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001846 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1847" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1848 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1849 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1850" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1851 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1852" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1853 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1854 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001855 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001856 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1857 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1858" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1859 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1860 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1861 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1862 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1863" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001864 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001865 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1866 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1867 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001868 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001869" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001870 call s:NetrwRestoreSetting("s:yykeep","@@")
1871 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1872 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1873 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1874 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1875
Bram Moolenaara6878372014-03-22 21:02:50 +01001876 if exists("{a:vt}netrw_swfkeep")
1877 if &directory == ""
1878 " user hasn't specified a swapfile directory;
1879 " netrw will temporarily set the swapfile directory
1880 " to the current directory as returned by getcwd().
1881 let &l:directory= getcwd()
1882 sil! let &l:swf = {a:vt}netrw_swfkeep
1883 setl directory=
1884 unlet {a:vt}netrw_swfkeep
1885 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001886 if !g:netrw_use_noswf
1887 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1888 sil! let &l:swf= {a:vt}netrw_swfkeep
1889 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001890 unlet {a:vt}netrw_swfkeep
1891 endif
1892 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001893 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001894 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1895 if exists("{a:vt}netrw_dirkeep")
1896 call s:NetrwLcd(dirkeep)
1897 unlet {a:vt}netrw_dirkeep
1898 endif
1899 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001900 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001901" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001902 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1903 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001904 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001905 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001906
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001907" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1908" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1909" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1910" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1911" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001912 " Moved the filetype detect here from NetrwGetFile() because remote files
1913 " were having their filetype detect-generated settings overwritten by
1914 " NetrwOptionRestore.
1915 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001916" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1917 filetype detect
1918" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001919 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001920" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001921" 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 +02001922" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001923endfun
1924
1925" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001926" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1927" but only when the options' value and the safe setting differ
1928" Doing this means that netrw will not come up as having changed a
1929" setting last when it really didn't actually change it.
1930"
1931" Called from s:NetrwOptionsSafe
1932" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1933fun! s:NetrwSetSafeSetting(setting,safesetting)
1934" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001935
Bram Moolenaar85850f32019-07-19 22:05:51 +02001936 if a:setting =~ '^&'
1937" call Decho("fyi: a:setting starts with &")
1938 exe "let settingval= ".a:setting
1939" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001940
Bram Moolenaar85850f32019-07-19 22:05:51 +02001941 if settingval != a:safesetting
1942" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1943 if type(a:safesetting) == 0
1944 exe "let ".a:setting."=".a:safesetting
1945 elseif type(a:safesetting) == 1
1946 exe "let ".a:setting."= '".a:safesetting."'"
1947 else
1948 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1949 endif
1950 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001951 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001952
Bram Moolenaar85850f32019-07-19 22:05:51 +02001953" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001954endfun
1955
1956" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001957" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1958" but only if the setting value differs from the associated keepvar.
1959" Doing this means that netrw will not come up as having changed a
1960" setting last when it really didn't actually change it.
1961"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001962" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001963" keepvars are set up by s:NetrwOptionsSave
1964fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001965""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001966
Bram Moolenaar85850f32019-07-19 22:05:51 +02001967 " typically called from s:NetrwOptionsRestore
1968 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1969 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001970 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001971 if exists(a:keepvar)
1972 exe "let keepvarval= ".a:keepvar
1973 exe "let setting= ".a:setting
1974
1975"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1976"" call Decho("fyi: keepvarval=".keepvarval)
1977"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1978
1979 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001980"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001981 if type(a:setting) == 0
1982 exe "let ".a:setting."= ".keepvarval
1983 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001984 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001985 else
1986 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1987 endif
1988 endif
1989
1990 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001991 endif
1992
Bram Moolenaar85850f32019-07-19 22:05:51 +02001993"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001994endfun
1995
1996" ---------------------------------------------------------------------
1997" NetrwStatusLine: {{{2
1998fun! NetrwStatusLine()
1999
2000" vvv NetrwStatusLine() debugging vvv
2001" let g:stlmsg=""
2002" if !exists("w:netrw_explore_bufnr")
2003" let g:stlmsg="!X<explore_bufnr>"
2004" elseif w:netrw_explore_bufnr != bufnr("%")
2005" let g:stlmsg="explore_bufnr!=".bufnr("%")
2006" endif
2007" if !exists("w:netrw_explore_line")
2008" let g:stlmsg=" !X<explore_line>"
2009" elseif w:netrw_explore_line != line(".")
2010" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2011" endif
2012" if !exists("w:netrw_explore_list")
2013" let g:stlmsg=" !X<explore_list>"
2014" endif
2015" ^^^ NetrwStatusLine() debugging ^^^
2016
2017 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")
2018 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002019 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002020 let &laststatus = s:netrw_users_ls
2021 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2022 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2023 return ""
2024 else
2025 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2026 endif
2027endfun
2028
Bram Moolenaar85850f32019-07-19 22:05:51 +02002029" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002030" Netrw Transfer Functions: {{{1
2031" ===============================
2032
Bram Moolenaar071d4272004-06-13 20:20:40 +00002033" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002034" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002035" mode: =0 read remote file and insert before current line
2036" =1 read remote file and insert after current line
2037" =2 replace with remote file
2038" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002039fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002040" 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 +00002041
Bram Moolenaar5c736222010-01-06 20:54:52 +01002042 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002043 call s:NetrwOptionsSave("w:")
2044 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002045 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002046 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2047 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2048 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002049" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002050
Bram Moolenaar5c736222010-01-06 20:54:52 +01002051 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002052 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002053 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002054 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002055 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056 elseif a:mode == 2 " replace with remote file
2057 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002058 elseif a:mode == 3 " skip read of file (leave as temporary)
2059 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002060 else
2061 exe a:mode
2062 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002063 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002064 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002065" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002066
Bram Moolenaar5c736222010-01-06 20:54:52 +01002067 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002068 let tmpfile= s:GetTempfile("")
2069 if tmpfile == ""
2070" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002071 return
2072 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002073
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002074 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002075
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002076 " attempt to repeat with previous host-file-etc
2077 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002078" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002079 let choice = b:netrw_lastfile
2080 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002081
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002082 else
2083 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002084" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002085
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002086 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002087 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002088 echomsg 'NetRead Usage:'
2089 echomsg ':Nread machine:path uses rcp'
2090 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2091 echomsg ':Nread "machine id password path" uses ftp'
2092 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2093 echomsg ':Nread fetch://machine/path uses fetch'
2094 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2095 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002096 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002097 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002098 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2099 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2100 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2101 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002102 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002103 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002104
Bram Moolenaar9964e462007-05-05 17:54:07 +00002105 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002106 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002107" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002108 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002109 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002110 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002111 else
2112 " case "... ... ..."
2113 let choice = strpart(choice,1,strlen(choice)-1)
2114 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002115
Bram Moolenaar9964e462007-05-05 17:54:07 +00002116 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002117 let wholechoice = wholechoice . " " . choice
2118 let ichoice = ichoice + 1
2119 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002120 if !exists("g:netrw_quiet")
2121 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2122 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002123" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002124 return
2125 endif
2126 let choice= a:{ichoice}
2127 endwhile
2128 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2129 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130 endif
2131 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002133" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002134 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002135
Bram Moolenaar5c736222010-01-06 20:54:52 +01002136 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002137 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002138 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002139" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002140 return
2141 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002142 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002143
Bram Moolenaar8d043172014-01-23 14:24:41 +01002144 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002145" 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 +02002146 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002147" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002148 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002149" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002150 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002151 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002152
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002153 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002154 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002155 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002156 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2157 echo "(netrw) Processing your read request..."
2158 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002159
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002160 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002161 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002162 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002163" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002164 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002165 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002166 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002167 " ER: the tmpfile is full path: rcp sees C:\... as host C
2168 if s:netrw_has_nt_rcp == 1
2169 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2170 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2171 else
2172 " Any way needed it machine contains a '.'
2173 let uid_machine = g:netrw_machine .'.'. $USERNAME
2174 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002175 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002176 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2177 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2178 else
2179 let uid_machine = g:netrw_machine
2180 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002181 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002182 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 +00002183 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002184 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002185
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002186 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002187 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002188 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002189" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002190 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002191 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002192 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002193 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002194 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002195" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002196 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002197 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002198" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002199 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002200 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002201" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002202 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002203 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 +00002204 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002206 endif
2207 " 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 +00002208 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002209 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002210 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002211 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002212 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002213 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002214 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002215 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002216 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2217 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002218 q!
2219 endif
2220 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002221 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002222 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002223
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002224 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002225 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2227 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002228" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002229 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002230 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002231 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002232 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002233 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002234 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002235" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002236 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002237 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002238" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002239 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002240
Bram Moolenaar97d62492012-11-15 21:28:22 +01002241 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002242 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002243 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002244" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002245 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002246 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002247 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002248" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002249 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002250 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002251" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002252 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002253 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002254
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002255 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002256 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002257" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002258 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002259 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002260 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002261" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002262 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002263 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002264" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002265
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002266 " perform ftp:
2267 " -i : turns off interactive prompting from ftp
2268 " -n unix : DON'T use <.netrc>, even though it exists
2269 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002270 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002271 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002272 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2273 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002274" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002275 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002276 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002277 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002278 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002279 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002280 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002281 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002282
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002283 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002284 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002285 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002286" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002287 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002288 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002289 else
2290 let useport= ""
2291 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002292 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2293 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002294 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002295 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2296 else
2297 let tmpfile_get = tmpfile
2298 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002299 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 +00002300 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002301 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002302
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002303 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002304 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002305 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002306" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002307 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002308 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002309 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002310 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002311" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002312 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002313 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002314
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002315 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2316 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002317" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002318 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002319 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 +00002320 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002321 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 +00002322 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002323 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002324
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002325 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002326 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002327" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002328 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2329 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002330" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2331" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2332 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 +00002333 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002334" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002335 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002336 endif
2337 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002338" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002339 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002340
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002341 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002342 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002343 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002344" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002345
Bram Moolenaar5c736222010-01-06 20:54:52 +01002346 if !executable(g:netrw_dav_cmd)
2347 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2348" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2349 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002350 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002351 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002352 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 +01002353 else
2354 " Construct execution string (four lines) which will be passed through filter
2355 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2356 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002357 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002358 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002359 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002360 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002361 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002362 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002363 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002364 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002365 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002366 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2367 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002368
Bram Moolenaar5c736222010-01-06 20:54:52 +01002369 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002370 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002371 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002372 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002373 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002374 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002375 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002376
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002377 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002378 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002379 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002380" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002381 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 +00002382 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002383 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002384
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002385 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002386 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002388 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002389" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002390 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002391 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002392 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002393 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002394" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002395 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002396 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002397 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002398 let netrw_option= "http"
2399 else
2400 let netrw_option= "ftp"
2401 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002402" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002403
Bram Moolenaar446cb832008-06-24 21:56:24 +00002404 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002405 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 +00002406 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002407 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 +00002408 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002409
Bram Moolenaar446cb832008-06-24 21:56:24 +00002410 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002411 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002412" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002413 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002414
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002415 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002416 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002417 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002418" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2419 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 +00002420 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002421 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002422
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002423 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002424 " NetRead: (file) NetRead Method #10 {{{3
2425 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002426" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2427 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002428 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2429 let b:netrw_lastfile = choice
2430
2431 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002432 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002433 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002434 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002435 endif
2436 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002437
Bram Moolenaar5c736222010-01-06 20:54:52 +01002438 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002439 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002440" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002441 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002442 unlet b:netrw_fname
2443 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002444 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 +01002445" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002446 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002447 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002448 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002449
Bram Moolenaar9964e462007-05-05 17:54:07 +00002450" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002451endfun
2452
2453" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002454" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002455fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002456" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002457
Bram Moolenaar5c736222010-01-06 20:54:52 +01002458 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002459 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002460 call s:NetrwOptionsSave("w:")
2461 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002462
Bram Moolenaar5c736222010-01-06 20:54:52 +01002463 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002464 let tmpfile= s:GetTempfile("")
2465 if tmpfile == ""
2466" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002467 return
2468 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002469
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002470 if a:0 == 0
2471 let ichoice = 0
2472 else
2473 let ichoice = 1
2474 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002475
Bram Moolenaar9964e462007-05-05 17:54:07 +00002476 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002477" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002478 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002479 " For binary writes, always write entire file.
2480 " (line numbers don't really make sense for that).
2481 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002482" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002483 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002484 elseif g:netrw_cygwin
2485 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002486 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002487" 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 +01002488 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002489 else
2490 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002491" 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 +01002492 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002493 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002494
Bram Moolenaar9964e462007-05-05 17:54:07 +00002495 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002496 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002497 " on the temporary file's name. Deletion of the temporary file during
2498 " cleanup then causes an error message.
2499 0file!
2500 endif
2501
Bram Moolenaar5c736222010-01-06 20:54:52 +01002502 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002503 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002504
Bram Moolenaar9964e462007-05-05 17:54:07 +00002505 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002506 " attempt to repeat with previous host-file-etc
2507 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002508" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002509 let choice = b:netrw_lastfile
2510 let ichoice= ichoice + 1
2511 else
2512 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002513
Bram Moolenaar8d043172014-01-23 14:24:41 +01002514 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002515 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002516 echomsg 'NetWrite Usage:"'
2517 echomsg ':Nwrite machine:path uses rcp'
2518 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2519 echomsg ':Nwrite "machine id password path" uses ftp'
2520 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2521 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2522 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2523 echomsg ':Nwrite rcp://machine/path uses rcp'
2524 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2525 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2526 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002527 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002528 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002529
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002530 elseif match(choice,"^\"") != -1
2531 if match(choice,"\"$") != -1
2532 " case "..."
2533 let choice=strpart(choice,1,strlen(choice)-2)
2534 else
2535 " case "... ... ..."
2536 let choice = strpart(choice,1,strlen(choice)-1)
2537 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002538
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002539 while match(choice,"\"$") == -1
2540 let wholechoice= wholechoice . " " . choice
2541 let ichoice = ichoice + 1
2542 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002543 if !exists("g:netrw_quiet")
2544 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2545 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002546" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002547 return
2548 endif
2549 let choice= a:{ichoice}
2550 endwhile
2551 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2552 endif
2553 endif
2554 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002555 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002556" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002557
Bram Moolenaar9964e462007-05-05 17:54:07 +00002558 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002559 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002560 if !exists("b:netrw_method") || b:netrw_method < 0
2561" call Dfunc("netrw#NetWrite : unsupported method")
2562 return
2563 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002564
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002565 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002566 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002567 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002568 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2569 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002570" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002571 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002572
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002573 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002574 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002575 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002576" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002577 if s:netrw_has_nt_rcp == 1
2578 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2579 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2580 else
2581 let uid_machine = g:netrw_machine .'.'. $USERNAME
2582 endif
2583 else
2584 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2585 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2586 else
2587 let uid_machine = g:netrw_machine
2588 endif
2589 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002590 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 +00002591 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002592
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002593 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002594 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002595 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002596" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002597 let netrw_fname = b:netrw_fname
2598
2599 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2600 let bhkeep = &l:bh
2601 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002602 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002603 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002604
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002605" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002606 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002607 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002608" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002609 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002610 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002612 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002613 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002614" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002616 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 +00002617 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002618" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2619 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 endif
2621 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2622 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002623 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002624 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002625 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002626 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002628
2629 " remove enew buffer (quietly)
2630 let filtbuf= bufnr("%")
2631 exe curbuf."b!"
2632 let &l:bh = bhkeep
2633 exe filtbuf."bw!"
2634
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002636
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002637 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002638 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002639 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002640 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002641" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002642 let netrw_fname = b:netrw_fname
2643 let bhkeep = &l:bh
2644
2645 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2646 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002647 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002648 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002649 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002650
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002651 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002652 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002653" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002654 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002655 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002656" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002657 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002658 if exists("g:netrw_uid") && g:netrw_uid != ""
2659 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002660 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002661" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002662 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002663 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002664 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002665" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002666 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002667 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002668" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002669 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002670 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002671 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002672" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002673 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002674 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002675" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002676 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002677 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002678" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002679 " save choice/id/password for future use
2680 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002681
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002682 " perform ftp:
2683 " -i : turns off interactive prompting from ftp
2684 " -n unix : DON'T use <.netrc>, even though it exists
2685 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002686 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002687 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002688 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2689 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002690 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002691 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002692 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002693 let mod=1
2694 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002695
2696 " remove enew buffer (quietly)
2697 let filtbuf= bufnr("%")
2698 exe curbuf."b!"
2699 let &l:bh= bhkeep
2700 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002701
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002702 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002703 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002704 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002705" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002706 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002707 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002708 else
2709 let useport= ""
2710 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002711 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 +00002712 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002713
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002714 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002715 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002716 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002717" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002718 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2719 if executable(curl)
2720 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002721 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 +01002722 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002723 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002724 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002725
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002726 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002727 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002728 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002729" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002730
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002731 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002732 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2733 let bhkeep = &l:bh
2734
2735 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2736 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002737 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002738 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002739
Bram Moolenaarff034192013-04-24 18:51:19 +02002740 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002741 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002742 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002743 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002744 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002745 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002746 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002747 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002748 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002749 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002750
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002751 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002752 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002753 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002754
2755 " remove enew buffer (quietly)
2756 let filtbuf= bufnr("%")
2757 exe curbuf."b!"
2758 let &l:bh = bhkeep
2759 exe filtbuf."bw!"
2760
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002761 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002762
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002763 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002764 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002765 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002766" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002767 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 +00002768 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002769
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002770 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002771 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002772 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002773" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002774 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2776 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2777 else
2778 let uid_machine = g:netrw_machine
2779 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002780
2781 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2782 let bhkeep = &l:bh
2783 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002784 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002785 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002786
Bram Moolenaarff034192013-04-24 18:51:19 +02002787 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002788 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002789" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002790 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002791 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002792 let filtbuf= bufnr("%")
2793 exe curbuf."b!"
2794 let &l:bh = bhkeep
2795 exe filtbuf."bw!"
2796 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002797
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002798 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002799 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002800 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002801 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002802 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002804 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002805
Bram Moolenaar5c736222010-01-06 20:54:52 +01002806 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002807" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002808 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002809" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002810 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002811 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002812 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002813
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002814 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002815 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002816 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002817" 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 +02002818 elseif !exists("leavemod")
2819 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002820" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002821 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002822" 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 +00002823 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002824
Bram Moolenaar9964e462007-05-05 17:54:07 +00002825" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002826endfun
2827
2828" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002829" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002830" uses NetRead to get a copy of the file into a temporarily file,
2831" then sources that file,
2832" then removes that file.
2833fun! netrw#NetSource(...)
2834" call Dfunc("netrw#NetSource() a:0=".a:0)
2835 if a:0 > 0 && a:1 == '?'
2836 " give help
2837 echomsg 'NetSource Usage:'
2838 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2839 echomsg ':Nsource fetch://machine/path uses fetch'
2840 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002841 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002842 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2843 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2844 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2845 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2846 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002847 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002848 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002849 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002850 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002851" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002852 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002853" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002854 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002855" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002856 if delete(s:netrw_tmpfile)
2857 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2858 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002859 unlet s:netrw_tmpfile
2860 else
2861 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2862 endif
2863 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002864 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002865 endif
2866" call Dret("netrw#NetSource")
2867endfun
2868
Bram Moolenaar8d043172014-01-23 14:24:41 +01002869" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002870" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2871" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002872fun! netrw#SetTreetop(iscmd,...)
2873" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2874" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002875
Bram Moolenaar85850f32019-07-19 22:05:51 +02002876 " iscmd==0: netrw#SetTreetop called using gn mapping
2877 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2878" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002879 " clear out the current tree
2880 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002881" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002882 let inittreetop= w:netrw_treetop
2883 unlet w:netrw_treetop
2884 endif
2885 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002886" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002887 unlet w:netrw_treedict
2888 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002889" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002890
Bram Moolenaar85850f32019-07-19 22:05:51 +02002891 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002892 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002893" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002894 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002895 if isdirectory(s:NetrwFile(a:1))
2896" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002897 let treedir = a:1
2898 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002899 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002900 let treedir = b:netrw_curdir."/".a:1
2901 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002902" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002903 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002904 " normally the cursor is left in the message window.
2905 " However, here this results in the directory being listed in the message window, which is not wanted.
2906 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002907 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002908 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002909 let treedir = "."
2910 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002911 endif
2912 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002913" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002914
2915 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002916 let islocal= expand("%") !~ '^\a\{3,}://'
2917" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002918
2919 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002920 if islocal
2921 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2922 else
2923 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2924 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002925
Bram Moolenaara6878372014-03-22 21:02:50 +01002926" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002927endfun
2928
Bram Moolenaar9964e462007-05-05 17:54:07 +00002929" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002930" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002931" readcmd == %r : replace buffer with newly read file
2932" == 0r : read file at top of buffer
2933" == r : read file after current line
2934" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002935fun! s:NetrwGetFile(readcmd, tfile, method)
2936" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002937
2938 " readcmd=='t': simply do nothing
2939 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002940" 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 +01002941" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002942 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002943 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002944
Bram Moolenaar9964e462007-05-05 17:54:07 +00002945 " get name of remote filename (ie. url and all)
2946 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002947" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002948
Bram Moolenaar9964e462007-05-05 17:54:07 +00002949 if exists("*NetReadFixup")
2950 " for the use of NetReadFixup (not otherwise used internally)
2951 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002952 endif
2953
Bram Moolenaar9964e462007-05-05 17:54:07 +00002954 if a:readcmd[0] == '%'
2955 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002956" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002957
2958 " rename the current buffer to the temp file (ie. tfile)
2959 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002960 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002961 else
2962 let tfile= a:tfile
2963 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002964 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002965
2966 " edit temporary file (ie. read the temporary file in)
2967 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002968" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002969 call zip#Browse(tfile)
2970 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002971" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.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\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002974" call Decho("handling remote gzip-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\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002977" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002978 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002979 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002981 call tar#Browse(tfile)
2982 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002983" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002984 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002985 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002986" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002987 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002988 endif
2989
2990 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002991 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002992
Bram Moolenaar71badf92023-04-22 22:40:14 +01002993 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002994 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002995 " Note that isk must not include a "/" for scripts.vim
2996 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002997" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2998" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002999" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003000" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3001 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003002 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003003 filetype detect
3004" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003005 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003006" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003007 let line1 = 1
3008 let line2 = line("$")
3009
Bram Moolenaar8d043172014-01-23 14:24:41 +01003010 elseif !&ma
3011 " 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 +01003012 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003013" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003014 return
3015
Bram Moolenaar9964e462007-05-05 17:54:07 +00003016 elseif s:FileReadable(a:tfile)
3017 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003018" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003019 let curline = line(".")
3020 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003021" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003022 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003023 let line1= curline + 1
3024 let line2= line("$") - lastline + 1
3025
3026 else
3027 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003028" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3029" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003030 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003031" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003032 return
3033 endif
3034
3035 " User-provided (ie. optional) fix-it-up command
3036 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003037" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003038 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003039" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003040" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003041 endif
3042
Bram Moolenaaradc21822011-04-01 18:03:16 +02003043 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003044 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003045 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003046 endif
3047
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003048" 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 +00003049
3050 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003051" redraw!
3052
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003053" 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 +00003054" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003055endfun
3056
Bram Moolenaar9964e462007-05-05 17:54:07 +00003057" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003058" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003059" Input:
3060" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3061" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003062" b:netrw_method= 1: rcp
3063" 2: ftp + <.netrc>
3064" 3: ftp + machine, id, password, and [path]filename
3065" 4: scp
3066" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003067" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003068" 7: rsync
3069" 8: fetch
3070" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003071" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003072" g:netrw_machine= hostname
3073" b:netrw_fname = filename
3074" g:netrw_port = optional port number (for ftp)
3075" g:netrw_choice = copy of input url (choice)
3076fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003077" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003078
Bram Moolenaar251e1912011-06-19 05:09:16 +02003079 " sanity check: choice should have at least three slashes in it
3080 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3081 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3082 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003083" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003084 return
3085 endif
3086
Bram Moolenaar5c736222010-01-06 20:54:52 +01003087 " record current g:netrw_machine, if any
3088 " curmachine used if protocol == ftp and no .netrc
3089 if exists("g:netrw_machine")
3090 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003091" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003092 else
3093 let curmachine= "N O T A HOST"
3094 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003095 if exists("g:netrw_port")
3096 let netrw_port= g:netrw_port
3097 endif
3098
3099 " insure that netrw_ftp_cmd starts off every method determination
3100 " with the current g:netrw_ftp_cmd
3101 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003102
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003103 " initialization
3104 let b:netrw_method = 0
3105 let g:netrw_machine = ""
3106 let b:netrw_fname = ""
3107 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003108 let g:netrw_choice = a:choice
3109
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003110 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003111 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003112 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3113 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003114 " rcpurm : rcp://[user@]host/filename Use rcp
3115 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003117 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003118 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003119 " rsyncurm : rsync://host[:port]/path Use rsync
3120 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3121 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003122 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003123 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3124 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003125 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3126 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003127 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003128 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003129 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003130 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003131 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003132 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003133 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003134 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003135
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003136" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003137 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003138 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003139 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003140" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003141 let b:netrw_method = 1
3142 let userid = substitute(a:choice,rcpurm,'\1',"")
3143 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3144 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003145 if userid != ""
3146 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003148
Bram Moolenaaradc21822011-04-01 18:03:16 +02003149 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003150 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003151" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003152 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003153 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3154 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3155 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003156
Bram Moolenaar15146672011-10-20 22:22:38 +02003157 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003158 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003159" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003160 let b:netrw_method = 5
3161 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3162 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003163 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003164
Bram Moolenaaradc21822011-04-01 18:03:16 +02003165 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003166 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003167" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003168 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003169 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003170 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3171 else
3172 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3173 endif
3174 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003175
Bram Moolenaaradc21822011-04-01 18:03:16 +02003176 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003177 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003178" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003179 let b:netrw_method = 7
3180 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3181 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003182
Bram Moolenaaradc21822011-04-01 18:03:16 +02003183 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003184 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003185" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003186 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003187 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3188 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3189 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003190" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003191 if userid != ""
3192 let g:netrw_uid= userid
3193 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003194
Bram Moolenaaradc21822011-04-01 18:03:16 +02003195 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003196 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003197 call NetUserPass("ftp:".g:netrw_machine)
3198 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003199 " if there's a change in hostname, require password re-entry
3200 unlet s:netrw_passwd
3201 endif
3202 if exists("netrw_port")
3203 unlet netrw_port
3204 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003205 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003206
Bram Moolenaar446cb832008-06-24 21:56:24 +00003207 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003208 let b:netrw_method = 3
3209 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003210 let host= substitute(g:netrw_machine,'\..*$','','')
3211 if exists("s:netrw_hup[host]")
3212 call NetUserPass("ftp:".host)
3213
Nir Lichtman1e34b952024-05-08 19:19:34 +02003214 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003215" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3216" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003217 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003218 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003219" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003220 endif
3221 let b:netrw_method= 2
3222 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003223" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003224 let b:netrw_method= 2
3225 else
3226 if !exists("g:netrw_uid") || g:netrw_uid == ""
3227 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003228 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003229 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003230 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003231 endif
3232 let b:netrw_method= 3
3233 endif
3234 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003235
Bram Moolenaaradc21822011-04-01 18:03:16 +02003236 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003237 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003238" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003239 let b:netrw_method = 8
3240 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3241 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3242 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3243 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003244
Bram Moolenaaradc21822011-04-01 18:03:16 +02003245 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003246 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003247" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003249 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3250 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003251 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003252 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003253 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003254
Bram Moolenaaradc21822011-04-01 18:03:16 +02003255 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003256 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003257" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003258 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003259 let b:netrw_method = 3
3260 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3261 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003262
Bram Moolenaar9964e462007-05-05 17:54:07 +00003263 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003264 let b:netrw_method = 2
3265 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3266 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3267 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003268
Bram Moolenaaradc21822011-04-01 18:03:16 +02003269 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003270 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003271" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003272 let b:netrw_method = 9
3273 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3274 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003275
Bram Moolenaaradc21822011-04-01 18:03:16 +02003276 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003277 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003278" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003279 let b:netrw_method = 1
3280 let userid = substitute(a:choice,rcphf,'\2',"")
3281 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3282 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003283" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3284" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3285" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3286" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003287 if userid != ""
3288 let g:netrw_uid= userid
3289 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003290
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003291 " Method#10: file://user@hostname/...path-to-file {{{3
3292 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003293" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003294 let b:netrw_method = 10
3295 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003296" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003297
Bram Moolenaaradc21822011-04-01 18:03:16 +02003298 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003299 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003300 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003301 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003302 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003303 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003304 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003305 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003306
Bram Moolenaar81695252004-12-29 20:58:21 +00003307 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003308 " remove any leading [:#] from port number
3309 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3310 elseif exists("netrw_port")
3311 " retain port number as implicit for subsequent ftp operations
3312 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003313 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003314
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003315" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3316" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3317" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3318" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003319" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003320" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003321" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003322" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003323" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003324" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003325" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003326" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003327endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328
Bram Moolenaar9964e462007-05-05 17:54:07 +00003329" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003330" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003331" Usage: :call NetUserPass() -- will prompt for userid and password
3332" :call NetUserPass("uid") -- will prompt for password
3333" :call NetUserPass("uid","password") -- sets global userid and password
3334" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3335" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336fun! NetUserPass(...)
3337
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003338" call Dfunc("NetUserPass() a:0=".a:0)
3339
3340 if !exists('s:netrw_hup')
3341 let s:netrw_hup= {}
3342 endif
3343
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003345 " case: no input arguments
3346
3347 " change host and username if not previously entered; get new password
3348 if !exists("g:netrw_machine")
3349 let g:netrw_machine= input('Enter hostname: ')
3350 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003352 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353 let g:netrw_uid= input('Enter username: ')
3354 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003355 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003356 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003357
3358 " set up hup database
3359 let host = substitute(g:netrw_machine,'\..*$','','')
3360 if !exists('s:netrw_hup[host]')
3361 let s:netrw_hup[host]= {}
3362 endif
3363 let s:netrw_hup[host].uid = g:netrw_uid
3364 let s:netrw_hup[host].passwd = s:netrw_passwd
3365
3366 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003367 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003368
3369 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003370 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003371 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003372" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003373 let host = substitute(a:1,'^ftp:','','')
3374 let host = substitute(host,'\..*','','')
3375 if exists("s:netrw_hup[host]")
3376 let g:netrw_uid = s:netrw_hup[host].uid
3377 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003378" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3379" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003380 else
3381 let g:netrw_uid = input("Enter UserId: ")
3382 let s:netrw_passwd = inputsecret("Enter Password: ")
3383 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003384
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003385 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003386 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003387" 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 +02003388 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003389 if g:netrw_machine =~ '[0-9.]\+'
3390 let host= g:netrw_machine
3391 else
3392 let host= substitute(g:netrw_machine,'\..*$','','')
3393 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003394 else
3395 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003396 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003397 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003398" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003399 if exists("g:netrw_passwd")
3400 " ask for password if one not previously entered
3401 let s:netrw_passwd= g:netrw_passwd
3402 else
3403 let s:netrw_passwd = inputsecret("Enter Password: ")
3404 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003405 endif
3406
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003407" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003408 if exists("host")
3409 if !exists('s:netrw_hup[host]')
3410 let s:netrw_hup[host]= {}
3411 endif
3412 let s:netrw_hup[host].uid = g:netrw_uid
3413 let s:netrw_hup[host].passwd = s:netrw_passwd
3414 endif
3415
3416 elseif a:0 == 2
3417 let g:netrw_uid = a:1
3418 let s:netrw_passwd = a:2
3419
3420 elseif a:0 == 3
3421 " enter hostname, user-id, and password into the hup dictionary
3422 let host = substitute(a:1,'^\a\+:','','')
3423 let host = substitute(host,'\..*$','','')
3424 if !exists('s:netrw_hup[host]')
3425 let s:netrw_hup[host]= {}
3426 endif
3427 let s:netrw_hup[host].uid = a:2
3428 let s:netrw_hup[host].passwd = a:3
3429 let g:netrw_uid = s:netrw_hup[host].uid
3430 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003431" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3432" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003434
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003435" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003436endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437
Bram Moolenaar85850f32019-07-19 22:05:51 +02003438" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003439" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003440" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003442" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003443" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3444fun! s:ExplorePatHls(pattern)
3445" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3446 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003447" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003448 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003449" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003450 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3451" call Dret("s:ExplorePatHls repat<".repat.">")
3452 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003453endfun
3454
3455" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003456" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003457" 0: (user: <mb>) bookmark current directory
3458" 1: (user: <gb>) change to the bookmarked directory
3459" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003460" 3: (browsing) records current directory history
3461" 4: (user: <u>) go up (previous) directory, using history
3462" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003463" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003464fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003465" 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 +02003466 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3467" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3468 return
3469 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003470
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003471 let ykeep = @@
3472 let curbufnr = bufnr("%")
3473
Bram Moolenaar9964e462007-05-05 17:54:07 +00003474 if a:chg == 0
3475 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003476" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003477 if exists("s:netrwmarkfilelist_{curbufnr}")
3478 call s:NetrwBookmark(0)
3479 echo "bookmarked marked files"
3480 else
3481 call s:MakeBookmark(a:curdir)
3482 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003483 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003484
KSR-Yasudaf4498252023-10-06 03:34:17 +09003485 try
3486 call s:NetrwBookHistSave()
3487 catch
3488 endtry
3489
Bram Moolenaar9964e462007-05-05 17:54:07 +00003490 elseif a:chg == 1
3491 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003492" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003493 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003494" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003495 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003496 else
3497 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3498 endif
3499
3500 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003501" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003502 let didwork= 0
3503 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003504" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003505 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003506" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003507 let cnt= 1
3508 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003509" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003510 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003511 let didwork = 1
3512 let cnt = cnt + 1
3513 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003514 endif
3515
3516 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003517 " Note: history is saved only when PerformListing is done;
3518 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3519 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003520 let first = 1
3521 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003522 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003523 while ( first || cnt != g:netrw_dirhistcnt )
3524" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003525 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003526" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003527 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003528 let didwork= 1
3529 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003530 let histcnt = histcnt + 1
3531 let first = 0
3532 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003533 if cnt < 0
3534 let cnt= cnt + g:netrw_dirhistmax
3535 endif
3536 endwhile
3537 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003538 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003539 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003540 if didwork
3541 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3542 endif
3543
3544 elseif a:chg == 3
3545 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003546" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003547 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 +02003548 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003549 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3550 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003551 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003552" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003553 endif
3554
3555 elseif a:chg == 4
3556 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003557" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003558 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003559 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3560 if g:netrw_dirhistcnt < 0
3561 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003562 endif
3563 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003564 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003565 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003566 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3567" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003568 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003569 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003570" call Decho("setl ma noro",'~'.expand("<slnum>"))
3571 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003572 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003573" call Decho("setl nomod",'~'.expand("<slnum>"))
3574" 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 +00003575 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003576" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3577 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003578 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003579 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003580 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003581 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003582 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003583 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003584 echo "Sorry, no predecessor directory exists yet"
3585 endif
3586
3587 elseif a:chg == 5
3588 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003589" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003590 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003591 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3592 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3593" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003594 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003595" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003596 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003597 sil! NetrwKeepj %d _
3598" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3599" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003600 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003601" 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 +02003602 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003603" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3604 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003605 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003606 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3607 if g:netrw_dirhistcnt < 0
3608 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003609 endif
3610 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003611 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003612 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003613 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003614 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003615 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003616
3617 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003618" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003619 if exists("s:netrwmarkfilelist_{curbufnr}")
3620 call s:NetrwBookmark(1)
3621 echo "removed marked files from bookmarks"
3622 else
3623 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003624 let iremove = v:count
3625 let dremove = g:netrw_bookmarklist[iremove - 1]
3626" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003627 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003628" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3629 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3630 echo "removed ".dremove." from g:netrw_bookmarklist"
3631" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003632 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003633" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003634
3635 try
3636 call s:NetrwBookHistSave()
3637 catch
3638 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003639 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003640 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003641 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003642 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003643" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003644endfun
3645
3646" ---------------------------------------------------------------------
3647" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003648" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003649" Sister function: s:NetrwBookHistSave()
3650fun! s:NetrwBookHistRead()
3651" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003652 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003653" 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 +02003654 return
3655 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003656 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003657
3658 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003659 if !exists("s:netrw_initbookhist")
3660 let home = s:NetrwHome()
3661 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003662 if filereadable(s:NetrwFile(savefile))
3663" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003664 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003665 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003666
3667 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003668 if g:netrw_dirhistmax > 0
3669 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003670 if filereadable(s:NetrwFile(savefile))
3671" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003672 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003673 endif
3674 let s:netrw_initbookhist= 1
3675 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003676 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003677 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003678
Bram Moolenaar97d62492012-11-15 21:28:22 +01003679 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003680" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3681" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003682" call Dret("s:NetrwBookHistRead")
3683endfun
3684
3685" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003686" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003687" Sister function: s:NetrwBookHistRead()
3688" I used to do this via viminfo but that appears to
3689" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003690" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3691" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003692" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003693fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003694" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003695 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003696" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003697 return
3698 endif
3699
Bram Moolenaar5c736222010-01-06 20:54:52 +01003700 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003701" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003702 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003703
3704 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003705 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003706" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003707 if g:netrw_use_noswf
3708 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3709 else
3710 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3711 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003712 setl nocin noai noci magic nospell nohid wig= noaw
3713 setl ma noro write
3714 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003715 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003716
Bram Moolenaar85850f32019-07-19 22:05:51 +02003717 " rename enew'd file: .netrwhist -- no attempt to merge
3718 " record dirhistmax and current dirhistcnt
3719 " save history
3720" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003721 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003722 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003723 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3724 if g:netrw_dirhistmax > 0
3725 let lastline = line("$")
3726 let cnt = g:netrw_dirhistcnt
3727 let first = 1
3728 while ( first || cnt != g:netrw_dirhistcnt )
3729 let lastline= lastline + 1
3730 if exists("g:netrw_dirhist_{cnt}")
3731 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3732" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3733 endif
3734 let first = 0
3735 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3736 if cnt < 0
3737 let cnt= cnt + g:netrw_dirhistmax
3738 endif
3739 endwhile
3740 exe "sil! w! ".savefile
3741" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3742 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003743
Bram Moolenaar85850f32019-07-19 22:05:51 +02003744 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003745 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003746 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003747" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003748 " merge and write .netrwbook
3749 let savefile= s:NetrwHome()."/.netrwbook"
3750
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003751 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003752 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003753 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003754 for bdm in booklist
3755 if index(g:netrw_bookmarklist,bdm) == -1
3756 call add(g:netrw_bookmarklist,bdm)
3757 endif
3758 endfor
3759 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003760 endif
3761
3762 " construct and save .netrwbook
3763 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003764 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003765" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003766 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003767
3768 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003769 let bgone= bufnr("%")
3770 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003771 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003772
3773" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003774endfun
3775
3776" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003777" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3778" list of the contents of a local or remote directory. It is assumed that the
3779" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3780" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003781" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003782fun! s:NetrwBrowse(islocal,dirname)
3783 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003784" 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 +02003785" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3786" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3787" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003788
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003789 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3790 " This is useful when one edits a local file, then :e ., then :Rex
3791 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3792 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003793" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003794 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003795
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003796 " s:NetrwBrowse : initialize history {{{3
3797 if !exists("s:netrw_initbookhist")
3798 NetrwKeepj call s:NetrwBookHistRead()
3799 endif
3800
3801 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003802 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003803 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003804" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003805 else
3806 let dirname= a:dirname
3807 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003808
Bram Moolenaar85850f32019-07-19 22:05:51 +02003809 " repoint t:netrw_lexbufnr if appropriate
3810 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3811" call Decho("set repointlexbufnr to true!")
3812 let repointlexbufnr= 1
3813 endif
3814
3815 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003816 if exists("s:netrw_skipbrowse")
3817 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003818" 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 +01003819" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003820 return
3821 endif
3822 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003823 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003824" call Dret("s:NetrwBrowse : missing shellescape()")
3825 return
3826 endif
3827 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003828 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003829" call Dret("s:NetrwBrowse : missing fnameescape()")
3830 return
3831 endif
3832
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003833 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003834 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003835
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003836 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003837 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3838 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3839" call Decho("clearing marked files",'~'.expand("<slnum>"))
3840 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3841 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003842 endif
3843
3844 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003845 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003846" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3847" 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 +02003848 if s:NetrwLcd(dirname)
3849" call Dret("s:NetrwBrowse : lcd failure")
3850 return
3851 endif
3852 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003853" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003854
Bram Moolenaar5c736222010-01-06 20:54:52 +01003855 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003856 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003857" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003858 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003859" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003860 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003861 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003862 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003863" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003864
3865 " remove any filetype indicator from end of dirname, except for the
3866 " "this is a directory" indicator (/).
3867 " There shouldn't be one of those here, anyway.
3868 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003869" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003870 call s:RemotePathAnalysis(dirname)
3871
3872 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3873 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003874 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003875 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003876" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003877 let b:netrw_curdir = dirname
3878 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003879 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003880 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3881 sil call netrw#NetRead(2,url)
3882 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003883" call Decho("url<".url.">",'~'.expand("<slnum>"))
3884" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3885" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003886 if s:path =~ '.bz2'
3887 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3888 elseif s:path =~ '.gz'
3889 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3890 elseif s:path =~ '.gz'
3891 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3892 else
3893 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3894 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003895 endif
3896
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003897 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003898 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003899 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003900" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003901 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003902" 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 +00003903
Bram Moolenaar446cb832008-06-24 21:56:24 +00003904" call Dret("s:NetrwBrowse : file<".s:fname.">")
3905 return
3906 endif
3907
Bram Moolenaaradc21822011-04-01 18:03:16 +02003908 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003909 call s:UseBufWinVars()
3910
3911 " set up some variables {{{3
3912 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003913 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003914 let s:last_sort_by = g:netrw_sort_by
3915
3916 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003917 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003918
Bram Moolenaar97d62492012-11-15 21:28:22 +01003919 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003920" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003921 let svpos = winsaveview()
3922" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003923 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003924
Bram Moolenaar446cb832008-06-24 21:56:24 +00003925 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003926 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3927 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3928" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3929" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3930 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3931 else
3932" " call Decho("2match none",'~'.expand("<slnum>"))
3933 2match none
3934 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003935 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003936 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003937 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003938" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003939 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003940" 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 +01003941" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003942 return
3943 endif
3944
3945 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003946" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003947 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003948 if b:netrw_curdir =~ '[/\\]$'
3949 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3950 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003951 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003952 let b:netrw_curdir= b:netrw_curdir."/"
3953 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003954 if b:netrw_curdir == ''
3955 if has("amiga")
3956 " On the Amiga, the empty string connotes the current directory
3957 let b:netrw_curdir= getcwd()
3958 else
3959 " under unix, when the root directory is encountered, the result
3960 " from the preceding substitute is an empty string.
3961 let b:netrw_curdir= '/'
3962 endif
3963 endif
3964 if !a:islocal && b:netrw_curdir !~ '/$'
3965 let b:netrw_curdir= b:netrw_curdir.'/'
3966 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003967" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003968
3969 " ------------
3970 " (local only) {{{3
3971 " ------------
3972 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003973" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003974
3975 " Set up ShellCmdPost handling. Append current buffer to browselist
3976 call s:LocalFastBrowser()
3977
3978 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3979 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003980" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3981" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003982 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003983 if s:NetrwLcd(b:netrw_curdir)
3984" call Dret("s:NetrwBrowse : lcd failure")
3985 return
3986 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003987 endif
3988 endif
3989
3990 " --------------------------------
3991 " remote handling: {{{3
3992 " --------------------------------
3993 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003994" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003995
Bram Moolenaar97d62492012-11-15 21:28:22 +01003996 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003997" 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 +02003998 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003999 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004000" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004001 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4002 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4003 if dirname !~ '/$'
4004 let dirname= dirname.'/'
4005 endif
4006 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004007" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004008 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004009 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004010" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004011 endif
4012
4013 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4014 if dirname !~ dirpat
4015 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004016 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004017 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004018 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004019" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004020 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004021" 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 +00004022" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4023 return
4024 endif
4025 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004026" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004027 endif " (additional remote handling)
4028
Bram Moolenaar85850f32019-07-19 22:05:51 +02004029 " -------------------------------
4030 " Perform Directory Listing: {{{3
4031 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004032 NetrwKeepj call s:NetrwMaps(a:islocal)
4033 NetrwKeepj call s:NetrwCommands(a:islocal)
4034 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004035
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004036 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004037 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004038" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4039
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004040 " If there is a rexposn: restore position with rexposn
4041 " Otherwise : set rexposn
4042 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004043" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4044 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4045 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4046 NetrwKeepj exe w:netrw_bannercnt
4047 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004048 else
4049 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4050 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004051 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004052 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004053" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004054 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004055 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004056
Bram Moolenaar85850f32019-07-19 22:05:51 +02004057 " repoint t:netrw_lexbufnr if appropriate
4058 if exists("repointlexbufnr")
4059 let t:netrw_lexbufnr= bufnr("%")
4060" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4061 endif
4062
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004063 " restore position
4064 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004065" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4066 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004067 endif
4068
Bram Moolenaara6878372014-03-22 21:02:50 +01004069 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004070 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4071 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004072" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4073" 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 +02004074" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004075 return
4076endfun
4077
4078" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004079" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4080" may not apply correctly; ie. netrw's idea of the current directory may
4081" differ from vim's. This function insures that netrw's idea of the current
4082" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004083" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004084fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004085" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4086" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4087" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4088" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4089" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004090
4091 " clean up any leading treedepthstring
4092 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4093 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004094" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004095 else
4096 let fname= a:fname
4097 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004098
4099 if g:netrw_keepdir
4100 " vim's idea of the current directory possibly may differ from netrw's
4101 if !exists("b:netrw_curdir")
4102 let b:netrw_curdir= getcwd()
4103 endif
4104
Nir Lichtman1e34b952024-05-08 19:19:34 +02004105 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004106 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004107 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004108 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004109" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004110 else
4111 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004112 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004113" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004114 endif
4115
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004116 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004117 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004118 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004119" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004120 else
4121 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004122 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004123" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004124 endif
4125 else
4126 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004127 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004128" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4129" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4130" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004131 endif
4132
Bram Moolenaar85850f32019-07-19 22:05:51 +02004133" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004134 return ret
4135endfun
4136
4137" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004138" s:NetrwFileInfo: supports qf (query for file information) {{{2
4139fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004140" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004141 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004142 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004143 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004144 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004145 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004146 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004147 let lsopt= "-lsadh --si"
4148 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004149" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004150 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004151
4152 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004153 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004154" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004155
Bram Moolenaara6878372014-03-22 21:02:50 +01004156 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004157 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004158" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004159
4160 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004161 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004162" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004163
Bram Moolenaar446cb832008-06-24 21:56:24 +00004164 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004165" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004166 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004167" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004168 endif
4169 else
4170 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004171" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4172 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004173 let fname= substitute(a:fname,".$","","")
4174 else
4175 let fname= a:fname
4176 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004177 let t = getftime(s:NetrwFile(fname))
4178 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004179 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004180 let sz= s:NetrwHumanReadable(sz)
4181 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004182 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4183" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004184 endif
4185 else
4186 echo "sorry, \"qf\" not supported yet for remote files"
4187 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004188 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004189" call Dret("s:NetrwFileInfo")
4190endfun
4191
4192" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004193" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4194fun! s:NetrwFullPath(filename)
4195" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4196 let filename= a:filename
4197 if filename !~ '^/'
4198 let filename= resolve(getcwd().'/'.filename)
4199 endif
4200 if filename != "/" && filename =~ '/$'
4201 let filename= substitute(filename,'/$','','')
4202 endif
4203" " call Dret("s:NetrwFullPath <".filename.">")
4204 return filename
4205endfun
4206
4207" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004208" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004209" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004210" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004211" 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 +00004212fun! s:NetrwGetBuffer(islocal,dirname)
4213" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004214" 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 +02004215" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4216" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004217 let dirname= a:dirname
4218
4219 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004220" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004221 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004222" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004223 let s:netrwbuf= {}
4224 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004225" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4226" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4227
4228 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4229 let bufnum = -1
4230
4231 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4232 if has_key(s:netrwbuf,"NetrwTreeListing")
4233 let bufnum= s:netrwbuf["NetrwTreeListing"]
4234 else
4235 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4236 endif
4237" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4238 if !bufexists(bufnum)
4239 call remove(s:netrwbuf,"NetrwTreeListing"])
4240 let bufnum= -1
4241 endif
4242 elseif bufnr("NetrwTreeListing") != -1
4243 let bufnum= bufnr("NetrwTreeListing")
4244" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4245 else
4246" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4247 let bufnum= -1
4248 endif
4249
4250 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004251 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004252" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004253 if !bufexists(bufnum)
4254 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4255 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004256 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004257
Bram Moolenaar446cb832008-06-24 21:56:24 +00004258 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004259" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004260 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004261 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004262" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4263
Bram Moolenaar71badf92023-04-22 22:40:14 +01004264 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004265 " IF the buffer already has the desired name
4266 " AND it is empty
4267 let curbuf = bufname("%")
4268 if curbuf == '.'
4269 let curbuf = getcwd()
4270 endif
4271" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004272" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004273" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4274" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4275" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4276" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4277 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004278" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4279 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004280 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004281" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004282 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004283 " 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 +00004284
4285 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004286 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004287" 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 +00004288 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004289" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004290 " name the buffer
4291 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4292 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004293" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004294 let w:netrw_treebufnr = bufnr("%")
4295 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004296 if g:netrw_use_noswf
4297 setl nobl bt=nofile noswf
4298 else
4299 setl nobl bt=nofile
4300 endif
4301 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4302 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4303 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4304 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004305" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004306 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004307 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004308 " enter the new buffer into the s:netrwbuf dictionary
4309 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4310" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4311" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004312 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004313" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004314
4315 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004316" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004317 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004318 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004319 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004320
4321 if &ft == "netrw"
4322" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4323 exe "sil! NetrwKeepj noswapfile b ".bufnum
4324" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004325 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004326" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4327 call s:NetrwEditBuf(bufnum)
4328" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004329 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004330" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004331 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004332 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004333 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004334
4335 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004336 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004337
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004338 if line("$") <= 1 && getline(1) == ""
4339 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004340 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004341" 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>"))
4342" 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 +01004343" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4344 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004345
Bram Moolenaar97d62492012-11-15 21:28:22 +01004346 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004347" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004348 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004349 sil NetrwKeepj %d _
4350" 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>"))
4351" 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 +01004352" 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 +00004353 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004354
Bram Moolenaar446cb832008-06-24 21:56:24 +00004355 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004356" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4357" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004358 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004359 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004360 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004361" 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>"))
4362" 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 +01004363" 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 +00004364 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004365
Bram Moolenaar446cb832008-06-24 21:56:24 +00004366 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004367" 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>"))
4368" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4369" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004370 return 1
4371 endif
4372 endif
4373
4374 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4375 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4376 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4377 " med 1 D H
4378 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004379" 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 +00004380 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004381 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004382 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004383
4384 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004385" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4386" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4387 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004388
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004389" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4390" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4391" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004392 return 0
4393endfun
4394
4395" ---------------------------------------------------------------------
4396" s:NetrwGetcwd: get the current directory. {{{2
4397" Change backslashes to forward slashes, if any.
4398" If doesc is true, escape certain troublesome characters
4399fun! s:NetrwGetcwd(doesc)
4400" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4401 let curdir= substitute(getcwd(),'\\','/','ge')
4402 if curdir !~ '[\/]$'
4403 let curdir= curdir.'/'
4404 endif
4405 if a:doesc
4406 let curdir= fnameescape(curdir)
4407 endif
4408" call Dret("NetrwGetcwd <".curdir.">")
4409 return curdir
4410endfun
4411
4412" ---------------------------------------------------------------------
4413" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4414fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004415" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4416" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4417 let keepsol= &l:sol
4418 setl nosol
4419
Bram Moolenaar446cb832008-06-24 21:56:24 +00004420 call s:UseBufWinVars()
4421
4422 " insure that w:netrw_liststyle is set up
4423 if !exists("w:netrw_liststyle")
4424 if exists("g:netrw_liststyle")
4425 let w:netrw_liststyle= g:netrw_liststyle
4426 else
4427 let w:netrw_liststyle= s:THINLIST
4428 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004429" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004430 endif
4431
4432 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4433 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004434" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004435 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004436 let dirname= "./"
4437 let curline= getline('.')
4438
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004439 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004440 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004441 let s:netrw_skipbrowse= 1
4442 echo 'Pressing "s" also works'
4443
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004444 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004445 let s:netrw_skipbrowse= 1
4446 echo 'Press "S" to edit sorting sequence'
4447
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004448 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004449 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004450 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004451
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004452 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004453 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004454 let s:netrw_skipbrowse= 1
4455 echo 'Pressing "a" also works'
4456
4457 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004458 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004459 endif
4460
4461 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004462" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004463 NetrwKeepj norm! 0
4464 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004465
4466 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004467" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004468 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004469 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4470
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004471 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004472" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004473 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004474 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004475
4476 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004477" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004478 let dirname= getline('.')
4479
4480 if !exists("b:netrw_cpf")
4481 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004482 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 +01004483 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004484" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004485 endif
4486
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004487" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004488 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004489" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4490" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004491 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004492 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004493 else
4494 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004495 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004496 endif
4497 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004498 let eofname= filestart + b:netrw_cpf + 1
4499 if eofname <= col("$")
4500 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004501 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004502 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004503 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004504 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004505 let dirname = @a
4506 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004507" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004509" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004510 endif
4511
4512 " symlinks are indicated by a trailing "@". Remove it before further processing.
4513 let dirname= substitute(dirname,"@$","","")
4514
4515 " executables are indicated by a trailing "*". Remove it before further processing.
4516 let dirname= substitute(dirname,"\*$","","")
4517
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004518 let &l:sol= keepsol
4519
Bram Moolenaar446cb832008-06-24 21:56:24 +00004520" call Dret("s:NetrwGetWord <".dirname.">")
4521 return dirname
4522endfun
4523
4524" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004525" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4526" g:netrw_bufsettings will be used after the listing is produced.
4527" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004528fun! s:NetrwListSettings(islocal)
4529" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004530" 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 +00004531 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004532" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4533 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4534 setl bt=nofile nobl ma nonu nowrap noro nornu
4535 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004536 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004537 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004538 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004539" call Dredir("ls!","s:NetrwListSettings")
4540" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004541 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004542 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004543 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004544 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004545 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004546 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004547 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004548" 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 +00004549" call Dret("s:NetrwListSettings")
4550endfun
4551
4552" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004553" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004554" islocal=0: remote browsing
4555" =1: local browsing
4556fun! s:NetrwListStyle(islocal)
4557" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004558
Bram Moolenaar97d62492012-11-15 21:28:22 +01004559 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004560 let fname = s:NetrwGetWord()
4561 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004562 let svpos = winsaveview()
4563" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004564 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004565" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4566" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4567" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004568
Bram Moolenaar85850f32019-07-19 22:05:51 +02004569 " repoint t:netrw_lexbufnr if appropriate
4570 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4571" call Decho("set repointlexbufnr to true!")
4572 let repointlexbufnr= 1
4573 endif
4574
Bram Moolenaar446cb832008-06-24 21:56:24 +00004575 if w:netrw_liststyle == s:THINLIST
4576 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004577" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004578 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4579
4580 elseif w:netrw_liststyle == s:LONGLIST
4581 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004582" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004583 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4584
4585 elseif w:netrw_liststyle == s:WIDELIST
4586 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004587" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004588 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4589
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004590 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004591" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004592 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4593
4594 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004595 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004596 let g:netrw_liststyle = s:THINLIST
4597 let w:netrw_liststyle = g:netrw_liststyle
4598 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4599 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004600 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004601" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004602
4603 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004604" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4605 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004606 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004607" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004608 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004609" 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 +00004610
4611 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004612" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004613 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004614 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004615
Bram Moolenaar85850f32019-07-19 22:05:51 +02004616 " repoint t:netrw_lexbufnr if appropriate
4617 if exists("repointlexbufnr")
4618 let t:netrw_lexbufnr= bufnr("%")
4619" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4620 endif
4621
Bram Moolenaar13600302014-05-22 18:26:40 +02004622 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004623" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4624 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004625 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004626
4627" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4628endfun
4629
4630" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004631" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4632fun! s:NetrwBannerCtrl(islocal)
4633" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4634
Bram Moolenaar97d62492012-11-15 21:28:22 +01004635 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004636 " toggle the banner (enable/suppress)
4637 let g:netrw_banner= !g:netrw_banner
4638
4639 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004640 let svpos= winsaveview()
4641" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004642 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4643
4644 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004645 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4646 let fname= s:NetrwGetWord()
4647 sil NetrwKeepj $
4648 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4649" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4650 if result <= 0 && exists("w:netrw_bannercnt")
4651 exe "NetrwKeepj ".w:netrw_bannercnt
4652 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004653 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004654 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004655" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4656endfun
4657
4658" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004659" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4660"
4661" No bang: enters files/directories into Netrw's bookmark system
4662" No argument and in netrw buffer:
4663" if there are marked files: bookmark marked files
4664" otherwise : bookmark file/directory under cursor
4665" No argument and not in netrw buffer: bookmarks current open file
4666" Has arguments: globs them individually and bookmarks them
4667"
4668" With bang: deletes files/directories from Netrw's bookmark system
4669fun! s:NetrwBookmark(del,...)
4670" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4671 if a:0 == 0
4672 if &ft == "netrw"
4673 let curbufnr = bufnr("%")
4674
4675 if exists("s:netrwmarkfilelist_{curbufnr}")
4676 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004677" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004678 let svpos = winsaveview()
4679" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004680 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004681 for fname in s:netrwmarkfilelist_{curbufnr}
4682 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4683 endfor
4684 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4685 call s:NetrwUnmarkList(curbufnr,curdir)
4686 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004687" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4688 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004689 else
4690 let fname= s:NetrwGetWord()
4691 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4692 endif
4693
4694 else
4695 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004696" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004697 let fname= expand("%")
4698 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4699 endif
4700
4701 else
4702 " bookmark specified files
4703 " attempts to infer if working remote or local
4704 " by deciding if the current file begins with an url
4705 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004706 let islocal= expand("%") !~ '^\a\{3,}://'
4707" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004708 let i = 1
4709 while i <= a:0
4710 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004711 if v:version > 704 || (v:version == 704 && has("patch656"))
4712 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004713 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004714 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004715 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004716 else
4717 let mbfiles= [a:{i}]
4718 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004719" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004720 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004721" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004722 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4723 endfor
4724 let i= i + 1
4725 endwhile
4726 endif
4727
4728 " update the menu
4729 call s:NetrwBookmarkMenu()
4730
4731" call Dret("s:NetrwBookmark")
4732endfun
4733
4734" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004735" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4736" .2.[cnt] for bookmarks, and
4737" .3.[cnt] for history
4738" (see s:NetrwMenu())
4739fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004740 if !exists("s:netrw_menucnt")
4741 return
4742 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004743" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004744
4745 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004746 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004747 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004748" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004749 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4750 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004751 endif
4752 if !exists("s:netrw_initbookhist")
4753 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004754 endif
4755
4756 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004757 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004758 let cnt= 1
4759 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004760" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004761 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004762
4763 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004764 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004765
4766 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004767 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 +01004768 let cnt= cnt + 1
4769 endfor
4770
4771 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004772
4773 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004774 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004775 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004776 let first = 1
4777 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004778 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004779 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004780 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004781 if exists("g:netrw_dirhist_{cnt}")
4782 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004783" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004784 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4785 endif
4786 let first = 0
4787 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4788 if cnt < 0
4789 let cnt= cnt + g:netrw_dirhistmax
4790 endif
4791 endwhile
4792 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004793
Bram Moolenaar9964e462007-05-05 17:54:07 +00004794 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004795" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004796endfun
4797
4798" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004799" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4800" directory and a new directory name. Also, if the
4801" "new directory name" is actually a file,
4802" NetrwBrowseChgDir() edits the file.
4803fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004804" 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 +01004805" 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 +00004806
Bram Moolenaar97d62492012-11-15 21:28:22 +01004807 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004808 if !exists("b:netrw_curdir")
4809 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4810 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004811 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004812" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4813" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004814" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004815" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004816 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004817 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004818" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004819
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004820 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004821" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004822 call s:SavePosn(s:netrw_posn)
4823 NetrwKeepj call s:NetrwOptionsSave("s:")
4824 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004825 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004826 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004827 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004828 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004829 endif
4830 let newdir = a:newdir
4831 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004832 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004833" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004834" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004835" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004836
4837 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004838" 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 +01004839 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004840" 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 +01004841 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004842 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004843" 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 +01004844 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004845" 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 +02004846 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004847 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004848 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004849 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004850" 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 +01004851 endif
4852 endif
4853" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004854" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004855 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004856
Bram Moolenaar446cb832008-06-24 21:56:24 +00004857 " set up o/s-dependent directory recognition pattern
4858 if has("amiga")
4859 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004860 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004861 let dirpat= '[\/]$'
4862 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004863" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004864
4865 if dirname !~ dirpat
4866 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004867 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004868 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004869" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870 endif
4871
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004872" 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 +01004873 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004874 " ------------------------------
4875 " NetrwBrowseChgDir: edit a file {{{3
4876 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004877" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004878
Bram Moolenaar97d62492012-11-15 21:28:22 +01004879 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004880 let s:rexposn_{bufnr("%")}= winsaveview()
4881" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004882" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4883" 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 +01004884
Bram Moolenaar446cb832008-06-24 21:56:24 +00004885 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004886" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4887" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004888" let newdir = s:NetrwTreePath(s:netrw_treetop)
4889" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004890 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004891 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4892" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4893 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004894 if dirname =~ '/$'
4895 let dirname= dirname.newdir
4896 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004897 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004898 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004899" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4900" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004902" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004904 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004905 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004906 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004907" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004908 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004909 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004910" 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 +02004911 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004912 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004913 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004914" " 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 +01004915 if type(g:netrw_browse_split) == 3
4916 " open file in server
4917 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004918" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004919 call s:NetrwServerEdit(a:islocal,dirname)
4920" call Dret("s:NetrwBrowseChgDir")
4921 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004922
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004923 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004924 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004925" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004926 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4927 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004928 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004929 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004930 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004931 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004932
Bram Moolenaar446cb832008-06-24 21:56:24 +00004933 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004934 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004935" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004936 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4937 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004938 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004939 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004940 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004941 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004942
Bram Moolenaar446cb832008-06-24 21:56:24 +00004943 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004944 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004945" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004946 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004947 if !exists("b:netrw_curdir")
4948 let b:netrw_curdir= getcwd()
4949 endif
4950 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004951
Bram Moolenaar446cb832008-06-24 21:56:24 +00004952 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004953 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004954" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004955 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004956 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004957" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004958 return
4959 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004960 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004961
Bram Moolenaar9964e462007-05-05 17:54:07 +00004962 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004963 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004964" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004965 call s:NetrwMenu(0)
4966 " optional change to window
4967 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004968" 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 +02004969 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004970 " if g:netrw_chgwin is set to one more than the last window, then
4971 " vertically split the last window to make that window available.
4972 let curwin= winnr()
4973 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4974 vs
4975 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004976 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004977 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004978 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004979 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004980 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004981
Bram Moolenaar9964e462007-05-05 17:54:07 +00004982 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004983
Bram Moolenaar446cb832008-06-24 21:56:24 +00004984 " the point where netrw actually edits the (local) file
4985 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004986 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004987 if !&mod
4988 " if e the new file would fail due to &mod, then don't change any of the flags
4989 let dolockout= 1
4990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004991 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004992" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004993 " some like c-^ to return to the last edited file
4994 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004995 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4996 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004997 call s:NetrwEditFile("e","",dirname)
4998" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004999 " COMBAK -- cuc cul related
5000 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005001 if &hidden || &bufhidden == "hide"
5002 " file came from vim's hidden storage. Don't "restore" options with it.
5003 let dorestore= 0
5004 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005005 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005006" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005007 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005008
5009 " handle g:Netrw_funcref -- call external-to-netrw functions
5010 " This code will handle g:Netrw_funcref as an individual function reference
5011 " or as a list of function references. It will ignore anything that's not
5012 " a function reference. See :help Funcref for information about function references.
5013 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005014" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005015 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005016" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005017 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005018 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005019" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005020 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005021 if type(Fncref) == 2
5022 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005023 endif
5024 endfor
5025 endif
5026 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005027 endif
5028
5029 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005030 " ----------------------------------------------------
5031 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5032 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005033" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005034 let dirname = newdir
5035 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005036 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005037 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005038
5039 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005040 " ---------------------------------------------
5041 " NetrwBrowseChgDir: refresh the directory list {{{3
5042 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005043" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005044 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005045 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005046
5047 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005048 " --------------------------------------
5049 " NetrwBrowseChgDir: go up one directory {{{3
5050 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005051" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005052
5053 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5054 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005055" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5056" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005057 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005058 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005059 endif
5060
5061 if has("amiga")
5062 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005063" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005064 if a:islocal
5065 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5066 let dirname= substitute(dirname,'/$','','')
5067 else
5068 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5069 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005070" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005071
Nir Lichtman1e34b952024-05-08 19:19:34 +02005072 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005073 " windows
5074 if a:islocal
5075 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5076 if dirname == ""
5077 let dirname= '/'
5078 endif
5079 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005080 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005081 endif
5082 if dirname =~ '^\a:$'
5083 let dirname= dirname.'/'
5084 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005085" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005086
Bram Moolenaar446cb832008-06-24 21:56:24 +00005087 else
5088 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005089" 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 +00005090 if a:islocal
5091 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5092 if dirname == ""
5093 let dirname= '/'
5094 endif
5095 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005096 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005097 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005098" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005099 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005100 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005101 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005102
5103 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005104 " --------------------------------------
5105 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5106 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005107" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005108 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5109" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005110 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005111 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005112" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5113 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005114 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005115 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005116" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005117 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005118 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005119" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005120
5121 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005122" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005123 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005124" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005125 let haskey= 1
5126 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005127" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005128 endif
5129
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005130 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005131" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005132 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005133 if has_key(w:netrw_treedict,treedir."/")
5134 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005135" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005136 let haskey = 1
5137 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005138" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005139 endif
5140 endif
5141
5142 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005143" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005144 if !haskey && treedir =~ '/$'
5145 let treedir= substitute(treedir,'/$','','')
5146 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005147" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005148 let haskey = 1
5149 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005150" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005151 endif
5152 endif
5153
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005154" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005155 if haskey
5156 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005157" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005158 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005159" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5160" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005161 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005162 else
5163 " go down one directory
5164 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005165" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5166" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005168 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005169" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005170 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171
5172 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005173 " ----------------------------------------
5174 " NetrwBrowseChgDir: Go down one directory {{{3
5175 " ----------------------------------------
5176 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005177" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005178 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005179 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005180 endif
5181
Bram Moolenaar97d62492012-11-15 21:28:22 +01005182 " --------------------------------------
5183 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5184 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005185 if dorestore
5186 " dorestore is zero'd when a local file was hidden or bufhidden;
5187 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005188" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005189 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005190" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005191" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005192 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005193 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005194" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005195 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005196" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5197" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005198 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005199" 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 +02005200 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005201" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5202" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005203 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005204" 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 +02005205 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005206 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005207 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005208 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005209
Bram Moolenaar446cb832008-06-24 21:56:24 +00005210" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5211 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005212endfun
5213
5214" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005215" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5216" for thin, long, and wide: cursor placed just after banner
5217" for tree, keeps cursor on current filename
5218fun! s:NetrwBrowseUpDir(islocal)
5219" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005220 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5221 " this test needed because occasionally this function seems to be incorrectly called
5222 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005223 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005224 " directories.
5225" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5226 return
5227 endif
5228
Bram Moolenaara6878372014-03-22 21:02:50 +01005229 norm! 0
5230 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005231" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005232 let curline= getline(".")
5233 let swwline= winline() - 1
5234 if exists("w:netrw_treetop")
5235 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005236 elseif exists("b:netrw_curdir")
5237 let w:netrw_treetop= b:netrw_curdir
5238 else
5239 let w:netrw_treetop= getcwd()
5240 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005241 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005242 let curfile = getline(".")
5243 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005244 if a:islocal
5245 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5246 else
5247 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5248 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005249" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5250" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5251 if w:netrw_treetop == '/'
5252 keepj call search('^\M'.curfile,"w")
5253 elseif curfile == '../'
5254 keepj call search('^\M'.curfile,"wb")
5255 else
5256" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5257 while 1
5258 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5259 let treepath= s:NetrwTreePath(w:netrw_treetop)
5260" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5261 if treepath == curpath
5262 break
5263 endif
5264 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005265 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005266
Bram Moolenaara6878372014-03-22 21:02:50 +01005267 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005268" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005269 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005270 if exists("b:netrw_curdir")
5271 let curdir= b:netrw_curdir
5272 else
5273 let curdir= expand(getcwd())
5274 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005275 if a:islocal
5276 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5277 else
5278 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5279 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005280 call s:RestorePosn(s:netrw_posn)
5281 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005282 let curdir= '\<'. escape(curdir, '~'). '/'
5283 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005284 endif
5285" call Dret("s:NetrwBrowseUpDir")
5286endfun
5287
5288" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005289" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005290" given filename; typically this means given their extension.
5291" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005292fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005293 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005294" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005295
Bram Moolenaar91359012019-11-30 17:57:03 +01005296 if a:remote == 0 && isdirectory(a:fname)
5297 " if its really just a local directory, then do a "gf" instead
5298" 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 +01005299" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5300 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005301" call Dret("netrw#BrowseX")
5302 return
5303 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5304 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5305" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5306" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5307" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5308" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5309 norm! gf
5310" call Dret("netrw#BrowseX")
5311 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005312 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005313" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005314
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005315 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5316 let remote = a:remote
5317 else
5318 let remote = 0
5319 endif
5320
Bram Moolenaar97d62492012-11-15 21:28:22 +01005321 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005322 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005323" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005324
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005325 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5326 let awkeep = &aw
5327 set noaw
5328
Bram Moolenaar5c736222010-01-06 20:54:52 +01005329 " special core dump handler
5330 if a:fname =~ '/core\(\.\d\+\)\=$'
5331 if exists("g:Netrw_corehandler")
5332 if type(g:Netrw_corehandler) == 2
5333 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005334" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005335 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005336 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005337 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005338" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005339 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005340 if type(Fncref) == 2
5341 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005342 endif
5343 endfor
5344 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005345" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005346 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005347 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005348 let &aw= awkeep
5349" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005350 return
5351 endif
5352 endif
5353
Bram Moolenaar446cb832008-06-24 21:56:24 +00005354 " set up the filename
5355 " (lower case the extension, make a local copy of a remote file)
5356 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005357 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005358 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005359 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005360 if exten =~ "[\\/]"
5361 let exten= ""
5362 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005363" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005364
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005365 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005366 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005367" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005368 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005369 call netrw#NetRead(3,a:fname)
5370 " attempt to rename tempfile
5371 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005372 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005373" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5374" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005375 if s:netrw_tmpfile != newname && newname != ""
5376 if rename(s:netrw_tmpfile,newname) == 0
5377 " renaming succeeded
5378" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5379 let fname= newname
5380 else
5381 " renaming failed
5382" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5383 let fname= s:netrw_tmpfile
5384 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005385 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005386 let fname= s:netrw_tmpfile
5387 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005388 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005389" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005390 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005391 " special ~ handler for local
5392 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005393" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5394 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005395 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005396 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005397" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5398" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005399
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005400 " set up redirection (avoids browser messages)
5401 " by default, g:netrw_suppress_gx_mesg is true
5402 if g:netrw_suppress_gx_mesg
5403 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005404 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005405 let redir= substitute(&srr,"%s","nul","")
5406 else
5407 let redir= substitute(&srr,"%s","/dev/null","")
5408 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005409 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005410 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005411 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005412 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005413 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005414 else
5415 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005416 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005417" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005418
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005419 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005420 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005421" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005422 if g:netrw_browsex_viewer =~ '\s'
5423 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5424 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5425 let oviewer = ''
5426 let cnt = 1
5427 while !executable(viewer) && viewer != oviewer
5428 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5429 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5430 let cnt = cnt + 1
5431 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005432" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005433 endwhile
5434 else
5435 let viewer = g:netrw_browsex_viewer
5436 let viewopt = ""
5437 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005438" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005439 endif
5440
5441 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005442" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005443 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005444" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005445 let ret= netrwFileHandlers#Invoke(exten,fname)
5446
5447 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005448" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005449 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005450 let ret= v:shell_error
5451
Nir Lichtman1e34b952024-05-08 19:19:34 +02005452 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005453" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005454 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005455 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005456 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005457 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005458 else
5459 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5460 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005461 let ret= v:shell_error
5462
Bram Moolenaar97d62492012-11-15 21:28:22 +01005463 elseif has("win32unix")
5464 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005465" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005466 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005467" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005468 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005469 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005470" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005471 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005472 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005473" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005474 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005475 else
5476 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5477 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005478 let ret= v:shell_error
5479
Bram Moolenaar85850f32019-07-19 22:05:51 +02005480 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005481" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5482 if a:fname =~ '^https\=://'
5483 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5484 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005485" call Decho("fname<".fname.">")
5486" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005487 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5488
5489 else
5490 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5491 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005492 let ret= v:shell_error
5493
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005494 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5495" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5496 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5497 let ret= v:shell_error
5498
5499 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5500" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5501 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5502 let ret= v:shell_error
5503
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005504 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005505" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005506 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005507 let ret= v:shell_error
5508
5509 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005510" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005511 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005512 let ret= v:shell_error
5513
5514 else
5515 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005516" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005517 let ret= netrwFileHandlers#Invoke(exten,fname)
5518 endif
5519
5520 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5521 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005522" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005523 let ret= netrwFileHandlers#Invoke(exten,fname)
5524 endif
5525
Bram Moolenaarc236c162008-07-13 17:41:49 +00005526 " restoring redraw! after external file handlers
5527 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005528
5529 " cleanup: remove temporary file,
5530 " delete current buffer if success with handler,
5531 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005532 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005533 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005534" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005535"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005536" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005537" endif
5538
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005539 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005540 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005541 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005542 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005543 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005544 if use_ctrlo
5545 exe "sil! NetrwKeepj norm! \<c-o>"
5546 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005547 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005548" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005549 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005550 let @@ = ykeep
5551 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005552
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005553" call Dret("netrw#BrowseX")
5554endfun
5555
5556" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005557" netrw#GX: gets word under cursor for gx support {{{2
5558" See also: netrw#BrowseXVis
5559" netrw#BrowseX
5560fun! netrw#GX()
5561" call Dfunc("netrw#GX()")
5562 if &ft == "netrw"
5563 let fname= s:NetrwGetWord()
5564 else
5565 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5566 endif
5567" call Dret("netrw#GX <".fname.">")
5568 return fname
5569endfun
5570
5571" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005572" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5573fun! netrw#BrowseXVis()
5574" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005575 let akeep = @a
5576 norm! gv"ay
5577 let gxfile= @a
5578 let @a = akeep
5579 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005580" call Dret("netrw#BrowseXVis")
5581endfun
5582
5583" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005584" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5585" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5586" to become an unlisted buffer, so in that case don't bwipe it.
5587fun! s:NetrwBufRename(newname)
5588" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5589" call Dredir("ls!","s:NetrwBufRename (before rename)")
5590 let oldbufname= bufname(bufnr("%"))
5591" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5592
5593 if oldbufname != a:newname
5594" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5595 let b:junk= 1
5596" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5597 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005598" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005599 let oldbufnr= bufnr(oldbufname)
5600" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5601" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5602 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5603" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5604 exe "bwipe! ".oldbufnr
5605" else " Decho
5606" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005607" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5608" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5609" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005610 endif
5611" call Dredir("ls!","s:NetrwBufRename (after rename)")
5612" else " Decho
5613" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5614 endif
5615
5616" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5617endfun
5618
5619" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005620" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005621fun! netrw#CheckIfRemote(...)
5622" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5623 if a:0 > 0
5624 let curfile= a:1
5625 else
5626 let curfile= expand("%")
5627 endif
5628" call Decho("curfile<".curfile.">")
5629 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005630" call Dret("netrw#CheckIfRemote 1")
5631 return 1
5632 else
5633" call Dret("netrw#CheckIfRemote 0")
5634 return 0
5635 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005636endfun
5637
5638" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005639" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5640fun! s:NetrwChgPerm(islocal,curdir)
5641" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005642 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005643 call inputsave()
5644 let newperm= input("Enter new permission: ")
5645 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005646 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5647 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5648" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005649 call system(chgperm)
5650 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005651 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005652 endif
5653 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005654 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005655 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005656 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005657" call Dret("s:NetrwChgPerm")
5658endfun
5659
5660" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005661" s:CheckIfKde: checks if kdeinit is running {{{2
5662" Returns 0: kdeinit not running
5663" 1: kdeinit is running
5664fun! s:CheckIfKde()
5665" call Dfunc("s:CheckIfKde()")
5666 " seems kde systems often have gnome-open due to dependencies, even though
5667 " gnome-open's subsidiary display tools are largely absent. Kde systems
5668 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5669 if !exists("s:haskdeinit")
5670 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005671 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005672 if v:shell_error
5673 let s:haskdeinit = 0
5674 endif
5675 else
5676 let s:haskdeinit= 0
5677 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005678" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005679 endif
5680
5681" call Dret("s:CheckIfKde ".s:haskdeinit)
5682 return s:haskdeinit
5683endfun
5684
5685" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005686" s:NetrwClearExplore: clear explore variables (if any) {{{2
5687fun! s:NetrwClearExplore()
5688" call Dfunc("s:NetrwClearExplore()")
5689 2match none
5690 if exists("s:explore_match") |unlet s:explore_match |endif
5691 if exists("s:explore_indx") |unlet s:explore_indx |endif
5692 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5693 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5694 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5695 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5696 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5697 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5698 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5699" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005700" call Dret("s:NetrwClearExplore")
5701endfun
5702
5703" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005704" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5705fun! s:NetrwEditBuf(bufnum)
5706" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5707 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5708" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5709 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5710 else
5711" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005712 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005713 endif
5714" call Dret("s:NetrwEditBuf")
5715endfun
5716
5717" ---------------------------------------------------------------------
5718" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5719" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5720fun! s:NetrwEditFile(cmd,opt,fname)
5721" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5722 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5723" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5724 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5725 else
5726" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5727 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5728 endif
5729" call Dret("s:NetrwEditFile")
5730endfun
5731
5732" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005733" s:NetrwExploreListUniq: {{{2
5734fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005735" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005736
5737 " this assumes that the list is already sorted
5738 let newexplist= []
5739 for member in a:explist
5740 if !exists("uniqmember") || member != uniqmember
5741 let uniqmember = member
5742 let newexplist = newexplist + [ member ]
5743 endif
5744 endfor
5745
Bram Moolenaar15146672011-10-20 22:22:38 +02005746" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005747 return newexplist
5748endfun
5749
5750" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005751" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5752fun! s:NetrwForceChgDir(islocal,newdir)
5753" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005754 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005755 if a:newdir !~ '/$'
5756 " ok, looks like force is needed to get directory-style treatment
5757 if a:newdir =~ '@$'
5758 let newdir= substitute(a:newdir,'@$','/','')
5759 elseif a:newdir =~ '[*=|\\]$'
5760 let newdir= substitute(a:newdir,'.$','/','')
5761 else
5762 let newdir= a:newdir.'/'
5763 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005764" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005765 else
5766 " should already be getting treatment as a directory
5767 let newdir= a:newdir
5768 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005769 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005770 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005771 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005772" call Dret("s:NetrwForceChgDir")
5773endfun
5774
5775" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005776" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005777" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5778" expr : this is the expression to follow the directory. Will use s:ComposePath()
5779" pare =1: remove the current directory from the resulting glob() filelist
5780" =0: leave the current directory in the resulting glob() filelist
5781fun! s:NetrwGlob(direntry,expr,pare)
5782" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005783 if netrw#CheckIfRemote()
5784 keepalt 1sp
5785 keepalt enew
5786 let keep_liststyle = w:netrw_liststyle
5787 let w:netrw_liststyle = s:THINLIST
5788 if s:NetrwRemoteListing() == 0
5789 keepj keepalt %s@/@@
5790 let filelist= getline(1,$)
5791 q!
5792 else
5793 " remote listing error -- leave treedict unchanged
5794 let filelist= w:netrw_treedict[a:direntry]
5795 endif
5796 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005797 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5798 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5799 if a:pare
5800 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5801 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005802 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005803 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5804 if a:pare
5805 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5806 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005807 endif
5808" call Dret("s:NetrwGlob ".string(filelist))
5809 return filelist
5810endfun
5811
5812" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005813" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5814fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005815" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005816 if a:newfile =~ '[/@*=|\\]$'
5817 let newfile= substitute(a:newfile,'.$','','')
5818 else
5819 let newfile= a:newfile
5820 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005821 if a:islocal
5822 call s:NetrwBrowseChgDir(a:islocal,newfile)
5823 else
5824 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5825 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005826" call Dret("s:NetrwForceFile")
5827endfun
5828
5829" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005830" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5831" and switches the hiding mode. The actual hiding is done by
5832" s:NetrwListHide().
5833" g:netrw_hide= 0: show all
5834" 1: show not-hidden files
5835" 2: show hidden files only
5836fun! s:NetrwHide(islocal)
5837" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005838 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005839 let svpos= winsaveview()
5840" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005841
5842 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005843" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5844" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005845
5846 " hide the files in the markfile list
5847 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005848" 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 +00005849 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5850 " remove fname from hiding list
5851 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5852 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5853 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005854" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005855 else
5856 " append fname to hiding list
5857 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5858 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5859 else
5860 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5861 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005862" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005863 endif
5864 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005865 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005866 let g:netrw_hide= 1
5867
5868 else
5869
5870 " switch between show-all/show-not-hidden/show-hidden
5871 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005872 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005873 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005874 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005875 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005876" call Dret("NetrwHide")
5877 return
5878 endif
5879 endif
5880
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005881 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005882" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5883 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005884 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005885" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005886endfun
5887
5888" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005889" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5890fun! s:NetrwHideEdit(islocal)
5891" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5892
5893 let ykeep= @@
5894 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005895 let svpos= winsaveview()
5896" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005897
5898 " get new hiding list from user
5899 call inputsave()
5900 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5901 call inputrestore()
5902 let g:netrw_list_hide= newhide
5903" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5904
5905 " refresh the listing
5906 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5907
5908 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005909" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5910 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005911 let @@= ykeep
5912
5913" call Dret("NetrwHideEdit")
5914endfun
5915
5916" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005917" s:NetrwHidden: invoked by "gh" {{{2
5918fun! s:NetrwHidden(islocal)
5919" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005920 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005921 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005922 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005923" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005924
5925 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005926 " remove .file pattern from hiding list
5927" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005928 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005929 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005930" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005931 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5932 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005933" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005934 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5935 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005936 if g:netrw_list_hide =~ '^,'
5937 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5938 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005939
5940 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005941 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005942" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5943 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005944 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005945" call Dret("s:NetrwHidden")
5946endfun
5947
5948" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005949" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5950fun! s:NetrwHome()
5951 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005952 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005953 else
5954 " go to vim plugin home
5955 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005956 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005957 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005958 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005959 let home= basehome."/.vim"
5960 break
5961 endif
5962 endfor
5963 if home == ""
5964 " just pick the first directory
5965 let home= substitute(&rtp,',.*$','','')
5966 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005967 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005968 let home= substitute(home,'/','\\','g')
5969 endif
5970 endif
5971 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005972 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005973" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005974 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005975" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005976 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005977 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005978" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005979 call mkdir(home)
5980 endif
5981 endif
5982 let g:netrw_home= home
5983 return home
5984endfun
5985
5986" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005987" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5988fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005989 if exists("s:netrwdrag")
5990 return
5991 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005992 if &ft != "netrw"
5993 return
5994 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005995" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005996
Bram Moolenaar97d62492012-11-15 21:28:22 +01005997 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005998 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005999 while getchar(0) != 0
6000 "clear the input stream
6001 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006002 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006003 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006004 let mouse_lnum = v:mouse_lnum
6005 let wlastline = line('w$')
6006 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006007" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6008" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006009 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6010 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006011 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006012" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6013 return
6014 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006015 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006016 " 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 +01006017 " without this test when its disabled.
6018 " 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 +01006019" 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 +01006020 if v:mouse_col > virtcol('.')
6021 let @@= ykeep
6022" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6023 return
6024 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006025
Bram Moolenaar446cb832008-06-24 21:56:24 +00006026 if a:islocal
6027 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006028 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006029 endif
6030 else
6031 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006032 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006033 endif
6034 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006035 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006036" call Dret("s:NetrwLeftmouse")
6037endfun
6038
6039" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006040" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6041fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006042 if &ft != "netrw"
6043 return
6044 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006045" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6046 call s:NetrwMarkFileTgt(a:islocal)
6047" call Dret("s:NetrwCLeftmouse")
6048endfun
6049
6050" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006051" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6052" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006053" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006054" a:islocal=2 : <c-r> used, remote
6055" a:islocal=3 : <c-r> used, local
6056fun! s:NetrwServerEdit(islocal,fname)
6057" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6058 let islocal = a:islocal%2 " =0: remote =1: local
6059 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006060" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006061
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006062 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006063 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006064 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006065" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006066 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006067 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006068 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6069 unlet s:netrw_browse_split_{winnr()}
6070 endif
6071 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6072" call Dret("s:NetrwServerEdit")
6073 return
6074 endif
6075
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006076" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006077 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006078" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006079
6080 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006081" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006082 let srvrname = g:netrw_browse_split[0]
6083 let tabnum = g:netrw_browse_split[1]
6084 let winnum = g:netrw_browse_split[2]
6085
6086 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006087" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006088
6089 if !ctrlr
6090 " user must have closed the server window and the user did not use <c-r>, but
6091 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006092" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006093 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006094 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006095 endif
6096 let g:netrw_browse_split= 0
6097 if exists("s:netrw_browse_split_".winnr())
6098 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6099 endif
6100 call s:NetrwBrowseChgDir(islocal,a:fname)
6101" call Dret("s:NetrwServerEdit")
6102 return
6103
6104 elseif has("win32") && executable("start")
6105 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006106" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006107 call system("start gvim --servername ".srvrname)
6108
6109 else
6110 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006111" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006112 call system("gvim --servername ".srvrname)
6113 endif
6114 endif
6115
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006116" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006117 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6118 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006119 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006120
6121 else
6122
6123 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6124
6125 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006126" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006127 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006128 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006129 endif
6130 let g:netrw_browse_split= 0
6131 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6132" call Dret("s:NetrwServerEdit")
6133 return
6134
6135 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006136" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006137 if has("win32") && executable("start")
6138 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006139" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006140 call system("start gvim --servername ".g:netrw_servername)
6141 else
6142 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006143" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006144 call system("gvim --servername ".g:netrw_servername)
6145 endif
6146 endif
6147 endif
6148
6149 while 1
6150 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006151" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6152 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006153 break
6154 catch /^Vim\%((\a\+)\)\=:E241/
6155 sleep 200m
6156 endtry
6157 endwhile
6158
6159 if exists("g:netrw_browse_split")
6160 if type(g:netrw_browse_split) != 3
6161 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6162 endif
6163 unlet g:netrw_browse_split
6164 endif
6165 let g:netrw_browse_split= [g:netrw_servername,1,1]
6166 endif
6167
6168 else
6169 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6170 endif
6171
6172" call Dret("s:NetrwServerEdit")
6173endfun
6174
6175" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006176" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6177fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006178 if &ft != "netrw"
6179 return
6180 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006181" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006182
Bram Moolenaar8d043172014-01-23 14:24:41 +01006183 let s:ngw= s:NetrwGetWord()
6184 call s:NetrwMarkFile(a:islocal,s:ngw)
6185
6186" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006187endfun
6188
6189" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006190" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6191" Used to mark multiple files.
6192fun! s:NetrwSLeftdrag(islocal)
6193" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6194 if !exists("s:netrwdrag")
6195 let s:netrwdrag = winnr()
6196 if a:islocal
6197 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006198 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006199 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006200 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006201 endif
6202 let ngw = s:NetrwGetWord()
6203 if !exists("s:ngw") || s:ngw != ngw
6204 call s:NetrwMarkFile(a:islocal,ngw)
6205 endif
6206 let s:ngw= ngw
6207" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6208endfun
6209
6210" ---------------------------------------------------------------------
6211" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6212fun! s:NetrwSLeftrelease(islocal)
6213" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6214 if exists("s:netrwdrag")
6215 nunmap <s-leftrelease>
6216 let ngw = s:NetrwGetWord()
6217 if !exists("s:ngw") || s:ngw != ngw
6218 call s:NetrwMarkFile(a:islocal,ngw)
6219 endif
6220 if exists("s:ngw")
6221 unlet s:ngw
6222 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006223 unlet s:netrwdrag
6224 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006225" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006226endfun
6227
6228" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006229" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6230" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006231fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006232" 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 +02006233" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006234 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006235
6236 " 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 +02006237 " How-it-works: take the hiding command, convert it into a range.
6238 " Duplicate characters don't matter.
6239 " Remove all such characters from the '/~@#...890' string.
6240 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006241" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006242 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006243 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006244" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006245
6246 while listhide != ""
6247 if listhide =~ ','
6248 let hide = substitute(listhide,',.*$','','e')
6249 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6250 else
6251 let hide = listhide
6252 let listhide = ""
6253 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006254" 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 +01006255 if g:netrw_sort_by =~ '^[ts]'
6256 if hide =~ '^\^'
6257" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6258 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6259 elseif hide =~ '^\\(\^'
6260 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6261 endif
6262" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6263 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006264
6265 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006266" 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 +00006267 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006268" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006269 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006270 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006271" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006272 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006273 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006274" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006275 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006276
Bram Moolenaar446cb832008-06-24 21:56:24 +00006277 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006278 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006279" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006280 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006281" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006282 endif
6283
Bram Moolenaaradc21822011-04-01 18:03:16 +02006284 " remove any blank lines that have somehow remained.
6285 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006286 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006287
Bram Moolenaar97d62492012-11-15 21:28:22 +01006288 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006289" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006290endfun
6291
6292" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006293" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006294" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006295fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006296" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006297
Bram Moolenaar97d62492012-11-15 21:28:22 +01006298 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006299 " get name of new directory from user. A bare <CR> will skip.
6300 " if its currently a directory, also request will be skipped, but with
6301 " a message.
6302 call inputsave()
6303 let newdirname= input("Please give directory name: ")
6304 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006305" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306
6307 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006308 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006309" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006310 return
6311 endif
6312
6313 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006314" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006315
6316 " Local mkdir:
6317 " sanity checks
6318 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006319" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6320 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006321 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006322 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006323 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006324 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006325" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006326 return
6327 endif
6328 if s:FileReadable(fullnewdir)
6329 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006330 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006331 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006332 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006333" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006334 return
6335 endif
6336
6337 " requested new local directory is neither a pre-existing file or
6338 " directory, so make it!
6339 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006340 if has("unix")
6341 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6342 else
6343 call mkdir(fullnewdir,"p")
6344 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006345 else
6346 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006347 if s:NetrwLcd(b:netrw_curdir)
6348" call Dret("s:NetrwMakeDir : lcd failure")
6349 return
6350 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006351" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006352 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006353 if v:shell_error != 0
6354 let @@= ykeep
6355 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 +01006356" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006357 return
6358 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006359 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006360" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006361 if s:NetrwLcd(netrw_origdir)
6362" call Dret("s:NetrwBrowse : lcd failure")
6363 return
6364 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006365 endif
6366 endif
6367
6368 if v:shell_error == 0
6369 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006370" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006371 let svpos= winsaveview()
6372" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006373 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006374" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6375 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006376 elseif !exists("g:netrw_quiet")
6377 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6378 endif
6379" redraw!
6380
6381 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006382 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006383" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006384 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6385 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006386 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006387 if v:shell_error == 0
6388 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006389 let svpos= winsaveview()
6390" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006391 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006392" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6393 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006394 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006395 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006396 endif
6397" redraw!
6398
6399 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006400 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006401 let svpos= winsaveview()
6402" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006403" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006404 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006405" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006406 let remotepath= b:netrw_fname
6407 else
6408 let remotepath= ""
6409 endif
6410 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006411 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006412" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6413 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006414
Bram Moolenaar446cb832008-06-24 21:56:24 +00006415 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006416 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006417 let svpos= winsaveview()
6418" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006419" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006420 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006421" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006422 let remotepath= b:netrw_fname
6423 else
6424 let remotepath= ""
6425 endif
6426 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006427 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006428" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6429 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006430 endif
6431
Bram Moolenaar97d62492012-11-15 21:28:22 +01006432 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006433" call Dret("s:NetrwMakeDir")
6434endfun
6435
6436" ---------------------------------------------------------------------
6437" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6438fun! s:TreeSqueezeDir(islocal)
6439" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6440 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6441 " its a tree-listing style
6442 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006443 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006444 let depth = strchars(substitute(curdepth,' ','','g'))
6445 let srch = -1
6446" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6447" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006448" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006449" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6450 if depth >= 2
6451 NetrwKeepj norm! 0
6452 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6453 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6454" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6455" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6456 elseif depth == 1
6457 NetrwKeepj norm! 0
6458 let treedepthchr= substitute(s:treedepthstring,' ','','')
6459 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6460" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6461 endif
6462 if srch > 0
6463" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6464 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6465 exe srch
6466 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006467 endif
6468" call Dret("s:TreeSqueezeDir")
6469endfun
6470
6471" ---------------------------------------------------------------------
6472" s:NetrwMaps: {{{2
6473fun! s:NetrwMaps(islocal)
6474" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6475
Bram Moolenaar85850f32019-07-19 22:05:51 +02006476 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006477 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006478" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006479 if !hasmapto("<Plug>NetrwReturn")
6480 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006481" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006482 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6483 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006484" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006485 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6486 endif
6487 endif
6488 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006489" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006490 endif
6491
Bram Moolenaar85850f32019-07-19 22:05:51 +02006492 " generate default <Plug> maps {{{3
6493 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006494 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006495 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6496 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6497 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6498 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6499 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6500 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6501 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6502 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6503 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6504 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6505" ---------------------------------------------------------------------
6506" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6507" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6508" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6509" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6510" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6511" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6512" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6513" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6514" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6515" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6516" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6517" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6518" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6519" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6520" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6521" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6522" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6523" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6524" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6525" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6526" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6527" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6528" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6529" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6530" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6531" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6532" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6533" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6534" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6535" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6536" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6537" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6538" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6539" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6540" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6541" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6542" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6543" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6544" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6545" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6546" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6547" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6548" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6549" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6550" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6551" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6552" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6553
Bram Moolenaara6878372014-03-22 21:02:50 +01006554 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006555" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006556 " local normal-mode maps {{{3
6557 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6558 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6559 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6560 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6561 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6562 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6563 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6564 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6565 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6566 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6567 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6568" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006569 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6570 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6571 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006572 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006573 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006574 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6575 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6576 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6577 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006578 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6579 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6580 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6581 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6582 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6583 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6584 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6585 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6586 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6587 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6588 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6589 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6590 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006591 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006592 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006593 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6594 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6595 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6596 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6597 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006598 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006599 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006600 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6601 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006602 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6603 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6604 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006605 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006606 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006607 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6608 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006609 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006610 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006611 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6612 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6613 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006614 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6615 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006616
6617 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 +01006618 if !hasmapto('<Plug>NetrwHideEdit')
6619 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006620 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006621 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006622 if !hasmapto('<Plug>NetrwRefresh')
6623 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006624 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006625 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 +01006626 if s:didstarstar || !mapcheck("<s-down>","n")
6627 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006628 endif
6629 if s:didstarstar || !mapcheck("<s-up>","n")
6630 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006631 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006632 if !hasmapto('<Plug>NetrwTreeSqueeze')
6633 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006634 endif
6635 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006636 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6637 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006638 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6639 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6640 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6641 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6642 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6643 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6644 imap <buffer> <leftmouse> <Plug>ILeftmouse
6645 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006646 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6647 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6648 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6649 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6650 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006651 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006652 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6653 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006654 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006655 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6656 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6657 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6658 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6659 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6660 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6661 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006662 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6663
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006664 " support user-specified maps
6665 call netrw#UserMaps(1)
6666
Bram Moolenaar85850f32019-07-19 22:05:51 +02006667 else
6668 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006669" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006670 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006671 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6672 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6673 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6674 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6675 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6676 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6677 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6678 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6679 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6680 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6681 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6682" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006683 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6684 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6685 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6686 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6687 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6688 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6689 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6690 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006691 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006692 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006693 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6694 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6695 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6696 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6697 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6698 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6699 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6700 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6701 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6702 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6703 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006704 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006705 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006706 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6707 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6708 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6709 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6710 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006711 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6712 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6713 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6714 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006715 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006716 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6717 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006718 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006719 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 +01006720 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6721 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6722 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6723 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6724 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6725 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6726 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6727 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6728 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006729 if !hasmapto('<Plug>NetrwHideEdit')
6730 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006731 endif
6732 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6733 if !hasmapto('<Plug>NetrwRefresh')
6734 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006735 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006736 if !hasmapto('<Plug>NetrwTreeSqueeze')
6737 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006738 endif
6739 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006740
6741 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006742 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006743
6744 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6745 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006746 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006747 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006748 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006749 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006750 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006751 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006752 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006753 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006754 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006755 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006756 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6757 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6758 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006759 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006760 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006761 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6762 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006763 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006764 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6765 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6766 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6767 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6768 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6769 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6770 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006771 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006772
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006773 " support user-specified maps
6774 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006775 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006776
6777" call Dret("s:NetrwMaps")
6778endfun
6779
6780" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006781" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006782" If -buffer, the command is only available from within netrw buffers
6783" Otherwise, the command is available from any window, so long as netrw
6784" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006785fun! s:NetrwCommands(islocal)
6786" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6787
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006788 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6789 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006790 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 +01006791 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006792 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006793 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006794 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006795 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006796 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006797
6798" call Dret("s:NetrwCommands")
6799endfun
6800
6801" ---------------------------------------------------------------------
6802" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6803" glob()ing only works with local files
6804fun! s:NetrwMarkFiles(islocal,...)
6805" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006806 let curdir = s:NetrwGetCurdir(a:islocal)
6807 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006808 while i <= a:0
6809 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006810 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006811 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006812 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006813 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006814 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006815 else
6816 let mffiles= [a:{i}]
6817 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006818" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006819 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006820" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006821 call s:NetrwMarkFile(a:islocal,mffile)
6822 endfor
6823 let i= i + 1
6824 endwhile
6825" call Dret("s:NetrwMarkFiles")
6826endfun
6827
6828" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006829" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006830fun! s:NetrwMarkTarget(...)
6831" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6832 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006833 let curdir = s:NetrwGetCurdir(1)
6834 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006835 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006836 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6837 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006838 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006839" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006840 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006841 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6842 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006843 let svpos = winsaveview()
6844" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006845 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006846" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6847 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006848" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006849endfun
6850
6851" ---------------------------------------------------------------------
6852" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6853" mark and unmark files. If a markfile list exists,
6854" then the rename and delete functions will use it instead
6855" of whatever may happen to be under the cursor at that
6856" moment. When the mouse and gui are available,
6857" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006858"
6859" Creates two lists
6860" s:netrwmarkfilelist -- holds complete paths to all marked files
6861" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6862"
6863" Creates a marked file match string
6864" s:netrwmarfilemtch_# -- used with 2match to display marked files
6865"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006866" Creates a buffer version of islocal
6867" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006868fun! s:NetrwMarkFile(islocal,fname)
6869" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006870" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006871
6872 " sanity check
6873 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006874" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006875 return
6876 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006877 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006878
Bram Moolenaar97d62492012-11-15 21:28:22 +01006879 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006880 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006881 if a:fname =~ '^\a'
6882 let leader= '\<'
6883 else
6884 let leader= ''
6885 endif
6886 if a:fname =~ '\a$'
6887 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6888 else
6889 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6890 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006891
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006892 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006893 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006894" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6895" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6896" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006897 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006898
6899 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006900 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006901" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006902 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006903 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006904
6905 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006906 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006907" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006908 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6909 if s:netrwmarkfilelist_{curbufnr} == []
6910 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006911" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006912 call s:NetrwUnmarkList(curbufnr,curdir)
6913 else
6914 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006915" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006916 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006917 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006918 for fname in s:netrwmarkfilelist_{curbufnr}
6919 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006920 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006921 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006922 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006923 endif
6924 let first= 0
6925 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006926" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006927 endif
6928 endif
6929
6930 else
6931 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006932" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006933
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006934" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006935 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006936 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6937" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006938
6939 " build initial markfile matching pattern
6940 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006941 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006943 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006944 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006945" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006946 endif
6947
6948 " handle global markfilelist
6949 if exists("s:netrwmarkfilelist")
6950 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6951 if index(s:netrwmarkfilelist,dname) == -1
6952 " append new filename to global markfilelist
6953 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006954" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006955 else
6956 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006957" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6958" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006959 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006960" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006961 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006962" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006963 unlet s:netrwmarkfilelist
6964 endif
6965 endif
6966 else
6967 " initialize new global-directory markfilelist
6968 let s:netrwmarkfilelist= []
6969 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006970" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006971 endif
6972
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006973 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006974 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6975 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6976" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6977 if exists("g:did_drchip_netrwlist_syntax")
6978 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6979 endif
6980 else
6981" " call Decho("2match none",'~'.expand("<slnum>"))
6982 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006983 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006984 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006985 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006986" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6987" 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 +00006988endfun
6989
6990" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006991" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6992" mA: move the argument list to marked file list (tomflist=1)
6993" Uses the global marked file list
6994fun! s:NetrwMarkFileArgList(islocal,tomflist)
6995" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6996
6997 let svpos = winsaveview()
6998" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6999 let curdir = s:NetrwGetCurdir(a:islocal)
7000 let curbufnr = bufnr("%")
7001
7002 if a:tomflist
7003 " mA: move argument list to marked file list
7004 while argc()
7005 let fname= argv(0)
7006" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7007 exe "argdel ".fnameescape(fname)
7008 call s:NetrwMarkFile(a:islocal,fname)
7009 endwhile
7010
7011 else
7012 " ma: move marked file list to argument list
7013 if exists("s:netrwmarkfilelist")
7014
7015 " for every filename in the marked list
7016 for fname in s:netrwmarkfilelist
7017" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7018 exe "argadd ".fnameescape(fname)
7019 endfor " for every file in the marked list
7020
7021 " unmark list and refresh
7022 call s:NetrwUnmarkList(curbufnr,curdir)
7023 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7024" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7025 NetrwKeepj call winrestview(svpos)
7026 endif
7027 endif
7028
7029" call Dret("s:NetrwMarkFileArgList")
7030endfun
7031
7032" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007033" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7034" compress/decompress files using the programs
7035" in g:netrw_compress and g:netrw_uncompress,
7036" using g:netrw_compress_suffix to know which to
7037" do. By default:
7038" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007039" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007040fun! s:NetrwMarkFileCompress(islocal)
7041" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007042 let svpos = winsaveview()
7043" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007044 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007045 let curbufnr = bufnr("%")
7046
Bram Moolenaarff034192013-04-24 18:51:19 +02007047 " sanity check
7048 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007049 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007050" call Dret("s:NetrwMarkFileCompress")
7051 return
7052 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007053" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007054
Bram Moolenaar446cb832008-06-24 21:56:24 +00007055 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007056
7057 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007058 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007059 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007060" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007061 if exists("g:netrw_decompress['".sfx."']")
7062 " fname has a suffix indicating that its compressed; apply associated decompression routine
7063 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007064" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007065 let exe= netrw#WinPath(exe)
7066 if a:islocal
7067 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007068 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007069 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007070 call system(exe." ".fname)
7071 if v:shell_error
7072 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007073 endif
7074 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007075 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7076 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007077 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007078
Bram Moolenaarff034192013-04-24 18:51:19 +02007079 endif
7080 unlet sfx
7081
Bram Moolenaar446cb832008-06-24 21:56:24 +00007082 if exists("exe")
7083 unlet exe
7084 elseif a:islocal
7085 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007086 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007087 if v:shell_error
7088 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7089 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007090 else
7091 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007092 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007093 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007094 endfor " for every file in the marked list
7095
Bram Moolenaar446cb832008-06-24 21:56:24 +00007096 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007097 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007098" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7099 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007100 endif
7101" call Dret("s:NetrwMarkFileCompress")
7102endfun
7103
7104" ---------------------------------------------------------------------
7105" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7106" If no marked files, then set up directory as the
7107" target. Currently does not support copying entire
7108" directories. Uses the local-buffer marked file list.
7109" Returns 1=success (used by NetrwMarkFileMove())
7110" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007111fun! s:NetrwMarkFileCopy(islocal,...)
7112" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7113
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007114 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007115 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007116 if b:netrw_curdir !~ '/$'
7117 if !exists("b:netrw_curdir")
7118 let b:netrw_curdir= curdir
7119 endif
7120 let b:netrw_curdir= b:netrw_curdir."/"
7121 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007122
Bram Moolenaarff034192013-04-24 18:51:19 +02007123 " sanity check
7124 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007125 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007126" call Dret("s:NetrwMarkFileCopy")
7127 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007128 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007129" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007130
Bram Moolenaar446cb832008-06-24 21:56:24 +00007131 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007132 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007133" call Dret("s:NetrwMarkFileCopy 0")
7134 return 0
7135 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007136" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007137
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007138 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007139 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007140" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007141 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007142 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7143" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7144 return
7145 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007146
7147 " copy marked files while within the same directory (ie. allow renaming)
7148 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7149 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7150 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007151" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007152 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007153 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7154 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007155" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007156 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007157 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007158 let oldname = a:1
7159 else
7160 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007161" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007162 let s:recursive= 1
7163 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7164 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7165 if ret == 0
7166 break
7167 endif
7168 endfor
7169 unlet s:recursive
7170 call s:NetrwUnmarkList(curbufnr,curdir)
7171" call Dret("s:NetrwMarkFileCopy ".ret)
7172 return ret
7173 endif
7174
7175 call inputsave()
7176 let newname= input("Copy ".oldname." to : ",oldname,"file")
7177 call inputrestore()
7178 if newname == ""
7179" call Dret("s:NetrwMarkFileCopy 0")
7180 return 0
7181 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007182 let args= s:ShellEscape(oldname)
7183 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007184 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007185 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7186 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007187 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007188 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007189 let args= substitute(args,'/','\\','g')
7190 let tgt = substitute(tgt, '/','\\','g')
7191 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007192 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7193 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7194 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7195 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7196" call Decho("args <".args.">",'~'.expand("<slnum>"))
7197" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007198 if isdirectory(s:NetrwFile(args))
7199" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007200 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007201" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007202 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007203 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7204 " contents to a target. One must append the source directory name to the target to get xcopy to
7205 " do the right thing.
7206 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007207" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007208 endif
7209 else
7210 let copycmd= g:netrw_localcopycmd
7211 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007212 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007213 let copycmd = substitute(copycmd,'\s.*$','','')
7214 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007215 let copycmd = netrw#WinPath(copycmd).copycmdargs
7216 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007217 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007218 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007219" call Decho("args <".args.">",'~'.expand("<slnum>"))
7220" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7221" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7222" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007223 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007224 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007225 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007226 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 +01007227 else
7228 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7229 endif
7230" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007231 return 0
7232 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007233
7234 elseif a:islocal && !s:netrwmftgt_islocal
7235 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007236" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007237 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007238
7239 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007240 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007241" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007242 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007243
7244 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007245 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007246" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007247 let curdir = getcwd()
7248 let tmpdir = s:GetTempfile("")
7249 if tmpdir !~ '/'
7250 let tmpdir= curdir."/".tmpdir
7251 endif
7252 if exists("*mkdir")
7253 call mkdir(tmpdir)
7254 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007255 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007256 if v:shell_error != 0
7257 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 +01007258" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007259 return
7260 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007261 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007262 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007263 if s:NetrwLcd(tmpdir)
7264" call Dret("s:NetrwMarkFileCopy : lcd failure")
7265 return
7266 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007267 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007268 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007269 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007270 if getcwd() == tmpdir
7271 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007272 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007273 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007274 if s:NetrwLcd(curdir)
7275" call Dret("s:NetrwMarkFileCopy : lcd failure")
7276 return
7277 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007278 if delete(tmpdir,"d")
7279 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007280 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007281 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007282 if s:NetrwLcd(curdir)
7283" call Dret("s:NetrwMarkFileCopy : lcd failure")
7284 return
7285 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007286 endif
7287 endif
7288 endif
7289
7290 " -------
7291 " cleanup
7292 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007293" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007294 " remove markings from local buffer
7295 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007296" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7297" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7298" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7299" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7300" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7301" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7302 if exists("s:recursive")
7303" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7304 else
7305" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007306 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007307 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007308 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007309 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007310 else
7311 " refresh local and targets for fast browsing
7312 if !exists("s:recursive")
7313 " remove markings from local buffer
7314" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7315 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7316 endif
7317
7318 " refresh buffers
7319 if s:netrwmftgt_islocal
7320" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7321 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7322 endif
7323 if a:islocal && s:netrwmftgt != curdir
7324" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7325 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7326 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007327 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007328
Bram Moolenaar446cb832008-06-24 21:56:24 +00007329" call Dret("s:NetrwMarkFileCopy 1")
7330 return 1
7331endfun
7332
7333" ---------------------------------------------------------------------
7334" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7335" invoke vim's diff mode on the marked files.
7336" Either two or three files can be so handled.
7337" Uses the global marked file list.
7338fun! s:NetrwMarkFileDiff(islocal)
7339" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7340 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007341
Bram Moolenaarff034192013-04-24 18:51:19 +02007342 " sanity check
7343 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007344 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007345" call Dret("s:NetrwMarkFileDiff")
7346 return
7347 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007348 let curdir= s:NetrwGetCurdir(a:islocal)
7349" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007350
Bram Moolenaara6878372014-03-22 21:02:50 +01007351 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007352 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007353 for fname in s:netrwmarkfilelist
7354 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007355 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007356" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007357 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007358 diffthis
7359 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007360 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007361" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007362 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007363 diffthis
7364 else
7365 break
7366 endif
7367 endfor
7368 call s:NetrwUnmarkList(curbufnr,curdir)
7369 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007370
Bram Moolenaar446cb832008-06-24 21:56:24 +00007371" call Dret("s:NetrwMarkFileDiff")
7372endfun
7373
7374" ---------------------------------------------------------------------
7375" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7376" Uses global markfilelist
7377fun! s:NetrwMarkFileEdit(islocal)
7378" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7379
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007380 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007381 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007382
7383 " sanity check
7384 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007385 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007386" call Dret("s:NetrwMarkFileEdit")
7387 return
7388 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007389" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007390
Bram Moolenaar446cb832008-06-24 21:56:24 +00007391 if exists("s:netrwmarkfilelist_{curbufnr}")
7392 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007393 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007394 " unmark markedfile list
7395" call s:NetrwUnmarkList(curbufnr,curdir)
7396 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007397" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007398 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007399 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007400 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007401
Bram Moolenaar446cb832008-06-24 21:56:24 +00007402" call Dret("s:NetrwMarkFileEdit")
7403endfun
7404
7405" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007406" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007407fun! s:NetrwMarkFileQFEL(islocal,qfel)
7408" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7409 call s:NetrwUnmarkAll()
7410 let curbufnr= bufnr("%")
7411
7412 if !empty(a:qfel)
7413 for entry in a:qfel
7414 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007415" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007416 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007417" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007418 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7419 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7420 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7421 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007422" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007423 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7424 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007425" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007426 endif
7427 endfor
7428 echo "(use me to edit marked files)"
7429 else
7430 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7431 endif
7432
7433" call Dret("s:NetrwMarkFileQFEL")
7434endfun
7435
7436" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007437" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7438" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7439" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7440fun! s:NetrwMarkFileExe(islocal,enbloc)
7441" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007442 let svpos = winsaveview()
7443" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007444 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007445 let curbufnr = bufnr("%")
7446
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007447 if a:enbloc == 0
7448 " individually apply command to files, one at a time
7449 " sanity check
7450 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7451 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7452" call Dret("s:NetrwMarkFileExe")
7453 return
7454 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007455" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007456
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007457 if exists("s:netrwmarkfilelist_{curbufnr}")
7458 " get the command
7459 call inputsave()
7460 let cmd= input("Enter command: ","","file")
7461 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007462" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007463 if cmd == ""
7464" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7465 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007466 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007467
7468 " apply command to marked files, individually. Substitute: filename -> %
7469 " If no %, then append a space and the filename to the command
7470 for fname in s:netrwmarkfilelist_{curbufnr}
7471 if a:islocal
7472 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007473 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007474 endif
7475 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007476 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007477 endif
7478 if cmd =~ '%'
7479 let xcmd= substitute(cmd,'%',fname,'g')
7480 else
7481 let xcmd= cmd.' '.fname
7482 endif
7483 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007484" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007485 let ret= system(xcmd)
7486 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007487" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007488 let ret= s:RemoteSystem(xcmd)
7489 endif
7490 if v:shell_error < 0
7491 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7492 break
7493 else
7494 echo ret
7495 endif
7496 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007497
7498 " unmark marked file list
7499 call s:NetrwUnmarkList(curbufnr,curdir)
7500
7501 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007502 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007503" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7504 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007505 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007506 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007507 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007508
7509 else " apply command to global list of files, en bloc
7510
7511 call inputsave()
7512 let cmd= input("Enter command: ","","file")
7513 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007514" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007515 if cmd == ""
7516" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7517 return
7518 endif
7519 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007520 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007521 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007522 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007523 endif
7524 if a:islocal
7525 call system(cmd)
7526 if v:shell_error < 0
7527 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7528 endif
7529 else
7530 let ret= s:RemoteSystem(cmd)
7531 endif
7532 call s:NetrwUnmarkAll()
7533
7534 " refresh the listing
7535 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007536" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7537 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007538
7539 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007540
Bram Moolenaar446cb832008-06-24 21:56:24 +00007541" call Dret("s:NetrwMarkFileExe")
7542endfun
7543
7544" ---------------------------------------------------------------------
7545" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7546" as the marked file(s) (toggles suffix presence)
7547" Uses the local marked file list.
7548fun! s:NetrwMarkHideSfx(islocal)
7549" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007550 let svpos = winsaveview()
7551" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007552 let curbufnr = bufnr("%")
7553
7554 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7555 if exists("s:netrwmarkfilelist_{curbufnr}")
7556
7557 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007558" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007559 " construct suffix pattern
7560 if fname =~ '\.'
7561 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7562 else
7563 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7564 endif
7565 " determine if its in the hiding list or not
7566 let inhidelist= 0
7567 if g:netrw_list_hide != ""
7568 let itemnum = 0
7569 let hidelist= split(g:netrw_list_hide,',')
7570 for hidepat in hidelist
7571 if sfxpat == hidepat
7572 let inhidelist= 1
7573 break
7574 endif
7575 let itemnum= itemnum + 1
7576 endfor
7577 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007578" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007579 if inhidelist
7580 " remove sfxpat from list
7581 call remove(hidelist,itemnum)
7582 let g:netrw_list_hide= join(hidelist,",")
7583 elseif g:netrw_list_hide != ""
7584 " append sfxpat to non-empty list
7585 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7586 else
7587 " set hiding list to sfxpat
7588 let g:netrw_list_hide= sfxpat
7589 endif
7590 endfor
7591
7592 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007593 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007594" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7595 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007596 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007597 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007598 endif
7599
7600" call Dret("s:NetrwMarkHideSfx")
7601endfun
7602
7603" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007604" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007605" Uses the local marked-file list.
7606fun! s:NetrwMarkFileVimCmd(islocal)
7607" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007608 let svpos = winsaveview()
7609" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007610 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007611 let curbufnr = bufnr("%")
7612
Bram Moolenaarff034192013-04-24 18:51:19 +02007613 " sanity check
7614 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007615 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007616" call Dret("s:NetrwMarkFileVimCmd")
7617 return
7618 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007619" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007620
Bram Moolenaar15146672011-10-20 22:22:38 +02007621 if exists("s:netrwmarkfilelist_{curbufnr}")
7622 " get the command
7623 call inputsave()
7624 let cmd= input("Enter vim command: ","","file")
7625 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007626" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007627 if cmd == ""
7628" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7629 return
7630 endif
7631
7632 " apply command to marked files. Substitute: filename -> %
7633 " If no %, then append a space and the filename to the command
7634 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007635" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007636 if a:islocal
7637 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007638 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007639" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007640 exe cmd
7641 exe "sil! keepalt wq!"
7642 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007643" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007644 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007645 endif
7646 endfor
7647
7648 " unmark marked file list
7649 call s:NetrwUnmarkList(curbufnr,curdir)
7650
7651 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007652 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007653" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7654 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007655 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007656 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007657 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007658
Bram Moolenaar15146672011-10-20 22:22:38 +02007659" call Dret("s:NetrwMarkFileVimCmd")
7660endfun
7661
7662" ---------------------------------------------------------------------
7663" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7664" as the marked file(s) (toggles suffix presence)
7665" Uses the local marked file list.
7666fun! s:NetrwMarkHideSfx(islocal)
7667" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007668 let svpos = winsaveview()
7669" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007670 let curbufnr = bufnr("%")
7671
7672 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7673 if exists("s:netrwmarkfilelist_{curbufnr}")
7674
7675 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007676" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007677 " construct suffix pattern
7678 if fname =~ '\.'
7679 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7680 else
7681 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7682 endif
7683 " determine if its in the hiding list or not
7684 let inhidelist= 0
7685 if g:netrw_list_hide != ""
7686 let itemnum = 0
7687 let hidelist= split(g:netrw_list_hide,',')
7688 for hidepat in hidelist
7689 if sfxpat == hidepat
7690 let inhidelist= 1
7691 break
7692 endif
7693 let itemnum= itemnum + 1
7694 endfor
7695 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007696" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007697 if inhidelist
7698 " remove sfxpat from list
7699 call remove(hidelist,itemnum)
7700 let g:netrw_list_hide= join(hidelist,",")
7701 elseif g:netrw_list_hide != ""
7702 " append sfxpat to non-empty list
7703 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7704 else
7705 " set hiding list to sfxpat
7706 let g:netrw_list_hide= sfxpat
7707 endif
7708 endfor
7709
7710 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007711 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007712" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7713 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007714 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007715 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007716 endif
7717
7718" call Dret("s:NetrwMarkHideSfx")
7719endfun
7720
7721" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007722" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7723" Uses the global markfilelist
7724fun! s:NetrwMarkFileGrep(islocal)
7725" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007726 let svpos = winsaveview()
7727" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007728 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007729 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007730
7731 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007732" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007733 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007734" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007735 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007736 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007737" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007738 let netrwmarkfilelist= "*"
7739 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007740
Bram Moolenaarff034192013-04-24 18:51:19 +02007741 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007742" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007743 call inputsave()
7744 let pat= input("Enter pattern: ","")
7745 call inputrestore()
7746 let patbang = ""
7747 if pat =~ '^!'
7748 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007749 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007750 endif
7751 if pat =~ '^\i'
7752 let pat = escape(pat,'/')
7753 let pat = '/'.pat.'/'
7754 else
7755 let nonisi = pat[0]
7756 endif
7757
7758 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007759" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007760 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007761 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007762 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007763 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007764" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7765 return
7766 endtry
7767 echo "(use :cn, :cp to navigate, :Rex to return)"
7768
7769 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007770" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7771 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007772
7773 if exists("nonisi")
7774 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007775" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007776 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007777 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007778 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007779 endif
7780
7781" call Dret("s:NetrwMarkFileGrep")
7782endfun
7783
7784" ---------------------------------------------------------------------
7785" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7786" uses the global marked file list
7787" s:netrwmfloc= 0: target directory is remote
7788" = 1: target directory is local
7789fun! s:NetrwMarkFileMove(islocal)
7790" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007791 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007792 let curbufnr = bufnr("%")
7793
7794 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007795 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007796 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007797" call Dret("s:NetrwMarkFileMove")
7798 return
7799 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007800" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007801
Bram Moolenaar446cb832008-06-24 21:56:24 +00007802 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007803 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007804" call Dret("s:NetrwMarkFileCopy 0")
7805 return 0
7806 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007807" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007808
7809 if a:islocal && s:netrwmftgt_islocal
7810 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007811" call Decho("move from local to local",'~'.expand("<slnum>"))
7812" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007813 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007814 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7815" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7816 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007818 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007819" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007820 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007821 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007822" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007823 if g:netrw_localmovecmd =~ '\s'
7824 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7825 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7826 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007827" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007828 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007829 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007830" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007831 endif
7832 else
7833 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007834" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007835 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007836 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007837 if g:netrw_keepdir
7838 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7839 let fname= b:netrw_curdir."/".fname
7840 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007841 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007842 let fname= substitute(fname,'/','\\','g')
7843 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007844" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007845 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007846 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007847 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007848 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 +01007849 else
7850 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7851 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007852 break
7853 endif
7854 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007855
7856 elseif a:islocal && !s:netrwmftgt_islocal
7857 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007858" call Decho("move from local to remote",'~'.expand("<slnum>"))
7859" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007860 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007861 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007862" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007863 for fname in mflist
7864 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7865 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7866 endfor
7867 unlet mflist
7868
7869 elseif !a:islocal && s:netrwmftgt_islocal
7870 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007871" call Decho("move from remote to local",'~'.expand("<slnum>"))
7872" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007873 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007874 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007875" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007876 for fname in mflist
7877 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7878 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7879 endfor
7880 unlet mflist
7881
7882 elseif !a:islocal && !s:netrwmftgt_islocal
7883 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007884" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7885" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007886 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007887 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007888" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007889 for fname in mflist
7890 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7891 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7892 endfor
7893 unlet mflist
7894 endif
7895
7896 " -------
7897 " cleanup
7898 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007899" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007900
7901 " remove markings from local buffer
7902 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7903
7904 " refresh buffers
7905 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007906" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007907 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007908 endif
7909 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007910" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007911 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007912 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007913 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007914" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007915 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007916 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007917
Bram Moolenaar446cb832008-06-24 21:56:24 +00007918" call Dret("s:NetrwMarkFileMove")
7919endfun
7920
7921" ---------------------------------------------------------------------
7922" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7923" using the hardcopy command. Local marked-file list only.
7924fun! s:NetrwMarkFilePrint(islocal)
7925" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7926 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007927
7928 " sanity check
7929 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007930 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007931" call Dret("s:NetrwMarkFilePrint")
7932 return
7933 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007934" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7935 let curdir= s:NetrwGetCurdir(a:islocal)
7936
Bram Moolenaar446cb832008-06-24 21:56:24 +00007937 if exists("s:netrwmarkfilelist_{curbufnr}")
7938 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007939 call s:NetrwUnmarkList(curbufnr,curdir)
7940 for fname in netrwmarkfilelist
7941 if a:islocal
7942 if g:netrw_keepdir
7943 let fname= s:ComposePath(curdir,fname)
7944 endif
7945 else
7946 let fname= curdir.fname
7947 endif
7948 1split
7949 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007950" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007951 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007952" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007953 hardcopy
7954 q
7955 endfor
7956 2match none
7957 endif
7958" call Dret("s:NetrwMarkFilePrint")
7959endfun
7960
7961" ---------------------------------------------------------------------
7962" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7963" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007964" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007965fun! s:NetrwMarkFileRegexp(islocal)
7966" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7967
7968 " get the regular expression
7969 call inputsave()
7970 let regexp= input("Enter regexp: ","","file")
7971 call inputrestore()
7972
7973 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007974 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007975" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007976 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007977" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007978 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007979 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007980 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007981 else
7982 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007983 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007984 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007985" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007986
7987 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007988 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007989 if fname =~ '^'.fnameescape(curdir)
7990" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7991 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7992 else
7993" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7994 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7995 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007996 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007997
7998 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007999" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008000
8001 " convert displayed listing into a filelist
8002 let eikeep = &ei
8003 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008004 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008005 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008006" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008007 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008008 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008009 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008010 sil NetrwKeepj norm! "ap
8011 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008012 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008013 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008014 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008015 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008016 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008017 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008019 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008020 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008022 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8023 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008024 call histdel("/",-1)
8025 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008026 endif
8027 " convert regexp into the more usual glob-style format
8028 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008029" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008030 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008031 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008032 let filelist= getline(1,line("$"))
8033 q!
8034 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008035 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008036 endfor
8037 unlet filelist
8038 let @a = areg
8039 let &ei = eikeep
8040 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008041 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008042
8043" call Dret("s:NetrwMarkFileRegexp")
8044endfun
8045
8046" ---------------------------------------------------------------------
8047" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8048" Uses the local marked file list.
8049fun! s:NetrwMarkFileSource(islocal)
8050" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8051 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008052
8053 " sanity check
8054 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008055 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008056" call Dret("s:NetrwMarkFileSource")
8057 return
8058 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008059" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8060 let curdir= s:NetrwGetCurdir(a:islocal)
8061
Bram Moolenaar446cb832008-06-24 21:56:24 +00008062 if exists("s:netrwmarkfilelist_{curbufnr}")
8063 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008064 call s:NetrwUnmarkList(curbufnr,curdir)
8065 for fname in netrwmarkfilelist
8066 if a:islocal
8067 if g:netrw_keepdir
8068 let fname= s:ComposePath(curdir,fname)
8069 endif
8070 else
8071 let fname= curdir.fname
8072 endif
8073 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008074" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008075 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008076 endfor
8077 2match none
8078 endif
8079" call Dret("s:NetrwMarkFileSource")
8080endfun
8081
8082" ---------------------------------------------------------------------
8083" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8084" Uses the global markfilelist
8085fun! s:NetrwMarkFileTag(islocal)
8086" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008087 let svpos = winsaveview()
8088" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008089 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008090 let curbufnr = bufnr("%")
8091
Bram Moolenaarff034192013-04-24 18:51:19 +02008092 " sanity check
8093 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008094 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008095" call Dret("s:NetrwMarkFileTag")
8096 return
8097 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008098" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008099
Bram Moolenaar446cb832008-06-24 21:56:24 +00008100 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008101" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8102 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008103 call s:NetrwUnmarkAll()
8104
8105 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008106
8107" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8108 call system(g:netrw_ctags." ".netrwmarkfilelist)
8109 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008110 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8111 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008112
Bram Moolenaar446cb832008-06-24 21:56:24 +00008113 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008114 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008115 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008116 let curdir= b:netrw_curdir
8117 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008118 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008120" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008121 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008122 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008123 wq!
8124 endif
8125 2match none
8126 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008127" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8128 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008129 endif
8130
8131" call Dret("s:NetrwMarkFileTag")
8132endfun
8133
8134" ---------------------------------------------------------------------
8135" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008136" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008137" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008138" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008139" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008140fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008141" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8142 let svpos = winsaveview()
8143" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008144 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008145 let hadtgt = exists("s:netrwmftgt")
8146 if !exists("w:netrw_bannercnt")
8147 let w:netrw_bannercnt= b:netrw_bannercnt
8148 endif
8149
8150 " set up target
8151 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008152" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008153 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8154 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008155" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008156 unlet s:netrwmftgt s:netrwmftgt_islocal
8157 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008158 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008159 endif
8160 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008161" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8162 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008163" call Dret("s:NetrwMarkFileTgt : removed target")
8164 return
8165 else
8166 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008167" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008168 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008169
8170 else
8171 " get word under cursor.
8172 " * If directory, use it for the target.
8173 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008174" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008175 let curword= s:NetrwGetWord()
8176 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008177 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008178 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008179" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008180 elseif !a:islocal && tgtdir =~ '/$'
8181 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008182" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008183 else
8184 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008185" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008186 endif
8187 endif
8188 if a:islocal
8189 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8190 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008192 endif
8193 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008194 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008195 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8196 endif
8197 let s:netrwmftgt_islocal= a:islocal
8198
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008199 " need to do refresh so that the banner will be updated
8200 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008201 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008202" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008203 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008204 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008205" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008206 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008207 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8208 else
8209 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8210 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008211" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8212 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008213 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008214 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008215 endif
8216
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008217" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8218" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008219" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8220endfun
8221
8222" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008223" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8224fun! s:NetrwGetCurdir(islocal)
8225" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8226
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008227 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008228 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8229" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8230 elseif !exists("b:netrw_curdir")
8231 let b:netrw_curdir= getcwd()
8232" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8233 endif
8234
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008235" 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 +01008236 if b:netrw_curdir !~ '\<\a\{3,}://'
8237 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008238" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008239 if g:netrw_keepdir == 0
8240 call s:NetrwLcd(curdir)
8241 endif
8242 endif
8243
8244" call Dret("s:NetrwGetCurdir <".curdir.">")
8245 return b:netrw_curdir
8246endfun
8247
8248" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008249" s:NetrwOpenFile: query user for a filename and open it {{{2
8250fun! s:NetrwOpenFile(islocal)
8251" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008252 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008253 call inputsave()
8254 let fname= input("Enter filename: ")
8255 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008256" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8257
8258 " determine if Lexplore is in use
8259 if exists("t:netrw_lexbufnr")
8260 " check if t:netrw_lexbufnr refers to a netrw window
8261" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8262 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8263 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8264" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8265 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8266 exe "NetrwKeepj e ".fnameescape(fname)
8267 let @@= ykeep
8268" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8269 endif
8270 endif
8271
8272 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008273 if fname !~ '[/\\]'
8274 if exists("b:netrw_curdir")
8275 if exists("g:netrw_quiet")
8276 let netrw_quiet_keep = g:netrw_quiet
8277 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008278 let g:netrw_quiet = 1
8279 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008280 let s:rexposn_{bufnr("%")}= winsaveview()
8281" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008282 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008283 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008284 else
8285 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8286 endif
8287 if exists("netrw_quiet_keep")
8288 let g:netrw_quiet= netrw_quiet_keep
8289 else
8290 unlet g:netrw_quiet
8291 endif
8292 endif
8293 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008294 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008295 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008296 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008297" call Dret("s:NetrwOpenFile")
8298endfun
8299
8300" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008301" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8302" For the mapping to this function be made via
8303" netrwPlugin, you'll need to have had
8304" g:netrw_usetab set to non-zero.
8305fun! netrw#Shrink()
8306" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8307 let curwin = winnr()
8308 let wiwkeep = &wiw
8309 set wiw=1
8310
8311 if &ft == "netrw"
8312 if winwidth(0) > g:netrw_wiw
8313 let t:netrw_winwidth= winwidth(0)
8314 exe "vert resize ".g:netrw_wiw
8315 wincmd l
8316 if winnr() == curwin
8317 wincmd h
8318 endif
8319" call Decho("vert resize 0",'~'.expand("<slnum>"))
8320 else
8321 exe "vert resize ".t:netrw_winwidth
8322" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8323 endif
8324
8325 elseif exists("t:netrw_lexbufnr")
8326 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8327 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8328 let t:netrw_winwidth= winwidth(0)
8329 exe "vert resize ".g:netrw_wiw
8330 wincmd l
8331 if winnr() == curwin
8332 wincmd h
8333 endif
8334" call Decho("vert resize 0",'~'.expand("<slnum>"))
8335 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8336 exe "vert resize ".t:netrw_winwidth
8337" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8338 else
8339 call netrw#Lexplore(0,0)
8340 endif
8341
8342 else
8343 call netrw#Lexplore(0,0)
8344 endif
8345 let wiw= wiwkeep
8346
8347" call Dret("netrw#Shrink")
8348endfun
8349
8350" ---------------------------------------------------------------------
8351" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8352fun! s:NetSortSequence(islocal)
8353" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8354
8355 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008356 let svpos= winsaveview()
8357" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008358 call inputsave()
8359 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8360 call inputrestore()
8361
8362 " refresh the listing
8363 let g:netrw_sort_sequence= newsortseq
8364 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008365" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8366 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008367 let @@= ykeep
8368
8369" call Dret("NetSortSequence")
8370endfun
8371
8372" ---------------------------------------------------------------------
8373" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8374" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008375" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008376fun! s:NetrwUnmarkList(curbufnr,curdir)
8377" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8378
8379 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008380 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008381 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8382 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8383 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8384 call remove(s:netrwmarkfilelist,idx) " remove from global list
8385 endfor
8386 if s:netrwmarkfilelist == []
8387 unlet s:netrwmarkfilelist
8388 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008389
Bram Moolenaar446cb832008-06-24 21:56:24 +00008390 " getting rid of the local marked-file lists is easy
8391 unlet s:netrwmarkfilelist_{a:curbufnr}
8392 endif
8393 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8394 unlet s:netrwmarkfilemtch_{a:curbufnr}
8395 endif
8396 2match none
8397" call Dret("s:NetrwUnmarkList")
8398endfun
8399
8400" ---------------------------------------------------------------------
8401" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8402fun! s:NetrwUnmarkAll()
8403" call Dfunc("s:NetrwUnmarkAll()")
8404 if exists("s:netrwmarkfilelist")
8405 unlet s:netrwmarkfilelist
8406 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008407 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008408 2match none
8409" call Dret("s:NetrwUnmarkAll")
8410endfun
8411
8412" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008413" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008414fun! s:NetrwUnmarkAll2()
8415" call Dfunc("s:NetrwUnmarkAll2()")
8416 redir => netrwmarkfilelist_let
8417 let
8418 redir END
8419 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008420 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008421 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8422 for flist in netrwmarkfilelist_list
8423 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8424 unlet s:netrwmarkfilelist_{curbufnr}
8425 unlet s:netrwmarkfilemtch_{curbufnr}
8426 endfor
8427" call Dret("s:NetrwUnmarkAll2")
8428endfun
8429
8430" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008431" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8432"
8433" Marked files are in two types of lists:
8434" s:netrwmarkfilelist -- holds complete paths to all marked files
8435" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8436"
8437" Marked files suitable for use with 2match are in:
8438" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008439fun! s:NetrwUnMarkFile(islocal)
8440" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008441 let svpos = winsaveview()
8442" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008443 let curbufnr = bufnr("%")
8444
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008445 " unmark marked file list
8446 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8447 if exists("s:netrwmarkfilelist")
8448" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008449 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008450 endif
8451
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008452 let ibuf= 1
8453 while ibuf < bufnr("$")
8454 if exists("s:netrwmarkfilelist_".ibuf)
8455 unlet s:netrwmarkfilelist_{ibuf}
8456 unlet s:netrwmarkfilemtch_{ibuf}
8457 endif
8458 let ibuf = ibuf + 1
8459 endwhile
8460 2match none
8461
Bram Moolenaar446cb832008-06-24 21:56:24 +00008462" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008463"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8464call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008465" call Dret("s:NetrwUnMarkFile")
8466endfun
8467
8468" ---------------------------------------------------------------------
8469" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8470fun! s:NetrwMenu(domenu)
8471
8472 if !exists("g:NetrwMenuPriority")
8473 let g:NetrwMenuPriority= 80
8474 endif
8475
Bram Moolenaaradc21822011-04-01 18:03:16 +02008476 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008477" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8478
8479 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008480" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008481 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008482 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8483 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8484 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8485 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8486 if g:netrw_dirhistmax > 0
8487 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8488 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8489 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8490 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8491 else
8492 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8493 endif
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8495 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8497 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8500 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8508 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 +01008509 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 +02008510 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8539 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>'
8540 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>'
8541 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>'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8543 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>'
8544 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>'
8545 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 +01008546 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 +02008547 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008549 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008550 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8551 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008552
8553 elseif !a:domenu
8554 let s:netrwcnt = 0
8555 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008556 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008557 exe curwin."wincmd w"
8558
8559 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008560" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008561 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008562" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008563 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008564 endif
8565 endif
8566" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008567 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008568 endif
8569
8570endfun
8571
8572" ---------------------------------------------------------------------
8573" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8574" Used by the O maps (as <SID>NetrwObtain())
8575fun! s:NetrwObtain(islocal)
8576" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8577
Bram Moolenaar97d62492012-11-15 21:28:22 +01008578 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008579 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008580 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008581 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008582 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8583 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008584 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008585 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008586 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008587
8588" call Dret("NetrwObtain")
8589endfun
8590
8591" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008592" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8593" If there's only one window, then the window will first be split.
8594" Returns:
8595" choice = 0 : didn't have to choose
8596" choice = 1 : saved modified file in window first
8597" choice = 2 : didn't save modified file, opened window
8598" choice = 3 : cancel open
8599fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008600" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601
Bram Moolenaar97d62492012-11-15 21:28:22 +01008602 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008603 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008604 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008605" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008606
8607 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008608 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008609 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008610" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8611" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8612 let curword = s:NetrwGetWord()
8613 let choice = 0
8614 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8615" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008616 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008617" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008618 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008619" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008620" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008621" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008622
Bram Moolenaar8d043172014-01-23 14:24:41 +01008623 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008624 if lastwinnr == 1
8625 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008626" 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 +02008627 " g:netrw_preview=0: preview window shown in a horizontally split window
8628 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008629 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008630 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008631 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008632" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008633 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008634 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008635 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008636 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008637" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008638 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008639 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008640 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008641" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008642
8643 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008644" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008645 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008646" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008647 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008648" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008649 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008650" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008651 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008652" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008653" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008654" call Decho("COMBAK#12: mod=".&mod)
8655
8656 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8657 " whoops -- user trying to open file in the Lexplore window.
8658 " Use Lexplore's opening-file window instead.
8659" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8660" exe g:netrw_chgwin."wincmd w"
8661 wincmd p
8662 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8663 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008664
8665 " prevwinnr: the window number of the "prev" window
8666 " prevbufnr: the buffer number of the buffer in the "prev" window
8667 " bnrcnt : the qty of windows open on the "prev" buffer
8668 let prevwinnr = winnr()
8669 let prevbufnr = bufnr("%")
8670 let prevbufname = bufname("%")
8671 let prevmod = &mod
8672 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008673" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008674 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008675" 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 +01008676" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008677
8678 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008679 " and it doesn't appear in any other extant window, then ask the
8680 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008681 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008682" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008683 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008684" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008685 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008686" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008687
8688 if bnrcnt == 1 && &hidden == 0
8689 " only one copy of the modified buffer in a window, and
8690 " hidden not set, so overwriting will lose the modified file. Ask first...
8691 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008692" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008693 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008694" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008695
8696 if choice == 1
8697 " Yes -- write file & then browse
8698 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008699 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008700 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008701 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008702 exe origwin."wincmd w"
8703 let &ei = eikeep
8704 let @@ = ykeep
8705" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008706 return choice
8707 endif
8708
8709 elseif choice == 2
8710 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008711" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008712 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008713
8714 else
8715 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008716" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008717 exe origwin."wincmd w"
8718 let &ei= eikeep
8719 let @@ = ykeep
8720" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008721 return choice
8722 endif
8723 endif
8724 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008725 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008726 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008727" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008728
8729 " restore b:netrw_curdir (window split/enew may have lost it)
8730 let b:netrw_curdir= curdir
8731 if a:islocal < 2
8732 if a:islocal
8733 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8734 else
8735 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8736 endif
8737 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008738 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008739" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008740 return choice
8741endfun
8742
8743" ---------------------------------------------------------------------
8744" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8745" Always assumed to be local -> remote
8746" call s:NetrwUpload(filename, target)
8747" call s:NetrwUpload(filename, target, fromdirectory)
8748fun! s:NetrwUpload(fname,tgt,...)
8749" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8750
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008751 if a:tgt =~ '^\a\{3,}://'
8752 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008753 else
8754 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8755 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008756" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008757
8758 if a:0 > 0
8759 let fromdir= a:1
8760 else
8761 let fromdir= getcwd()
8762 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008763" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008764
8765 if type(a:fname) == 1
8766 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008767" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008768 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008769" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8770 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8771" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008772 if a:tgt =~ '/$'
8773 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008774" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008775 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008776 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008777" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008778 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008779" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008780 endif
8781 q!
8782
8783 elseif type(a:fname) == 3
8784 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008785" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008786 let curdir= getcwd()
8787 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008788 if s:NetrwLcd(fromdir)
8789" call Dret("s:NetrwUpload : lcd failure")
8790 return
8791 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008792 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008793 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008794 if exists("g:netrw_port") && g:netrw_port != ""
8795 let useport= " ".g:netrw_scpport." ".g:netrw_port
8796 else
8797 let useport= ""
8798 endif
8799 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8800 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008801 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 +02008802 if s:NetrwLcd(curdir)
8803" call Dret("s:NetrwUpload : lcd failure")
8804 return
8805 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008806
8807 elseif a:tgt =~ '^ftp:'
8808 call s:NetrwMethod(a:tgt)
8809
8810 if b:netrw_method == 2
8811 " handle uploading a list of files via ftp+.netrc
8812 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008813 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008814" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008815
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008816 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008817" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008818
8819 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008820 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008821" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008822 endif
8823
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008824 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008825" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008826
Bram Moolenaaradc21822011-04-01 18:03:16 +02008827 if tgtdir == ""
8828 let tgtdir= '/'
8829 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008830 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008831" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008832
8833 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008834 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8835" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008836 endfor
8837
8838 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008839 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 +00008840 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008841" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8842 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008843 endif
8844 " 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 +01008845 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008846 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008847 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8848 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8849 else
8850 bw!|q
8851 endif
8852
8853 elseif b:netrw_method == 3
8854 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8855 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008856 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008857 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008858 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008859
8860 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008861 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008862" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008863 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008864 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008865" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008866 endif
8867
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008868 if exists("g:netrw_uid") && g:netrw_uid != ""
8869 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008870 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008871" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008872 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008873 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008874 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008875" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008876 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008877 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008878" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008879 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008880 endif
8881
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008882 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008883" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008884
8885 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008886 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008887" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008888 endif
8889
8890 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008891 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008892" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008893 endif
8894
8895 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008896 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008897" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008898 endfor
8899
8900 " perform ftp:
8901 " -i : turns off interactive prompting from ftp
8902 " -n unix : DON'T use <.netrc>, even though it exists
8903 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008904 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008905 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008906 " 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 +01008907 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008908 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008909 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8910 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008911 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008912 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8913 let &debug = debugkeep
8914 let mod = 1
8915 else
8916 bw!|q
8917 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008918 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008919" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008920 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008921 endif
8922 else
8923 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8924 endif
8925 endif
8926
8927" call Dret("s:NetrwUpload")
8928endfun
8929
8930" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008931" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008932fun! s:NetrwPreview(path) range
8933" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008934" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8935" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008936 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008937 NetrwKeepj call s:NetrwOptionsSave("s:")
8938 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8939 NetrwKeepj call s:NetrwOptionsSafe(1)
8940 else
8941 NetrwKeepj call s:NetrwOptionsSafe(0)
8942 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008943 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008944" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008945 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008946" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8947 if g:netrw_preview
8948 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008949 let pvhkeep = &pvh
8950 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8951 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008952" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8953 else
8954 " horizontal split
8955 let pvhkeep = &pvh
8956 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8957 let &pvh = winheight(0) - winsz
8958" 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 +02008959 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008960 " g:netrw_preview g:netrw_alto
8961 " 1 : vert 1: top -- preview window is vertically split off and on the left
8962 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8963 " 0 : 1: top -- preview window is horizontally split off and on the top
8964 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8965 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008966 " 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 +02008967 " the BufEnter event set up in netrwPlugin.vim
8968" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8969 let eikeep = &ei
8970 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008971 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008972 let &ei= eikeep
8973" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008974 if exists("pvhkeep")
8975 let &pvh= pvhkeep
8976 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008977 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008978 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008979 endif
8980 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008981 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 +00008982 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008983 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008984 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008985" call Dret("NetrwPreview")
8986endfun
8987
8988" ---------------------------------------------------------------------
8989" s:NetrwRefresh: {{{2
8990fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008991" 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 +00008992 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008993 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008994" call Decho("setl ma noro",'~'.expand("<slnum>"))
8995" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008996 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008997 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8998 if !exists("w:netrw_treetop")
8999 if exists("b:netrw_curdir")
9000 let w:netrw_treetop= b:netrw_curdir
9001 else
9002 let w:netrw_treetop= getcwd()
9003 endif
9004 endif
9005 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9006 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009007
9008 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009009 let screenposn = winsaveview()
9010" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009011
9012" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9013" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9014 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009015 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009016 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009017 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009018 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009019 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009020
9021 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009022" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9023 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009024
9025 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009026 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9027 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9028" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9029 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9030 else
9031" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9032 2match none
9033 endif
9034 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009035
Bram Moolenaar97d62492012-11-15 21:28:22 +01009036" restore
9037 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009038" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009039endfun
9040
9041" ---------------------------------------------------------------------
9042" s:NetrwRefreshDir: refreshes a directory by name {{{2
9043" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009044" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009045fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009046" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009047 if g:netrw_fastbrowse == 0
9048 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009049" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009050 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009051" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009052
9053 if tgtwin > 0
9054 " tgtwin is being displayed, so refresh it
9055 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009056" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009057 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009058 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009059 exe curwin."wincmd w"
9060
9061 elseif bufnr(a:dirname) > 0
9062 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009063" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9064 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009065 endif
9066
9067 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009068" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009069 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009070 endif
9071" call Dret("s:NetrwRefreshDir")
9072endfun
9073
9074" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009075" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9076" window number to do its editing in.
9077" Supports [count]C where the count, if present, is used to specify
9078" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009079fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009080" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009081 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009082" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009083 if a:1 == "" " :NetrwC win#
9084 let g:netrw_chgwin= winnr()
9085 else " :NetrwC
9086 let g:netrw_chgwin= a:1
9087 endif
9088 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009089 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009090 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009091 let g:netrw_chgwin= winnr()
9092 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009093 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009094" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009095endfun
9096
9097" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009098" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9099" What this function does is to compute a priority for the patterns
9100" in the g:netrw_sort_sequence. It applies a substitute to any
9101" "files" that satisfy each pattern, putting the priority / in
9102" front. An "*" pattern handles the default priority.
9103fun! s:NetrwSetSort()
9104" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009105 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009106 if w:netrw_liststyle == s:LONGLIST
9107 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9108 else
9109 let seqlist = g:netrw_sort_sequence
9110 endif
9111 " sanity check -- insure that * appears somewhere
9112 if seqlist == ""
9113 let seqlist= '*'
9114 elseif seqlist !~ '\*'
9115 let seqlist= seqlist.',*'
9116 endif
9117 let priority = 1
9118 while seqlist != ""
9119 if seqlist =~ ','
9120 let seq = substitute(seqlist,',.*$','','e')
9121 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9122 else
9123 let seq = seqlist
9124 let seqlist = ""
9125 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009126 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009127 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009128 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009129 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009130 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009131 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009132 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009133" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009134
9135 " sanity check
9136 if w:netrw_bannercnt > line("$")
9137 " apparently no files were left after a Hiding pattern was used
9138" call Dret("SetSort : no files left after hiding")
9139 return
9140 endif
9141 if seq == '*'
9142 let starpriority= spriority
9143 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009144 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009145 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009146 " sometimes multiple sorting patterns will match the same file or directory.
9147 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009148 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9149 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009150 endif
9151 let priority = priority + 1
9152 endwhile
9153 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009154 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9155 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009156 endif
9157
9158 " Following line associated with priority -- items that satisfy a priority
9159 " pattern get prefixed by ###/ which permits easy sorting by priority.
9160 " Sometimes files can satisfy multiple priority patterns -- only the latest
9161 " priority pattern needs to be retained. So, at this point, these excess
9162 " priority prefixes need to be removed, but not directories that happen to
9163 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009164 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9165 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009166 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009167
9168" call Dret("SetSort")
9169endfun
9170
Bram Moolenaarff034192013-04-24 18:51:19 +02009171" ---------------------------------------------------------------------
9172" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9173" Implements [count]Tb (bookhist<b>)
9174" [count]Th (bookhist<h>)
9175" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009176fun! s:NetrwSetTgt(islocal,bookhist,choice)
9177" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009178
9179 if a:bookhist == 'b'
9180 " supports choosing a bookmark as a target using a qb-generated list
9181 let choice= a:choice - 1
9182 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009183 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009184 else
9185 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9186 endif
9187
9188 elseif a:bookhist == 'h'
9189 " supports choosing a history stack entry as a target using a qb-generated list
9190 let choice= (a:choice % g:netrw_dirhistmax) + 1
9191 if exists("g:netrw_dirhist_".choice)
9192 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009193 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009194 else
9195 echomsg "Sorry, history#".a:choice." not available!"
9196 endif
9197 endif
9198
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009199 " refresh the display
9200 if !exists("b:netrw_curdir")
9201 let b:netrw_curdir= getcwd()
9202 endif
9203 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9204
Bram Moolenaarff034192013-04-24 18:51:19 +02009205" call Dret("s:NetrwSetTgt")
9206endfun
9207
Bram Moolenaar446cb832008-06-24 21:56:24 +00009208" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009209" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009210fun! s:NetrwSortStyle(islocal)
9211" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009212 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009213 let svpos= winsaveview()
9214" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009215
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009216 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 +01009217 NetrwKeepj norm! 0
9218 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009219" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9220 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009221
9222" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9223endfun
9224
9225" ---------------------------------------------------------------------
9226" s:NetrwSplit: mode {{{2
9227" =0 : net and o
9228" =1 : net and t
9229" =2 : net and v
9230" =3 : local and o
9231" =4 : local and t
9232" =5 : local and v
9233fun! s:NetrwSplit(mode)
9234" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9235
Bram Moolenaar97d62492012-11-15 21:28:22 +01009236 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009237 call s:SaveWinVars()
9238
9239 if a:mode == 0
9240 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009241 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009242 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009243" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009244 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009245 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009246 NetrwKeepj call s:RestoreWinVars()
9247 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009248 unlet s:didsplit
9249
9250 elseif a:mode == 1
9251 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009252 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009253" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009254 tabnew
9255 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009256 NetrwKeepj call s:RestoreWinVars()
9257 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009258 unlet s:didsplit
9259
9260 elseif a:mode == 2
9261 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009262 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009263 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009264" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009265 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009266 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009267 NetrwKeepj call s:RestoreWinVars()
9268 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009269 unlet s:didsplit
9270
9271 elseif a:mode == 3
9272 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009273 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009274 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009275" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009276 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009277 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009278 NetrwKeepj call s:RestoreWinVars()
9279 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009280 unlet s:didsplit
9281
9282 elseif a:mode == 4
9283 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009284 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009285 let eikeep = &ei
9286 let netrw_winnr = winnr()
9287 let netrw_line = line(".")
9288 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009289 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009290 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009291 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009292 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9293 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009294 let &ei = eikeep
9295 let netrw_curdir = s:NetrwTreeDir(0)
9296" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009297 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009298 let b:netrw_curdir = netrw_curdir
9299 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009300 NetrwKeepj call s:RestoreWinVars()
9301 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009302 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009303 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009304 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9305 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009306 let &ei= eikeep
9307 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009308 unlet s:didsplit
9309
9310 elseif a:mode == 5
9311 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009312 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009313 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009314" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009315 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009316 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009317 NetrwKeepj call s:RestoreWinVars()
9318 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009319 unlet s:didsplit
9320
9321 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009322 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009323 endif
9324
Bram Moolenaar97d62492012-11-15 21:28:22 +01009325 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009326" call Dret("s:NetrwSplit")
9327endfun
9328
9329" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009330" s:NetrwTgtMenu: {{{2
9331fun! s:NetrwTgtMenu()
9332 if !exists("s:netrw_menucnt")
9333 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009334 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009335" call Dfunc("s:NetrwTgtMenu()")
9336
9337 " the following test assures that gvim is running, has menus available, and has menus enabled.
9338 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9339 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009340" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009341 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9342 endif
9343 if !exists("s:netrw_initbookhist")
9344 call s:NetrwBookHistRead()
9345 endif
9346
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009347 " try to cull duplicate entries
9348 let tgtdict={}
9349
Bram Moolenaarff034192013-04-24 18:51:19 +02009350 " target bookmarked places
9351 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009352" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009353 let cnt= 1
9354 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009355 if has_key(tgtdict,bmd)
9356 let cnt= cnt + 1
9357 continue
9358 endif
9359 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009360 let ebmd= escape(bmd,g:netrw_menu_escape)
9361 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009362" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009363 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 +02009364 let cnt= cnt + 1
9365 endfor
9366 endif
9367
9368 " target directory browsing history
9369 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009370" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009371 let histcnt = 1
9372 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009373 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009374 if exists("g:netrw_dirhist_{histcnt}")
9375 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009376 if has_key(tgtdict,histentry)
9377 let histcnt = histcnt + 1
9378 continue
9379 endif
9380 let tgtdict[histentry] = histcnt
9381 let ehistentry = escape(histentry,g:netrw_menu_escape)
9382" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009383 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 +02009384 endif
9385 let histcnt = histcnt + 1
9386 endwhile
9387 endif
9388 endif
9389" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009390endfun
9391
9392" ---------------------------------------------------------------------
9393" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9394" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009395fun! s:NetrwTreeDir(islocal)
9396" 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 +02009397" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009398" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9399" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9400" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009401" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009402
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009403 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009404 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009405" 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 +01009406 let treedir= s:treedir
9407 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009408 unlet s:prevwinopen
9409" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009410 return treedir
9411 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009412 if exists("s:prevwinopen")
9413 unlet s:prevwinopen
9414 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009415" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009416
Bram Moolenaar8d043172014-01-23 14:24:41 +01009417 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9418 let b:netrw_curdir= getcwd()
9419 endif
9420 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009421" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009422" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009423
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009424 let s:treecurpos= winsaveview()
9425" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009426" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009427
9428 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009429" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9430" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009431" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009432
9433 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009434 let curline= substitute(getline('.'),"\t -->.*$",'','')
9435 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009436" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009437 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009438" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9439 elseif curline =~ '@$'
9440" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009441 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009442" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009443 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009444" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009445 let treedir= ""
9446 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009447" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009448
9449 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009450" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9451" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009452" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009453 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009454" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009455 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009456" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9457 sil! NetrwKeepj %d _
9458" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009459 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009460" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009461" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009462 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009463" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009464
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009465" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009466" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009467" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009468
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009469 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9470" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9471" let newdir = w:netrw_treetop.'/'.potentialdir
9472" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9473" let treedir = s:NetrwTreePath(newdir)
9474" let w:netrw_treetop = newdir
9475" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9476" else
9477" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009478 if a:islocal && curline =~ '@$'
9479 if isdirectory(s:NetrwFile(potentialdir))
9480 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9481 let w:netrw_treetop = treedir
9482 endif
9483 else
9484 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9485 let treedir = s:NetrwTreePath(w:netrw_treetop)
9486 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009487 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009488" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009489
9490 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009491 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009492" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009493" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009494
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009495" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009496 return treedir
9497endfun
9498
9499" ---------------------------------------------------------------------
9500" s:NetrwTreeDisplay: recursive tree display {{{2
9501fun! s:NetrwTreeDisplay(dir,depth)
9502" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9503
9504 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009505 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009506
9507 " install ../ and shortdir
9508 if a:depth == ""
9509 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009510" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009511 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009512 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009513 if a:dir == w:netrw_treetop
9514 let shortdir= a:dir
9515 else
9516 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9517 endif
9518 call setline(line("$")+1,a:depth.shortdir)
9519 else
9520 let shortdir= substitute(a:dir,'^.*/','','e')
9521 call setline(line("$")+1,a:depth.shortdir.'/')
9522 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009523" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009524 " append a / to dir if its missing one
9525 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009526
9527 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009528 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009529" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009530
Bram Moolenaar85850f32019-07-19 22:05:51 +02009531 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9532 if g:netrw_hide == 1
9533 " hide given patterns
9534 let listhide= split(g:netrw_list_hide,',')
9535" call Decho("listhide=".string(listhide))
9536 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009537 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009538 endfor
9539
9540 elseif g:netrw_hide == 2
9541 " show given patterns (only)
9542 let listhide= split(g:netrw_list_hide,',')
9543" call Decho("listhide=".string(listhide))
9544 let entries=[]
9545 for entry in w:netrw_treedict[dir]
9546 for pat in listhide
9547 if entry =~ pat
9548 call add(entries,entry)
9549 break
9550 endif
9551 endfor
9552 endfor
9553 let w:netrw_treedict[dir]= entries
9554 endif
9555 if depth != ""
9556 " always remove "." and ".." entries when there's depth
9557 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9558 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9559 endif
9560
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009561" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009562 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009563 if dir =~ '/$'
9564 let direntry= substitute(dir.entry,'[@/]$','','e')
9565 else
9566 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9567 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009568" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009569 if 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>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009571 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009572 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009573" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9574 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9575 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9576" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009577 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009579" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009580 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009581 endif
9582 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009583" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009584
Bram Moolenaar446cb832008-06-24 21:56:24 +00009585" call Dret("NetrwTreeDisplay")
9586endfun
9587
9588" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009589" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9590fun! s:NetrwRefreshTreeDict(dir)
9591" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009592 if !exists("w:netrw_treedict")
9593" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9594 return
9595 endif
9596
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009597 for entry in w:netrw_treedict[a:dir]
9598 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9599" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9600
9601 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9602" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9603 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009604 let liststar = s:NetrwGlob(direntry,'*',1)
9605 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009606 let w:netrw_treedict[direntry] = liststar + listdotstar
9607" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9608
9609 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9610" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9611 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009612 let liststar = s:NetrwGlob(direntry.'/','*',1)
9613 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009614 let w:netrw_treedict[direntry]= liststar + listdotstar
9615" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9616
9617 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9618" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9619 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009620 let liststar = s:NetrwGlob(direntry.'/','*',1)
9621 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009622" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9623
9624 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009625" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009626 endif
9627 endfor
9628" call Dret("s:NetrwRefreshTreeDict")
9629endfun
9630
9631" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009632" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009633" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009634fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009635 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009636" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009637" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9638" 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>"))
9639" 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 +00009640
9641 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009642 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009643" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009644 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009645 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009646" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009647 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 +02009648" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009649 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009650 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009651" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009652 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009653 if exists("w:netrw_treetop")
9654 let s:netrw_treetop= w:netrw_treetop
9655 else
9656 let w:netrw_treetop= getcwd()
9657 let s:netrw_treetop= w:netrw_treetop
9658 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009659
Bram Moolenaar446cb832008-06-24 21:56:24 +00009660 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009661 " insure that we have a treedict, albeit empty
9662" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009663 let w:netrw_treedict= {}
9664 endif
9665
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009666 " update the dictionary for the current directory
9667" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009668" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009669 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009670 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009671" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009672 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009673
9674 " if past banner, record word
9675 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9676 let fname= expand("<cword>")
9677 else
9678 let fname= ""
9679 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009680" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9681" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009682
9683 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009684" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009685 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009686" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009687
9688 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9689 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009690" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009691 1d
9692 endwhile
9693
Bram Moolenaar13600302014-05-22 18:26:40 +02009694 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009695
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009696" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009697 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009698 endif
9699endfun
9700
9701" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009702" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009703" Normally, treetop is w:netrw_treetop, but a
9704" user of the function ( netrw#SetTreetop() )
9705" wipes that out prior to calling this function
9706fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009707" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9708 if line(".") < w:netrw_bannercnt + 2
9709 let treedir= a:treetop
9710 if treedir !~ '/$'
9711 let treedir= treedir.'/'
9712 endif
9713" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9714 return treedir
9715 endif
9716
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009717 let svpos = winsaveview()
9718" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009719 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009720" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009721 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009722" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9723 let curline= getline('.')
9724" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9725 if curline =~ '/$'
9726" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9727 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9728" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9729 elseif curline =~ '@\s\+-->'
9730" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9731 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9732 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9733" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009734 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009735" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009736 let treedir= ""
9737 endif
9738 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009739" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9740" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009741 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9742 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9743 let treedir= dirname.treedir
9744 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009745" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009746 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009747" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009748 if a:treetop =~ '/$'
9749 let treedir= a:treetop.treedir
9750 else
9751 let treedir= a:treetop.'/'.treedir
9752 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009753" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009754 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009755" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009756" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9757 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009758" call Dret("s:NetrwTreePath <".treedir.">")
9759 return treedir
9760endfun
9761
9762" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009763" s:NetrwWideListing: {{{2
9764fun! s:NetrwWideListing()
9765
9766 if w:netrw_liststyle == s:WIDELIST
9767" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9768 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009769 " cpf: characters per filename
9770 " fpl: filenames per line
9771 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009772 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009773 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009774" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009775 let b:netrw_cpf= 0
9776 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009777 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009778 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9779 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009780 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009781 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009782" call Dret("NetrwWideListing")
9783 return
9784 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009785 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009786 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009787" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009788
9789 " determine qty files per line (fpl)
9790 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9791 if w:netrw_fpl <= 0
9792 let w:netrw_fpl= 1
9793 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009794" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795
9796 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009797 " fpc: files per column of wide listing
9798 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009799 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009800 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9801 let newcolstart = w:netrw_bannercnt + fpc
9802 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009803" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009804 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009805" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009806 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009807 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009808 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009809 while line("$") >= newcolstart
9810 if newcolend > line("$") | let newcolend= line("$") | endif
9811 let newcolqty= newcolend - newcolstart
9812 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009813 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009814 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009815 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009816 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009817 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009818 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009819 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009820 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009821 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009822 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009823" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009824 if @* != keepregstar | sil! let @* = keepregstar | endif
9825 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009826 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009827 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9828 NetrwKeepj call histdel("/",-1)
9829 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9830 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009831" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009832 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009833 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009834" 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 +00009835" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009836 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009837 else
9838 if hasmapto("w","n")
9839 sil! nunmap <buffer> w
9840 endif
9841 if hasmapto("b","n")
9842 sil! nunmap <buffer> b
9843 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009844 endif
9845
9846endfun
9847
9848" ---------------------------------------------------------------------
9849" s:PerformListing: {{{2
9850fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009851" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9852" 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 +02009853" 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>"))
9854 sil! NetrwKeepj %d _
9855" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009856
Bram Moolenaar15146672011-10-20 22:22:38 +02009857 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009858" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009859 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009860
Bram Moolenaar85850f32019-07-19 22:05:51 +02009861 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009862 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009863" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009864
9865" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009866" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009867" endif " Decho
9868
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009869" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009870 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9871 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009872" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9873 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009874 endif
9875
9876 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009877 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009878
9879 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009880 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009881" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009882 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009883 if exists("g:netrw_pchk")
9884 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9885 " failure detections.
9886 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009887 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009888 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9889 endif
9890 if exists("g:netrw_pchk")
9891 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9892 else
9893 let curdir= b:netrw_curdir
9894 endif
9895 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9896 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9897 else
9898 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009899 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009900 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009901 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009902 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009903" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009904 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009905 let w:netrw_bannercnt= 1
9906 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009907" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9908" 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 +00009909
Bram Moolenaar85850f32019-07-19 22:05:51 +02009910 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009911 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009912 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009913 let sortby= sortby." reversed"
9914 endif
9915
9916 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009917 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009918" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009919 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009920" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009921 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009922 NetrwKeepj put ='\" Sorted by '.sortby
9923 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009924 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9925 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009926" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009927 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009928 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009929 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9930 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009931 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009932" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009933" 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 +00009934 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009935
Bram Moolenaar85850f32019-07-19 22:05:51 +02009936 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009937 if g:netrw_banner
9938 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009939" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009940 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009941 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009942 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009943 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009944 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009945 endif
9946 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009947 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009948" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009949 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009950 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009951 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009952
9953 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009954 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009955" 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 +01009956 if g:netrw_list_hide != "" && g:netrw_hide
9957 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009958 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009959 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009960 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009961 endif
9962 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009963 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009964 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009965
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009966" 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 +01009967 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009968" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009969 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009970" 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 +01009971 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009972 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009973" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009974" 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 +00009975 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009976
9977 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009978 if g:netrw_banner
9979 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009980 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009981" 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 +01009982" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009983" 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 +01009984 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009985
Bram Moolenaar446cb832008-06-24 21:56:24 +00009986 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009987" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009988 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009989 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009990 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009991 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009992 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009993" 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 +01009994" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9995 return
9996 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009997 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009998
9999 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010000 if !exists("w:netrw_bannercnt")
10001 let w:netrw_bannercnt= 0
10002 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010003" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10004" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10005" 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 +010010006
Bram Moolenaar5c736222010-01-06 20:54:52 +010010007 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010008" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010009" 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 +000010010 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010011 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010012 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010013 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010014" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010015
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010016 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010017 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010018" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010019 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010020
Bram Moolenaar5c736222010-01-06 20:54:52 +010010021 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010022" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010023 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010024 " name: sort by name of file
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 else
10027 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010028 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010029 endif
10030 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010031
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010033" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010034 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10035 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010036
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010037 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010038 " exten: sort by extension
10039 " The histdel(...,-1) calls remove the last search from the search history
10040" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010041 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10042 NetrwKeepj call histdel("/",-1)
10043 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10044 NetrwKeepj call histdel("/",-1)
10045 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10046 NetrwKeepj call histdel("/",-1)
10047 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10048" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010049 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010050 " normal direction sorting
10051 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10052 else
10053 " reverse direction sorting
10054 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10055 endif
10056 endif
10057 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10058 NetrwKeepj call histdel("/",-1)
10059
Bram Moolenaar446cb832008-06-24 21:56:24 +000010060 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010061 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010062" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010063 if g:netrw_sort_direction =~# 'n'
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 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010067" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010068 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010069 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010070" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010071 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10072 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010073 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010074 endif
10075
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010076 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010077" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010078 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010079 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010080 call histdel("/",-1)
10081 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010082 endif
10083 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010084" 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 +000010085
10086 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010087" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10088" 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 +010010089 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010090" 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 +010010091 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010092" 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 +000010093
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010094 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010095 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010096" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010097 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010098 endif
10099
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010100 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010101 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010102" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10103 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010104 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010105" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10106 else
10107" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10108" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10109" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10110" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010111 endif
10112
10113 " record previous current directory
10114 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010115" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010116
10117 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010118" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10119" 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 +010010120 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010121" 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 +020010122 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010123" 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 +000010124
10125 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010126" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010127 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010128" 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 +010010129 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010130" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010131 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10132 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010133" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010134" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010135
Bram Moolenaar8d043172014-01-23 14:24:41 +010010136 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010137" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10138" 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 +010010139" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10140 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010141 unlet s:treecurpos
10142 endif
10143
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010144" 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>"))
10145" 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 +000010146" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10147endfun
10148
10149" ---------------------------------------------------------------------
10150" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010151fun! s:SetupNetrwStatusLine(statline)
10152" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10153
10154 if !exists("s:netrw_setup_statline")
10155 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010156" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010157
10158 if !exists("s:netrw_users_stl")
10159 let s:netrw_users_stl= &stl
10160 endif
10161 if !exists("s:netrw_users_ls")
10162 let s:netrw_users_ls= &laststatus
10163 endif
10164
10165 " set up User9 highlighting as needed
10166 let keepa= @a
10167 redir @a
10168 try
10169 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010170 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010171 if &bg == "dark"
10172 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10173 else
10174 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10175 endif
10176 endtry
10177 redir END
10178 let @a= keepa
10179 endif
10180
10181 " set up status line (may use User9 highlighting)
10182 " insure that windows have a statusline
10183 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010184 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010185 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010186" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010187 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010188
10189" call Dret("SetupNetrwStatusLine : stl=".&stl)
10190endfun
10191
Bram Moolenaar85850f32019-07-19 22:05:51 +020010192" =========================================
10193" Remote Directory Browsing Support: {{{1
10194" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010195
10196" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010197" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10198" This function assumes that a long listing will be received. Size, time,
10199" and reverse sorts will be requested of the server but not otherwise
10200" enforced here.
10201fun! s:NetrwRemoteFtpCmd(path,listcmd)
10202" 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 +010010203" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010204 " sanity check: {{{3
10205 if !exists("w:netrw_method")
10206 if exists("b:netrw_method")
10207 let w:netrw_method= b:netrw_method
10208 else
10209 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10210" call Dret("NetrwRemoteFtpCmd")
10211 return
10212 endif
10213 endif
10214
10215 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10216 let ffkeep= &ff
10217 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010218" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010219
10220 " clear off any older non-banner lines " {{{3
10221 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010222" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10223 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010224
10225 ".........................................
10226 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10227 " ftp + <.netrc>: Method #2
10228 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010229 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010230 endif
10231 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010232 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010233" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010234 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010235 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010236" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010237 if exists("g:netrw_port") && g:netrw_port != ""
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)." ".s:ShellEscape(g:netrw_port,1),'~'.expand("<slnum>"))
10239 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 +010010240 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010241" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10242 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 +010010243 endif
10244
10245 ".........................................
10246 elseif w:netrw_method == 3 " {{{3
10247 " ftp + machine,id,passwd,filename: Method #3
10248 setl ff=unix
10249 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010250 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010251 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010252 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010253 endif
10254
10255 " handle userid and password
10256 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010257" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010258 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10259 call NetUserPass("ftp:".host)
10260 endif
10261 if exists("g:netrw_uid") && g:netrw_uid != ""
10262 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010263 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010264 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010265 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010266 endif
10267 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010268 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010269 endif
10270 endif
10271
10272 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010273 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010274 endif
10275 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010276 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010277" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010278 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010279 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010280
10281 " perform ftp:
10282 " -i : turns off interactive prompting from ftp
10283 " -n unix : DON'T use <.netrc>, even though it exists
10284 " -n win32: quit being obnoxious about password
10285 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010286" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010287 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010288" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010289" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10290" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010291 endif
10292
10293 ".........................................
10294 elseif w:netrw_method == 9 " {{{3
10295 " sftp username@machine: Method #9
10296 " s:netrw_sftp_cmd
10297 setl ff=unix
10298
10299 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010300 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010301" call Dret("NetrwRemoteFtpCmd")
10302 return
10303
10304 ".........................................
10305 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010306 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010307 endif
10308
10309 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010310 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010311 sil! NetrwKeepj %s/\r$//e
10312 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010313 endif
10314 if a:listcmd == "dir"
10315 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010316 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10317 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10318 NetrwKeepj call histdel("/",-1)
10319 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010320 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 +010010321 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10322 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010323 endif
10324 endif
10325
10326 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10327 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010328 exe 'NetrwKeepj '.w:netrw_bannercnt
10329 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010330 endif
10331 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010332 exe 'NetrwKeepj '.w:netrw_bannercnt
10333 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010334 endif
10335
10336 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010337 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010338" call Dret("NetrwRemoteFtpCmd")
10339endfun
10340
10341" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010342" s:NetrwRemoteListing: {{{2
10343fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010344" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010345
Bram Moolenaara6878372014-03-22 21:02:50 +010010346 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10347 let w:netrw_bannercnt= s:bannercnt
10348 endif
10349 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010350 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010351 endif
10352
Bram Moolenaar446cb832008-06-24 21:56:24 +000010353 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010354
Bram Moolenaar446cb832008-06-24 21:56:24 +000010355 " sanity check:
10356 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010357" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010358 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010359" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010360 if !exists("g:netrw_quiet")
10361 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10362 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010363 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010364" call Dret("s:NetrwRemoteListing -1")
10365 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010366 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010367
Bram Moolenaar8d043172014-01-23 14:24:41 +010010368 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010369" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010370 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010371 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010372 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 +000010373 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010374 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 +000010375 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010376 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010377
Bram Moolenaar85850f32019-07-19 22:05:51 +020010378 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010379" call Dret("s:NetrwRemoteListing -1")
10380 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010381 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010382" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010383
Bram Moolenaar446cb832008-06-24 21:56:24 +000010384 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010385" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010386 let w:netrw_method= b:netrw_method
10387 endif
10388
Bram Moolenaar13600302014-05-22 18:26:40 +020010389 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010390 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010391" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010392 let s:method = "ftp"
10393 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010394 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010395 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010396 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 let listcmd= g:netrw_ftp_sizelist_cmd
10398 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010399" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010400 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010401" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010402
Bram Moolenaara6878372014-03-22 21:02:50 +010010403 " report on missing file or directory messages
10404 if search('[Nn]o such file or directory\|Failed to change directory')
10405 let mesg= getline(".")
10406 if exists("w:netrw_bannercnt")
10407 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010408 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010409 setl noma
10410 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010411 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010412 call netrw#ErrorMsg(s:WARNING,mesg,96)
10413" call Dret("s:NetrwRemoteListing : -1")
10414 return -1
10415 endif
10416
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010417 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 +000010418 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010419" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010420 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010421
10422 " cleanup
10423 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010424 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10425 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010426 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010427 sil! NetrwKeepj %s/\r$//e
10428 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010429
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010430 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010431 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010432 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010433 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010434" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010435 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010436" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010437 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010438 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010439 exe "sil! NetrwKeepj ".line1
10440 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010441
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010442" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010443 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010444" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010445 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10446 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010448" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010449 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10450 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10451 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10452 NetrwKeepj call histdel("/",-1)
10453 NetrwKeepj call histdel("/",-1)
10454 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010455 endif
10456 endif
10457
Bram Moolenaar13600302014-05-22 18:26:40 +020010458 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010459 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010460" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010461 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010462" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010463 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010464" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10465 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010466 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010467 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10468 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10469 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10470 NetrwKeepj call histdel("/",-1)
10471 NetrwKeepj call histdel("/",-1)
10472 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010473 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010474 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10475 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010476 endif
10477 else
10478 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010479" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010480 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010481 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010482" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10483 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10484" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010485 endif
10486 endif
10487
10488 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010489 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010490" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010491 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10492 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010493 endif
10494 endif
10495
10496 if w:netrw_liststyle == s:LONGLIST
10497 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010498" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010499
10500 if s:method == "ftp"
10501 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010502 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010503 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010504 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010505 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010506 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010507 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010508 sil! NetrwKeepj 1
10509 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010510 let line2= line(".")
10511 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010512 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010513 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514 endif
10515 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010516 exe "sil! NetrwKeepj ".line1
10517 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010518 endif
10519
10520 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010521" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010522 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 +000010523 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010524" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010525 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010526 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010527 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10528 NetrwKeepj call histdel("/",-1)
10529 NetrwKeepj call histdel("/",-1)
10530 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531 endif
10532 endif
10533
10534" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010535" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010536" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010537
10538" call Dret("s:NetrwRemoteListing 0")
10539 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010540endfun
10541
Bram Moolenaar446cb832008-06-24 21:56:24 +000010542" ---------------------------------------------------------------------
10543" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10544fun! s:NetrwRemoteRm(usrhost,path) range
10545" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010546" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010547 let svpos= winsaveview()
10548" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010549
10550 let all= 0
10551 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10552 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010553" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010554 for fname in s:netrwmarkfilelist_{bufnr("%")}
10555 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010556 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010557 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010558 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010559 let all= 1
10560 endif
10561 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010562 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010563
10564 else
10565 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010566" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010567
10568 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010569 let keepsol = &l:sol
10570 setl nosol
10571 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010572
10573 " remove multiple files and directories
10574 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010575 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010576 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010577 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010579 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010580 let all= 1
10581 endif
10582 let ctr= ctr + 1
10583 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010584 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010585 endif
10586
10587 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010588" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010589 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010590" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10591 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010592
10593" call Dret("s:NetrwRemoteRm")
10594endfun
10595
10596" ---------------------------------------------------------------------
10597" s:NetrwRemoteRmFile: {{{2
10598fun! s:NetrwRemoteRmFile(path,rmfile,all)
10599" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10600
10601 let all= a:all
10602 let ok = ""
10603
10604 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10605 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010606" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010607 if !all
10608 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010609" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010610 call inputsave()
10611 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10612 call inputrestore()
10613 echohl NONE
10614 if ok == ""
10615 let ok="no"
10616 endif
10617 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010618 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010619 let all= 1
10620 endif
10621 endif
10622
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010623 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010624" 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 +000010625 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010626" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010627 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010628 if path =~ '^\a\{3,}://'
10629 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010630 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010631 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010632 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10633 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010634" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010635 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010636" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010637 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010638 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010639 let ok="q"
10640 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010641 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010642" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10643" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10644" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010645 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010646 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010647 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010648 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010649 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010650" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010651 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010652 if v:shell_error != 0
10653 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010654 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 +010010655 else
10656 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10657 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010658 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010659 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010660 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010661" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010662 endif
10663 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010664 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010665" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010666 endif
10667
10668 else
10669 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010670" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010671 if !all
10672 call inputsave()
10673 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10674 call inputrestore()
10675 if ok == ""
10676 let ok="no"
10677 endif
10678 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010679 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010680 let all= 1
10681 endif
10682 endif
10683
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010684 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010685 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010686 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010687 else
10688 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010689 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10690" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010691 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010692" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010693
10694 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010695" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10696 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10697" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010698 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010699" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010700
10701 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010702 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010703 endif
10704 endif
10705 endif
10706
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010707 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010708" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010709 endif
10710 endif
10711
10712" call Dret("s:NetrwRemoteRmFile ".ok)
10713 return ok
10714endfun
10715
10716" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010717" s:NetrwRemoteRename: rename a remote file or directory {{{2
10718fun! s:NetrwRemoteRename(usrhost,path) range
10719" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10720
10721 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010722 let svpos = winsaveview()
10723" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010724 let ctr = a:firstline
10725 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10726
10727 " rename files given by the markfilelist
10728 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10729 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010730" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010731 if exists("subfrom")
10732 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010733" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010734 else
10735 call inputsave()
10736 let newname= input("Moving ".oldname." to : ",oldname)
10737 call inputrestore()
10738 if newname =~ '^s/'
10739 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10740 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10741 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010742" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010743 endif
10744 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010745
Bram Moolenaar446cb832008-06-24 21:56:24 +000010746 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010747 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010748 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010749 let oldname= s:ShellEscape(a:path.oldname)
10750 let newname= s:ShellEscape(a:path.newname)
10751" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010752 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010753 endif
10754
10755 endfor
10756 call s:NetrwUnMarkFile(1)
10757
10758 else
10759
10760 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010761 let keepsol= &l:sol
10762 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010763 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010764 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010765
10766 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010767" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010768
10769 call inputsave()
10770 let newname= input("Moving ".oldname." to : ",oldname)
10771 call inputrestore()
10772
10773 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10774 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10775 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010776 let oldname= s:ShellEscape(a:path.oldname)
10777 let newname= s:ShellEscape(a:path.newname)
10778" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010779 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010780 endif
10781
10782 let ctr= ctr + 1
10783 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010784 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010785 endif
10786
10787 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010788 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010789" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10790 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010791
10792" call Dret("NetrwRemoteRename")
10793endfun
10794
Bram Moolenaar85850f32019-07-19 22:05:51 +020010795" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010796" Local Directory Browsing Support: {{{1
10797" ==========================================
10798
10799" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010800" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010801" Should accept: file://localhost/etc/fstab
10802" file:///etc/fstab
10803" file:///c:/WINDOWS/clock.avi
10804" file:///c|/WINDOWS/clock.avi
10805" file://localhost/c:/WINDOWS/clock.avi
10806" file://localhost/c|/WINDOWS/clock.avi
10807" file://c:/foo.txt
10808" file:///c:/foo.txt
10809" 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 +020010810fun! netrw#FileUrlEdit(fname)
10811" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010812 let fname = a:fname
10813 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010814" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010815 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010816" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010817 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010818 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010819 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010820" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010821 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010822" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010823 endif
10824 endif
10825 let fname2396 = netrw#RFC2396(fname)
10826 let fname2396e= fnameescape(fname2396)
10827 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010828 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010829" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010830 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010831" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010832 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10833 endif
10834 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010835
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010836" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10837" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010838 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010839 exe 'NetrwKeepj keepalt edit '.plainfname
10840 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10841
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010842" 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 +020010843" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010844 exe "sil doau BufReadPost ".fname2396e
10845endfun
10846
10847" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010848" netrw#LocalBrowseCheck: {{{2
10849fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010850 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010851 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10852 "
10853 " unfortunate interaction -- split window debugging can't be used here, must use
10854 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10855 " another call to LocalBrowseCheck() when attempts to write
10856 " to the DBG buffer are made.
10857 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010858 " The &ft == "netrw" test was installed because the BufEnter event
10859 " would hit when re-entering netrw windows, creating unexpected
10860 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010861" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010862" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010863" 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 +010010864 " getting E930: Cannot use :redir inside execute
10865"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010866" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10867" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010868
Bram Moolenaar97d62492012-11-15 21:28:22 +010010869 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010870 if isdirectory(s:NetrwFile(a:dirname))
10871" 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 +010010872
Bram Moolenaar97d62492012-11-15 21:28:22 +010010873 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010874" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10875" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010876 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010877
Bram Moolenaar446cb832008-06-24 21:56:24 +000010878 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010879" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010880 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010881
Bram Moolenaar5c736222010-01-06 20:54:52 +010010882 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010883" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010884 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010885 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010886 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010887" 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 +010010888" call Dret("netrw#LocalBrowseCheck")
10889 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010890 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010891
Bram Moolenaar85850f32019-07-19 22:05:51 +020010892 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010893 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10894 " AND IF the listing style is not a tree listing
10895 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010896" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010897 let ibuf = 1
10898 let buflast = bufnr("$")
10899 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010900 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10901 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010902 endif
10903 let ibuf= ibuf + 1
10904 endwhile
10905 endif
10906 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010907" 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>"))
10908" 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 +000010909 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010910" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010911endfun
10912
10913" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010914" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010915" performed any shell command. The idea is to cause all local-browsing
10916" buffers to be refreshed after a user has executed some shell command,
10917" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010918fun! s:LocalBrowseRefresh()
10919" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010920" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10921" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010922
Bram Moolenaar446cb832008-06-24 21:56:24 +000010923 " determine which buffers currently reside in a tab
10924 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010925" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010926 return
10927 endif
10928 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010929" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010930 return
10931 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010932 if !empty(getcmdwintype())
10933 " cannot move away from cmdline window, see :h E11
10934 return
10935 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010936 if exists("s:netrw_events") && s:netrw_events == 1
10937 " s:LocalFastBrowser gets called (indirectly) from a
10938 let s:netrw_events= 2
10939" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10940 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010941 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010942 let itab = 1
10943 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010944 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010945 while itab <= tabpagenr("$")
10946 let buftablist = buftablist + tabpagebuflist()
10947 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010948 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010949 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010950" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10951" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010952 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10953 " | refresh any netrw window
10954 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010955 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010956 let ibl = 0
10957 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010958" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010959 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10960 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010961 " (ibuf not shown in a current window AND
10962 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010963" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10964 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010966" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010967 continue
10968 elseif index(tabpagebuflist(),ibuf) != -1
10969 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010970" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010971 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010972 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010973 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10974 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10975 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10976 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010977" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010978 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10979 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10980 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010981 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010982 endif
10983 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010984" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010985 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010986" call Decho("restore window: win_gotoid(".curwinid.")")
10987 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010988 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010989
Bram Moolenaara6878372014-03-22 21:02:50 +010010990" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010991endfun
10992
10993" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010994" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10995"
10996" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010997" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010998" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10999" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011000" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011001"
11002" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11003" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011004" (re-using a buffer may not be as accurate)
11005"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011006" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011007" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11008" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11009" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11010" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011011fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011012" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11013" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11014" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11015" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011016
11017 " initialize browselist, a list of buffer numbers that the local browser has used
11018 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011019" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011020 let s:netrw_browselist= []
11021 endif
11022
11023 " append current buffer to fastbrowse list
11024 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011025" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011026 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011027" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011028 endif
11029
11030 " enable autocmd events to handle refreshing/removing local browser buffers
11031 " If local browse buffer is currently showing: refresh it
11032 " If local browse buffer is currently hidden : wipe it
11033 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11034 " =1 : medium speed, re-use directory listing for remote only
11035 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011036 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11037 let s:netrw_events= 1
11038 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011039 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011040 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011041" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011042 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011043 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011044" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011045 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011046 endif
11047 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011048
11049 " user must have changed fastbrowse to its fast setting, so remove
11050 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011051 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011052" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011053 unlet s:netrw_events
11054 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011055 au!
11056 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011057 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011058 endif
11059
Bram Moolenaar85850f32019-07-19 22:05:51 +020011060" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011061endfun
11062
11063" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011064" s:LocalListing: does the job of "ls" for local directories {{{2
11065fun! s:LocalListing()
11066" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011067" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11068" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11069" 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 +010011070
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011071" 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
11072" 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
11073" 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 +010011074
11075 " get the list of files contained in the current directory
11076 let dirname = b:netrw_curdir
11077 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011078 let filelist = s:NetrwGlob(dirname,"*",0)
11079 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011080" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011081
Nir Lichtman1e34b952024-05-08 19:19:34 +020011082 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011083" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011084 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11085 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011086" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011087 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011088" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011089 endif
11090
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011091" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011092" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011093" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011094
11095 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11096 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11097 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011098" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11099" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011100 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011101" 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 +010011102
11103 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011104" call Decho(" ",'~'.expand("<slnum>"))
11105" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011106
11107 if getftype(filename) == "link"
11108 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011109" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011110 let pfile= filename."@"
11111
11112 elseif getftype(filename) == "socket"
11113 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011114" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011115 let pfile= filename."="
11116
11117 elseif getftype(filename) == "fifo"
11118 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011119" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011120 let pfile= filename."|"
11121
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011122 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011123 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011124" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011125 let pfile= filename."/"
11126
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011127 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011128 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011129 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11130 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011131" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011132 let pfile= filename."*"
11133 else
11134 " normal file
11135 let pfile= filename
11136 endif
11137 elseif executable(filename)
11138 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011139" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011140 let pfile= filename."*"
11141 else
11142 " normal file
11143 let pfile= filename
11144 endif
11145
11146 else
11147 " normal file
11148 let pfile= filename
11149 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011150" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011151
11152 if pfile =~ '//$'
11153 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011154" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011155 endif
11156 let pfile= strpart(pfile,dirnamelen)
11157 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011158" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11159" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011160
11161 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011162 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11163 let sz = getfsize(filename)
11164 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11165 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011166
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011167 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011168 let sz= s:NetrwHumanReadable(sz)
11169 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011170 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011171 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011172" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011173 endif
11174
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011175 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011176 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011177 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011178" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011179" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011180 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011181 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011182" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011183 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011184 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011185
11186 elseif g:netrw_sort_by =~ "^s"
11187 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011188" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011189" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011190 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011191 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011192" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011193 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011194 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011195
11196 else
11197 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011198" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011199" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011200 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011201 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011202" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011203 endfor
11204
11205 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011206 sil! NetrwKeepj g/^$/d
11207 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011208 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011209" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011210 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11211
11212" call Dret("s:LocalListing")
11213endfun
11214
11215" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011216" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11217fun! s:NetrwLocalExecute(cmd)
11218" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11219 let ykeep= @@
11220 " sanity check
11221 if !executable(a:cmd)
11222 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11223 let @@= ykeep
11224" call Dret("s:NetrwLocalExecute")
11225 return
11226 endif
11227
11228 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011229" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011230 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011231" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011232
11233 " strip any ansi escape sequences off
11234 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11235
11236 " show user the result(s)
11237 echomsg result
11238 let @@= ykeep
11239
11240" call Dret("s:NetrwLocalExecute")
11241endfun
11242
11243" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011244" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011245fun! s:NetrwLocalRename(path) range
11246" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11247
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011248 if !exists("w:netrw_bannercnt")
11249 let w:netrw_bannercnt= b:netrw_bannercnt
11250 endif
11251
Bram Moolenaar97d62492012-11-15 21:28:22 +010011252 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011253 let ykeep = @@
11254 let ctr = a:firstline
11255 let svpos = winsaveview()
11256 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011257" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011258
11259 " rename files given by the markfilelist
11260 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11261 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011262" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011263 if exists("subfrom")
11264 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011265" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011266 else
11267 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011268 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011269 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011270 if newname =~ ''
11271 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11272 let newname = substitute(newname,'^.*','','')
11273 elseif newname =~ ''
11274 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11275 let newname = substitute(newname,'[^/]*','','')
11276 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011277 if newname =~ '^s/'
11278 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11279 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011280" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011281 let newname = substitute(oldname,subfrom,subto,'')
11282 endif
11283 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011284 if !all && filereadable(newname)
11285 call inputsave()
11286 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11287 call inputrestore()
11288 if response == "all"
11289 let all= 1
11290 elseif response != "y" && response != "yes"
11291 " refresh the directory
11292" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11293 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11294" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11295 NetrwKeepj call winrestview(svpos)
11296 let @@= ykeep
11297" call Dret("NetrwLocalRename")
11298 return
11299 endif
11300 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011301 call rename(oldname,newname)
11302 endfor
11303 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011304
Bram Moolenaar97d62492012-11-15 21:28:22 +010011305 else
11306
11307 " attempt to rename files/directories
11308 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011309 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011310
11311 " sanity checks
11312 if line(".") < w:netrw_bannercnt
11313 let ctr= ctr + 1
11314 continue
11315 endif
11316 let curword= s:NetrwGetWord()
11317 if curword == "./" || curword == "../"
11318 let ctr= ctr + 1
11319 continue
11320 endif
11321
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011322 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011323 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011324" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011325
11326 call inputsave()
11327 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11328 call inputrestore()
11329
11330 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011331" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011332
11333 let ctr= ctr + 1
11334 endwhile
11335 endif
11336
11337 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011338" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011339 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011340" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11341 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011342 let @@= ykeep
11343
11344" call Dret("NetrwLocalRename")
11345endfun
11346
11347" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011348" s:NetrwLocalRm: {{{2
11349fun! s:NetrwLocalRm(path) range
11350" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011351" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011352
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011353 if !exists("w:netrw_bannercnt")
11354 let w:netrw_bannercnt= b:netrw_bannercnt
11355 endif
11356
Bram Moolenaar446cb832008-06-24 21:56:24 +000011357 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011358 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011359 let ret = 0
11360 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011361 let svpos = winsaveview()
11362" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011363
11364 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11365 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011366" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011367 for fname in s:netrwmarkfilelist_{bufnr("%")}
11368 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011369 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011370 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011371 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011372 let all= 1
11373 endif
11374 endfor
11375 call s:NetrwUnMarkFile(1)
11376
11377 else
11378 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011379" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011380
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011381 let keepsol= &l:sol
11382 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011383 let ctr = a:firstline
11384 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011385 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011386
11387 " sanity checks
11388 if line(".") < w:netrw_bannercnt
11389 let ctr= ctr + 1
11390 continue
11391 endif
11392 let curword= s:NetrwGetWord()
11393 if curword == "./" || curword == "../"
11394 let ctr= ctr + 1
11395 continue
11396 endif
11397 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011398 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011399 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011400 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011401 let all= 1
11402 endif
11403 let ctr= ctr + 1
11404 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011405 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011406 endif
11407
11408 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011409" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011410 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011411 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011412" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11413 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011414 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011415 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011416
11417" call Dret("s:NetrwLocalRm")
11418endfun
11419
11420" ---------------------------------------------------------------------
11421" s:NetrwLocalRmFile: remove file fname given the path {{{2
11422" Give confirmation prompt unless all==1
11423fun! s:NetrwLocalRmFile(path,fname,all)
11424" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011425
Bram Moolenaar446cb832008-06-24 21:56:24 +000011426 let all= a:all
11427 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011428 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011429 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11430" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011431
11432 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11433 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011434" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011435 if !all
11436 echohl Statement
11437 call inputsave()
11438 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11439 call inputrestore()
11440 echohl NONE
11441 if ok == ""
11442 let ok="no"
11443 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011444" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011445 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011446" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011447 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011448 let all= 1
11449 endif
11450 endif
11451
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011452 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011453 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011454" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011455 endif
11456
11457 else
11458 " attempt to remove directory
11459 if !all
11460 echohl Statement
11461 call inputsave()
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011462 let ok= input("Confirm *recursive* deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011463 call inputrestore()
11464 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11465 if ok == ""
11466 let ok="no"
11467 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011468 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011469 let all= 1
11470 endif
11471 endif
11472 let rmfile= substitute(rmfile,'[\/]$','','e')
11473
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011474 if all || ok =~# 'y\%[es]' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011475 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011476 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011477 endif
11478 endif
11479 endif
11480
11481" call Dret("s:NetrwLocalRmFile ".ok)
11482 return ok
11483endfun
11484
Bram Moolenaar85850f32019-07-19 22:05:51 +020011485" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011486" Support Functions: {{{1
11487
Bram Moolenaar488c6512005-08-11 20:09:58 +000011488" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011489" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11490" 0: marked file list of current buffer
11491" 1: marked file target
11492fun! netrw#Access(ilist)
11493 if a:ilist == 0
11494 if exists("s:netrwmarkfilelist_".bufnr('%'))
11495 return s:netrwmarkfilelist_{bufnr('%')}
11496 else
11497 return "no-list-buf#".bufnr('%')
11498 endif
11499 elseif a:ilist == 1
11500 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011501 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011502endfun
11503
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011504" ---------------------------------------------------------------------
11505" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11506fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011507 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011508endfun
11509
Bram Moolenaara6878372014-03-22 21:02:50 +010011510" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011511" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11512" I expect this function to be used in
11513" :PChkAssert netrw#Expose("netrwmarkfilelist")
11514" for example.
11515fun! netrw#Expose(varname)
11516" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011517 if exists("s:".a:varname)
11518 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011519" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011520 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011521" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011522 if type(retval) == 3
11523 let retval = copy(retval)
11524 let i = 0
11525 while i < len(retval)
11526 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11527 let i = i + 1
11528 endwhile
11529 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011530" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011531 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011532 else
11533" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011534 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011535 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011536" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011537 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011538 endif
11539
11540" call Dret("netrw#Expose ".string(retval))
11541 return retval
11542endfun
11543
11544" ---------------------------------------------------------------------
11545" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11546fun! netrw#Modify(varname,newvalue)
11547" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11548 exe "let s:".a:varname."= ".string(a:newvalue)
11549" call Dret("netrw#Modify")
11550endfun
11551
11552" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011553" netrw#RFC2396: converts %xx into characters {{{2
11554fun! netrw#RFC2396(fname)
11555" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011556 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011557" call Dret("netrw#RFC2396 ".fname)
11558 return fname
11559endfun
11560
11561" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011562" netrw#UserMaps: supports user-specified maps {{{2
11563" see :help function()
11564"
11565" g:Netrw_UserMaps is a List with members such as:
11566" [[keymap sequence, function reference],...]
11567"
11568" The referenced function may return a string,
11569" refresh : refresh the display
11570" -other- : this string will be executed
11571" or it may return a List of strings.
11572"
11573" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011574" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011575" Related functions:
11576" netrw#Expose(varname) -- see s:varname variables
11577" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11578" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11579fun! netrw#UserMaps(islocal)
11580" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11581" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11582
11583 " set up usermaplist
11584 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11585" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11586 for umap in g:Netrw_UserMaps
11587" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11588" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11589 " if umap[0] is a string and umap[1] is a string holding a function name
11590 if type(umap[0]) == 1 && type(umap[1]) == 1
11591" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11592 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11593 else
11594 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11595 endif
11596 endfor
11597 endif
11598" call Dret("netrw#UserMaps")
11599endfun
11600
11601" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011602" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11603fun! netrw#WinPath(path)
11604" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011605 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011606 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011607 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011608 " remove trailing slash (Win95)
11609 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11610 " remove escaped spaces
11611 let path = substitute(path, '\ ', ' ', 'g')
11612 " convert slashes to backslashes
11613 let path = substitute(path, '/', '\', 'g')
11614 else
11615 let path= a:path
11616 endif
11617" call Dret("netrw#WinPath <".path.">")
11618 return path
11619endfun
11620
11621" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011622" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11623" cb : bl2mf=0 add marked files to buffer list
11624" cB : bl2mf=1 use bufferlist to mark files
11625" (mnemonic: cb = copy (marked files) to buffer list)
11626fun! s:NetrwBadd(islocal,bl2mf)
11627" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11628 if a:bl2mf
11629 " cB: add buffer list to marked files
11630 redir => bufl
11631 ls
11632 redir END
11633 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11634 for fname in bufl
11635 call s:NetrwMarkFile(a:islocal,fname)
11636 endfor
11637 else
11638 " cb: add marked files to buffer list
11639 for fname in s:netrwmarkfilelist_{bufnr("%")}
11640" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11641 exe "badd ".fnameescape(fname)
11642 endfor
11643 let curbufnr = bufnr("%")
11644 let curdir = s:NetrwGetCurdir(a:islocal)
11645 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11646 endif
11647" call Dret("s:NetrwBadd")
11648endfun
11649
11650" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011651" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11652fun! s:ComposePath(base,subdir)
11653" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11654
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011655 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011656" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011657 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011658 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011659 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011660 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011661 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011662 endif
11663
Bram Moolenaar85850f32019-07-19 22:05:51 +020011664 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011665 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011666" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011667 let ret= a:subdir
11668
Nir Lichtman1e34b952024-05-08 19:19:34 +020011669 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011670" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011671 if a:base =~ '[/\\]$'
11672 let ret= a:base.a:subdir
11673 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011674 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011675 endif
11676
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011677 elseif a:base =~ '^\a\{3,}://'
11678" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011679 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11680 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11681 if a:subdir == '../'
11682 if curpath =~ '[^/]/[^/]\+/$'
11683 let curpath= substitute(curpath,'[^/]\+/$','','')
11684 else
11685 let curpath=""
11686 endif
11687 let ret= urlbase.curpath
11688 else
11689 let ret= urlbase.curpath.a:subdir
11690 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011691" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11692" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11693" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011694
11695 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011696" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011697 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11698 if a:base =~ '^//'
11699 " keeping initial '//' for the benefit of network share listing support
11700 let ret= '/'.ret
11701 endif
11702 let ret= simplify(ret)
11703 endif
11704
11705" call Dret("s:ComposePath ".ret)
11706 return ret
11707endfun
11708
11709" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011710" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11711" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11712fun! s:DeleteBookmark(fname)
11713" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11714 call s:MergeBookmarks()
11715
11716 if exists("g:netrw_bookmarklist")
11717 let indx= index(g:netrw_bookmarklist,a:fname)
11718 if indx == -1
11719 let indx= 0
11720 while indx < len(g:netrw_bookmarklist)
11721 if g:netrw_bookmarklist[indx] =~ a:fname
11722 call remove(g:netrw_bookmarklist,indx)
11723 let indx= indx - 1
11724 endif
11725 let indx= indx + 1
11726 endwhile
11727 else
11728 " remove exact match
11729 call remove(g:netrw_bookmarklist,indx)
11730 endif
11731 endif
11732
11733" call Dret("s:DeleteBookmark")
11734endfun
11735
11736" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011737" s:FileReadable: o/s independent filereadable {{{2
11738fun! s:FileReadable(fname)
11739" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11740
11741 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011742 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011743 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011744 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011745 endif
11746
11747" call Dret("s:FileReadable ".ret)
11748 return ret
11749endfun
11750
11751" ---------------------------------------------------------------------
11752" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11753" Places correct suffix on end of temporary filename,
11754" using the suffix provided with fname
11755fun! s:GetTempfile(fname)
11756" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11757
11758 if !exists("b:netrw_tmpfile")
11759 " get a brand new temporary filename
11760 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011761" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011762
Bram Moolenaarc236c162008-07-13 17:41:49 +000011763 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011764" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011765
Bram Moolenaar9964e462007-05-05 17:54:07 +000011766 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011767 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11768" 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 +010011769 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011770" call Dret("s:GetTempfile getcwd<".getcwd().">")
11771 return ""
11772 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011773
Bram Moolenaar9964e462007-05-05 17:54:07 +000011774 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011775 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011776" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011777
Bram Moolenaar9964e462007-05-05 17:54:07 +000011778 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011779 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011780 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011781 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011782 if !exists("+shellslash") || !&ssl
11783 let tmpfile = substitute(tmpfile,'/','\','g')
11784 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011785 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011786 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011787 endif
11788 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011789" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011790 else
11791 " re-use temporary filename
11792 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011793" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011794 endif
11795
11796 " use fname's suffix for the temporary file
11797 if a:fname != ""
11798 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011799" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011800 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011801 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011802 elseif a:fname =~ '.txz$'
11803 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011804 else
11805 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11806 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011807" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011808 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011809" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011810 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011811" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011812 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11813 endif
11814 endif
11815
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011816" 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 +000011817" call Dret("s:GetTempfile <".tmpfile.">")
11818 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011819endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011820
11821" ---------------------------------------------------------------------
11822" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011823" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011824fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011825" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011826 if s:user == ""
11827 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11828 else
11829 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11830 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011831 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011832 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011833 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011834 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011835 else
11836 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11837 endif
11838" call Dret("s:MakeSshCmd <".sshcmd.">")
11839 return sshcmd
11840endfun
11841
11842" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011843" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11844fun! s:MakeBookmark(fname)
11845" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11846
11847 if !exists("g:netrw_bookmarklist")
11848 let g:netrw_bookmarklist= []
11849 endif
11850
11851 if index(g:netrw_bookmarklist,a:fname) == -1
11852 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011853 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011854 call add(g:netrw_bookmarklist,a:fname.'/')
11855 elseif a:fname !~ '/'
11856 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11857 else
11858 call add(g:netrw_bookmarklist,a:fname)
11859 endif
11860 call sort(g:netrw_bookmarklist)
11861 endif
11862
11863" call Dret("s:MakeBookmark")
11864endfun
11865
11866" ---------------------------------------------------------------------
11867" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11868fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011869" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011870 " get bookmarks from .netrwbook file
11871 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011872 if filereadable(s:NetrwFile(savefile))
11873" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011874 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011875" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011876 NetrwKeepj call delete(savefile)
11877 endif
11878" call Dret("s:MergeBookmarks")
11879endfun
11880
11881" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011882" s:NetrwBMShow: {{{2
11883fun! s:NetrwBMShow()
11884" call Dfunc("s:NetrwBMShow()")
11885 redir => bmshowraw
11886 menu
11887 redir END
11888 let bmshowlist = split(bmshowraw,'\n')
11889 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011890 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011891 if bmshowfuncs != []
11892 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011893 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011894 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011895 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011896 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011897 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011898" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11899endfun
11900
11901" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011902" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011903fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011904 if !exists("w:netrw_liststyle")
11905 let w:netrw_liststyle= g:netrw_liststyle
11906 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011907" 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 +020011908
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011909" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11910
Bram Moolenaaradc21822011-04-01 18:03:16 +020011911 if &ft != "netrw"
11912 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11913 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011914" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011915
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011916 elseif g:netrw_cursor == 8
11917 if w:netrw_liststyle == s:WIDELIST
11918 setl cursorline
11919 setl cursorcolumn
11920 else
11921 setl cursorline
11922 endif
11923 elseif g:netrw_cursor == 7
11924 setl cursorline
11925 elseif g:netrw_cursor == 6
11926 if w:netrw_liststyle == s:WIDELIST
11927 setl cursorline
11928 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011929 elseif g:netrw_cursor == 4
11930 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011931" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011932 setl cursorline
11933 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011934
11935 elseif g:netrw_cursor == 3
11936 " thin-long-tree: cursorline, user's cursorcolumn
11937 " wide : cursorline, cursorcolumn
11938 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011939" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011940 setl cursorline
11941 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011942 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011943" 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 +020011944 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011945 endif
11946
11947 elseif g:netrw_cursor == 2
11948 " thin-long-tree: cursorline, user's cursorcolumn
11949 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011950" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011951 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011952
11953 elseif g:netrw_cursor == 1
11954 " thin-long-tree: user's cursorline, user's cursorcolumn
11955 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011956 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011957" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011958 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011959 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011960" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011961 endif
11962
11963 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011964 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011965" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011966 let &l:cursorline = s:netrw_usercul
11967 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011968 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011969
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011970" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011971" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011972endfun
11973
11974" ---------------------------------------------------------------------
11975" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11976fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011977" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011978 if exists("s:netrw_usercul")
11979 let &l:cursorline = s:netrw_usercul
11980 endif
11981 if exists("s:netrw_usercuc")
11982 let &l:cursorcolumn = s:netrw_usercuc
11983 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011984" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011985" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11986endfun
11987
11988" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011989" s:NetrwDelete: Deletes a file. {{{2
11990" Uses Steve Hall's idea to insure that Windows paths stay
11991" acceptable. No effect on Unix paths.
11992" Examples of use: let result= s:NetrwDelete(path)
11993fun! s:NetrwDelete(path)
11994" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11995
Bram Moolenaar5c736222010-01-06 20:54:52 +010011996 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011997 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011998 if exists("+shellslash")
11999 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012000 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012001 let result = delete(path)
12002 let &shellslash = sskeep
12003 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012004" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012005 let result= delete(path)
12006 endif
12007 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012008" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012009 let result= delete(path)
12010 endif
12011 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012012 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012013 endif
12014
12015" call Dret("s:NetrwDelete ".result)
12016 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012017endfun
12018
12019" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012020" s:NetrwBufRemover: removes a buffer that: {{{2s
12021" has buffer-id > 1
12022" is unlisted
12023" is unnamed
12024" does not appear in any window
12025fun! s:NetrwBufRemover(bufid)
12026" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12027" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12028" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12029" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12030" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12031
yasuda4dbb2662023-10-04 20:50:35 +020012032 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012033" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012034 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012035 endif
12036
12037" call Dret("s:NetrwBufRemover")
12038endfun
12039
12040" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012041" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012042fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012043" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012044" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012045
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012046 " Clean out the last buffer:
12047 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12048 " If so, delete it.
12049 call s:NetrwBufRemover(bufnr("$"))
12050
Bram Moolenaar446cb832008-06-24 21:56:24 +000012051 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012052" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012053 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12054 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12055 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12056 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12057 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12058 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12059 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12060 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12061 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12062 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12063 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12064 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12065 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12066 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12067 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12068 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12069
Bram Moolenaar85850f32019-07-19 22:05:51 +020012070 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012071" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012072 " when tree listing uses file TreeListing... a new buffer is made.
12073 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012074 " COMBAK: this causes a problem, see P43
12075" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012076 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012077 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012078 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012079" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012080 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012081
Bram Moolenaar446cb832008-06-24 21:56:24 +000012082 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012083" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012084 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12085 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12086 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12087 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12088 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12089 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12090 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12091 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12092 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12093 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12094 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12095 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12096 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12097 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12098 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12099 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12100
Bram Moolenaar5c736222010-01-06 20:54:52 +010012101 if a:0 > 0
12102 let b:netrw_curdir= a:1
12103 if b:netrw_curdir =~ '/$'
12104 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012105 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012106 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012107 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012108 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12109 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012110 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012111 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012112 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012113 endif
12114 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012115 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12116 let &l:bexpr = "netrw#BalloonHelp()"
12117 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012118
Bram Moolenaar8d043172014-01-23 14:24:41 +010012119" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012120endfun
12121
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012122" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012123" s:NetrwExe: executes a string using "!" {{{2
12124fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012125" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012126 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012127" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012128 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12129 set shell& shellcmdflag& shellxquote& shellxescape&
12130 set shellquote& shellpipe& shellredir& shellslash&
12131 exe a:cmd
12132 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12133 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012134" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012135 exe a:cmd
12136 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012137 if v:shell_error
12138 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12139 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012140" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012141endfun
12142
12143" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012144" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12145fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012146 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012147" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012148 let curbuf = bufnr("%")
12149 let curwin = winnr()
12150 let iwin = 1
12151 while iwin <= winnr("$")
12152 exe iwin."wincmd w"
12153 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12154 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12155 let winvars= w:
12156 break
12157 endif
12158 let iwin= iwin + 1
12159 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012160 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012161 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012162" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012163 for k in keys(winvars)
12164 let w:{k}= winvars[k]
12165 endfor
12166 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012167" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012168 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012169endfun
12170
Bram Moolenaara6878372014-03-22 21:02:50 +010012171" ---------------------------------------------------------------------
12172" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012173" Returns: 0=success
12174" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012175fun! s:NetrwLcd(newdir)
12176" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012177" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012178
Bram Moolenaar85850f32019-07-19 22:05:51 +020012179 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012180 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012181 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012182 catch /^Vim\%((\a\+)\)\=:E344/
12183 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12184 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012185 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012186 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12187 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012188 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012189 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12190 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012191 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012192 endif
12193 endif
12194 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012195 let err472= 1
12196 endtry
12197
12198 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012199 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12200 if exists("w:netrw_prvdir")
12201 let a:newdir= w:netrw_prvdir
12202 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012203 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012204" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012205 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012206" 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 +010012207 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012208 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012209" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12210 return -1
12211 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012212
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012213" call Decho("getcwd <".getcwd().">")
12214" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012215" call Dret("s:NetrwLcd 0")
12216 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012217endfun
12218
Bram Moolenaar9964e462007-05-05 17:54:07 +000012219" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012220" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12221" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12222fun! s:NetrwSaveWordPosn()
12223" call Dfunc("NetrwSaveWordPosn()")
12224 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12225" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12226endfun
12227
12228" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012229" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12230" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12231fun! s:NetrwHumanReadable(sz)
12232" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12233
12234 if g:netrw_sizestyle == 'h'
12235 if a:sz >= 1000000000
12236 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12237 elseif a:sz >= 10000000
12238 let sz = printf("%d",a:sz/1000000)."m"
12239 elseif a:sz >= 1000000
12240 let sz = printf("%.1f",a:sz/1000000.0)."m"
12241 elseif a:sz >= 10000
12242 let sz = printf("%d",a:sz/1000)."k"
12243 elseif a:sz >= 1000
12244 let sz = printf("%.1f",a:sz/1000.0)."k"
12245 else
12246 let sz= a:sz
12247 endif
12248
12249 elseif g:netrw_sizestyle == 'H'
12250 if a:sz >= 1073741824
12251 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12252 elseif a:sz >= 10485760
12253 let sz = printf("%d",a:sz/1048576)."M"
12254 elseif a:sz >= 1048576
12255 let sz = printf("%.1f",a:sz/1048576.0)."M"
12256 elseif a:sz >= 10240
12257 let sz = printf("%d",a:sz/1024)."K"
12258 elseif a:sz >= 1024
12259 let sz = printf("%.1f",a:sz/1024.0)."K"
12260 else
12261 let sz= a:sz
12262 endif
12263
12264 else
12265 let sz= a:sz
12266 endif
12267
12268" call Dret("s:NetrwHumanReadable ".sz)
12269 return sz
12270endfun
12271
12272" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012273" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12274" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12275fun! s:NetrwRestoreWordPosn()
12276" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012277 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012278" call Dret("NetrwRestoreWordPosn")
12279endfun
12280
12281" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012282" s:RestoreBufVars: {{{2
12283fun! s:RestoreBufVars()
12284" call Dfunc("s:RestoreBufVars()")
12285
12286 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12287 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12288 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12289 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12290 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12291 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12292
12293" call Dret("s:RestoreBufVars")
12294endfun
12295
12296" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012297" s:RemotePathAnalysis: {{{2
12298fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012299" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012300
Bram Moolenaara6878372014-03-22 21:02:50 +010012301 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012302 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012303 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012304 let s:user = substitute(a:dirname,dirpat,'\3','')
12305 let s:machine = substitute(a:dirname,dirpat,'\4','')
12306 let s:port = substitute(a:dirname,dirpat,'\5','')
12307 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012308 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012309 if s:machine =~ '@'
12310 let dirpat = '^\(.*\)@\(.\{-}\)$'
12311 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12312 let s:machine = substitute(s:machine,dirpat,'\2','')
12313 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012314
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012315" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12316" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12317" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12318" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12319" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12320" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012321
12322" call Dret("s:RemotePathAnalysis")
12323endfun
12324
12325" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012326" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12327" Returns status
12328" Runs system() on
12329" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012330" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012331fun! s:RemoteSystem(cmd)
12332" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12333 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012334 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 +000012335 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012336 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012337 else
12338 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12339 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12340 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012341 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012342 else
12343 let cmd= cmd.' '
12344 endif
12345 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012346" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012347 let ret= system(cmd)
12348 endif
12349" call Dret("s:RemoteSystem ".ret)
12350 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012351endfun
12352
12353" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012354" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012355fun! s:RestoreWinVars()
12356" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012357 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012358 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12359 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12360 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12361 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12362 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12363 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12364 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12365 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12366 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12367 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12368 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12369 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012370 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12371 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012372 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12373 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12374 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12375" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012376endfun
12377
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012378" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012379" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12380"
12381" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12382" is true) and a command, :Rexplore, which call this function.
12383"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012384" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012385"
12386" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012387fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012388 if exists("s:netrwdrag")
12389 return
12390 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012391" 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 +010012392" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12393" 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 +010012394
12395 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012396 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012397" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012398 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012399 unlet w:netrw_rexfile
12400" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012401 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012402" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012403" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12404" 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 +020012405 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012406
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012407 " ---------------------------
12408 " :Rex issued while in a file
12409 " ---------------------------
12410
Bram Moolenaara6878372014-03-22 21:02:50 +010012411 " record current file so :Rex can return to it from netrw
12412 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012413" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012414
12415 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012416" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012417 return
12418 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012419" 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 +020012420 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012421 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012422 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012423 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012424 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012425 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012426 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012427 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012428 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012429" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12430 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012431" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12432 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012433 if exists("s:rexposn_".bufnr('%'))
12434 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012435 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012436 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012437" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012438 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012439
Bram Moolenaar85850f32019-07-19 22:05:51 +020012440 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12441 if exists("s:explore_match")
12442 exe "2match netrwMarkFile /".s:explore_match."/"
12443 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012444 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012445
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012446" 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 +010012447" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012448endfun
12449
12450" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012451" s:SaveBufVars: save selected b: variables to s: variables {{{2
12452" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012453fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012454" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012455
12456 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12457 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12458 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12459 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12460 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12461 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12462
12463" call Dret("s:SaveBufVars")
12464endfun
12465
12466" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012467" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12468fun! s:SavePosn(posndict)
12469" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12470
Bram Moolenaar85850f32019-07-19 22:05:51 +020012471 if !exists("a:posndict[bufnr('%')]")
12472 let a:posndict[bufnr("%")]= []
12473 endif
12474" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12475 call add(a:posndict[bufnr("%")],winsaveview())
12476" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012477
12478" call Dret("s:SavePosn posndict")
12479 return a:posndict
12480endfun
12481
12482" ---------------------------------------------------------------------
12483" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12484fun! s:RestorePosn(posndict)
12485" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012486 if exists("a:posndict")
12487 if has_key(a:posndict,bufnr("%"))
12488" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12489 let posnlen= len(a:posndict[bufnr("%")])
12490 if posnlen > 0
12491 let posnlen= posnlen - 1
12492" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12493 call winrestview(a:posndict[bufnr("%")][posnlen])
12494 call remove(a:posndict[bufnr("%")],posnlen)
12495" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12496 endif
12497 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012498 endif
12499" call Dret("s:RestorePosn")
12500endfun
12501
12502" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012503" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012504fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012505" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012506 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12507 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12508 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12509 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12510 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12511 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12512 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12513 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12514 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12515 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12516 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12517 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12518 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12519 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12520 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12521 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12522 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12523 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12524" call Dret("s:SaveWinVars")
12525endfun
12526
12527" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012528" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012529" To allow separate windows to have their own activities, such as
12530" Explore **/pattern, several variables have been made window-oriented.
12531" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012532" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012533" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012534fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012535" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012536 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12537 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12538 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12539 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12540 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12541 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12542 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12543 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12544 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12545 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12546" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012547endfun
12548
12549" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012550" s:SetRexDir: set directory for :Rexplore {{{2
12551fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012552" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012553 let w:netrw_rexdir = a:dirname
12554 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012555 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012556" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12557" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012558" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012559" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012560" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012561endfun
12562
12563" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012564" s:ShowLink: used to modify thin and tree listings to show links {{{2
12565fun! s:ShowLink()
12566" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012567" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12568" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012569 if exists("b:netrw_curdir")
12570 norm! $?\a
12571 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12572 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012573" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12574" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12575" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12576 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012577 let dirlen = strlen(b:netrw_curdir)
12578 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012579" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012580 endif
12581 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012582" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12583" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012584 setl noro ma
12585 call setline(".",modline)
12586 setl ro noma nomod
12587 endif
12588" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12589endfun
12590
12591" ---------------------------------------------------------------------
12592" s:ShowStyle: {{{2
12593fun! s:ShowStyle()
12594 if !exists("w:netrw_liststyle")
12595 let liststyle= g:netrw_liststyle
12596 else
12597 let liststyle= w:netrw_liststyle
12598 endif
12599 if liststyle == s:THINLIST
12600 return s:THINLIST.":thin"
12601 elseif liststyle == s:LONGLIST
12602 return s:LONGLIST.":long"
12603 elseif liststyle == s:WIDELIST
12604 return s:WIDELIST.":wide"
12605 elseif liststyle == s:TREELIST
12606 return s:TREELIST.":tree"
12607 else
12608 return 'n/a'
12609 endif
12610endfun
12611
12612" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012613" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12614" Solution from Nicolai Weibull, vim docs (:help strlen()),
12615" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012616fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012617" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12618
12619 if v:version >= 703 && exists("*strdisplaywidth")
12620 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012621
Bram Moolenaar8d043172014-01-23 14:24:41 +010012622 elseif type(g:Align_xstrlen) == 1
12623 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12624 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012625
Bram Moolenaar8d043172014-01-23 14:24:41 +010012626 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012627 " number of codepoints (Latin a + combining circumflex is two codepoints)
12628 " (comment from TM, solution from NW)
12629 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012630
Bram Moolenaar8d043172014-01-23 14:24:41 +010012631 elseif g:Align_xstrlen == 2
12632 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012633 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12634 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012635 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012636
Bram Moolenaar8d043172014-01-23 14:24:41 +010012637 elseif g:Align_xstrlen == 3
12638 " virtual length (counting, for instance, tabs as anything between 1 and
12639 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012640 " preceded by lam, one otherwise, etc.)
12641 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012642 let modkeep= &l:mod
12643 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012644 call setline(line("."),a:x)
12645 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012646 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012647 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012648 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012649
Bram Moolenaar446cb832008-06-24 21:56:24 +000012650 else
12651 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012652 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012653 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012654" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012655 return ret
12656endfun
12657
12658" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012659" s:ShellEscape: shellescape(), or special windows handling {{{2
12660fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012661 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012662 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12663 endif
12664 let f = a:0 > 0 ? a:1 : 0
12665 return shellescape(a:s, f)
12666endfun
12667
12668" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012669" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012670fun! s:TreeListMove(dir)
12671" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012672 let curline = getline('.')
12673 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12674 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12675 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12676 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12677 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12678 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12679" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12680" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12681" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12682" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12683" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12684 " COMBAK : need to handle when on a directory
12685 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012686 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012687 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012688 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012689 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012690" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012691 elseif a:dir == '[]' && nxtline != ''
12692 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012693" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012694 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12695 if nl != 0
12696 NetrwKeepj norm! k
12697 else
12698 NetrwKeepj norm! G
12699 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012700" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012701 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012702 endif
12703
12704" call Dret("s:TreeListMove")
12705endfun
12706
12707" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012708" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12709" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12710" can't be called except via emenu. But due to locale, that menu line may not be called
12711" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12712fun! s:UpdateBuffersMenu()
12713" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012714 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012715 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012716 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012717 catch /^Vim\%((\a\+)\)\=:E/
12718 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012719 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012720 endtry
12721 endif
12722" call Dret("s:UpdateBuffersMenu")
12723endfun
12724
12725" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012726" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012727" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012728fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012729" call Dfunc("s:UseBufWinVars()")
12730 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012731 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12732 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12733 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12734 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12735 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12736 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12737 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12738 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12739 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 +000012740" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012741endfun
12742
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012743" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012744" s:UserMaps: supports user-defined UserMaps {{{2
12745" * calls a user-supplied funcref(islocal,curdir)
12746" * interprets result
12747" See netrw#UserMaps()
12748fun! s:UserMaps(islocal,funcname)
12749" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12750
12751 if !exists("b:netrw_curdir")
12752 let b:netrw_curdir= getcwd()
12753 endif
12754 let Funcref = function(a:funcname)
12755 let result = Funcref(a:islocal)
12756
12757 if type(result) == 1
12758 " if result from user's funcref is a string...
12759" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12760 if result == "refresh"
12761" call Decho("refreshing display",'~'.expand("<slnum>"))
12762 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12763 elseif result != ""
12764" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12765 exe result
12766 endif
12767
12768 elseif type(result) == 3
12769 " if result from user's funcref is a List...
12770" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12771 for action in result
12772 if action == "refresh"
12773" call Decho("refreshing display",'~'.expand("<slnum>"))
12774 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12775 elseif action != ""
12776" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12777 exe action
12778 endif
12779 endfor
12780 endif
12781
12782" call Dret("s:UserMaps")
12783endfun
12784
Bram Moolenaar85850f32019-07-19 22:05:51 +020012785" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012786" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012787" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012788let &cpo= s:keepcpo
12789unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012790
Bram Moolenaar85850f32019-07-19 22:05:51 +020012791" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012792" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012793" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012794" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012795" doing autoload/netrw.vim version v172g ~57
12796" varname<g:netrw_dirhistcnt> value=0 ~1
12797" varname<s:THINLIST> value=0 ~1
12798" varname<s:LONGLIST> value=1 ~1
12799" varname<s:WIDELIST> value=2 ~1
12800" varname<s:TREELIST> value=3 ~1
12801" varname<s:MAXLIST> value=4 ~1
12802" varname<g:netrw_use_errorwindow> value=2 ~1
12803" varname<g:netrw_http_xcmd> value=-q -O ~1
12804" varname<g:netrw_http_put_cmd> value=curl -T ~1
12805" varname<g:netrw_keepj> value=keepj ~1
12806" varname<g:netrw_rcp_cmd> value=rcp ~1
12807" varname<g:netrw_rsync_cmd> value=rsync ~1
12808" varname<g:netrw_rsync_sep> value=/ ~1
12809" varname<g:netrw_scp_cmd> value=scp -q ~1
12810" varname<g:netrw_sftp_cmd> value=sftp ~1
12811" varname<g:netrw_ssh_cmd> value=ssh ~1
12812" varname<g:netrw_alto> value=0 ~1
12813" varname<g:netrw_altv> value=1 ~1
12814" varname<g:netrw_banner> value=1 ~1
12815" varname<g:netrw_browse_split> value=0 ~1
12816" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12817" varname<g:netrw_chgwin> value=-1 ~1
12818" varname<g:netrw_clipboard> value=1 ~1
12819" varname<g:netrw_compress> value=gzip ~1
12820" varname<g:netrw_ctags> value=ctags ~1
12821" varname<g:netrw_cursor> value=2 ~1
12822" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12823" varname<g:netrw_cygdrive> value=/cygdrive ~1
12824" varname<s:didstarstar> value=0 ~1
12825" varname<g:netrw_dirhistcnt> value=0 ~1
12826" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12827" varname<g:netrw_dirhistmax> value=10 ~1
12828" varname<g:netrw_errorlvl> value=0 ~1
12829" varname<g:netrw_fastbrowse> value=1 ~1
12830" 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
12831" varname<g:netrw_ftpmode> value=binary ~1
12832" varname<g:netrw_hide> value=1 ~1
12833" varname<g:netrw_keepdir> value=1 ~1
12834" varname<g:netrw_list_hide> value= ~1
12835" varname<g:netrw_localmkdir> value=mkdir ~1
12836" varname<g:netrw_remote_mkdir> value=mkdir ~1
12837" varname<g:netrw_liststyle> value=0 ~1
12838" varname<g:netrw_markfileesc> value=*./[\~ ~1
12839" varname<g:netrw_maxfilenamelen> value=32 ~1
12840" varname<g:netrw_menu> value=1 ~1
12841" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12842" varname<g:netrw_mousemaps> value=1 ~1
12843" varname<g:netrw_retmap> value=0 ~1
12844" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12845" varname<g:netrw_preview> value=0 ~1