blob: b723074f08cb90fadabe30d85d68a3d7efb97d13 [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 Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Christian Brabandt62f7b552024-06-23 20:23:40 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077)
Christian Brabandtf9ca1392024-02-19 20:37:11 +010019" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000020" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010021" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000022" Permission is hereby granted to use and distribute this code,
23" with or without modifications, provided that this copyright
24" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000025" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000026" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000027" expressed or implied. By using this plugin, you agree that
28" in no event will the copyright holder be liable for any damages
29" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010030"
31" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
32" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
33"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020034"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000035"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000036" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000037" (James 1:22 RSV)
38" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000039" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000040if &cp || exists("g:loaded_netrw")
41 finish
42endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020043
44" Check that vim has patches that netrw requires.
45" Patches needed for v7.4: 1557, and 213.
46" (netrw will benefit from vim's having patch#656, too)
47let s:needspatches=[1557,213]
48if exists("s:needspatches")
49 for ptch in s:needspatches
50 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
51 if !exists("s:needpatch{ptch}")
52 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
53 endif
54 let s:needpatch{ptch}= 1
55 finish
56 endif
57 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020058endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020059
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010060let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000061if !exists("s:NOTE")
62 let s:NOTE = 0
63 let s:WARNING = 1
64 let s:ERROR = 2
65endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000066
Bram Moolenaar1afcace2005-11-25 19:54:28 +000067let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010068setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020069"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010070"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010071"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000072
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000073" ======================
74" Netrw Variables: {{{1
75" ======================
76
Bram Moolenaar071d4272004-06-13 20:20:40 +000077" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020078" netrw#ErrorMsg: {{{2
79" 0=note = s:NOTE
80" 1=warning = s:WARNING
81" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010082" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
83" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
84" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010085" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020086fun! netrw#ErrorMsg(level,msg,errnum)
87" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
88
89 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020090" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020091 return
92 endif
93
94 if a:level == 1
95 let level= "**warning** (netrw) "
96 elseif a:level == 2
97 let level= "**error** (netrw) "
98 else
99 let level= "**note** (netrw) "
100 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100101" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200102
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200103 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
104 " use popup window
105 if type(a:msg) == 3
106 let msg = [level]+a:msg
107 else
108 let msg= level.a:msg
109 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200110 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200111 let s:popuperr_text= ""
112 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200113 " (default) netrw creates a one-line window to show error/warning
114 " messages (reliably displayed)
115
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100116 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200117 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100118" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200119
120 " getting messages out reliably is just plain difficult!
121 " This attempt splits the current window, creating a one line window.
122 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100123" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200124 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100125" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200126 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100127 if type(a:msg) == 3
128 for msg in a:msg
129 NetrwKeepj call setline(line("$")+1,level.msg)
130 endfor
131 else
132 NetrwKeepj call setline(line("$")+1,level.a:msg)
133 endif
134 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200135 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100136" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200137 bo 1split
138 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200139 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200140 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100141 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100142" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200143 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100144 if type(a:msg) == 3
145 for msg in a:msg
146 NetrwKeepj call setline(line("$")+1,level.msg)
147 endfor
148 else
149 NetrwKeepj call setline(line("$"),level.a:msg)
150 endif
151 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200152 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100153" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200154 if &fo !~ '[ta]'
155 syn clear
156 syn match netrwMesgNote "^\*\*note\*\*"
157 syn match netrwMesgWarning "^\*\*warning\*\*"
158 syn match netrwMesgError "^\*\*error\*\*"
159 hi link netrwMesgWarning WarningMsg
160 hi link netrwMesgError Error
161 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100162" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200163 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200164
165 else
166 " (optional) netrw will show messages using echomsg. Even if the
167 " message doesn't appear, at least it'll be recallable via :messages
168" redraw!
169 if a:level == s:WARNING
170 echohl WarningMsg
171 elseif a:level == s:ERROR
172 echohl Error
173 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100174
175 if type(a:msg) == 3
176 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100177 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100178 endfor
179 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100180 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100181 endif
182
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100183" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200184 echohl None
185 endif
186
187" call Dret("netrw#ErrorMsg")
188endfun
189
190" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100191" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100192" Loosely, varname = value.
193fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100194" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100195 if !exists(a:varname)
196 if type(a:value) == 0
197 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200198 elseif type(a:value) == 1 && a:value =~ '^[{[]'
199 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100200 elseif type(a:value) == 1
201 exe "let ".a:varname."="."'".a:value."'"
202 else
203 exe "let ".a:varname."=".a:value
204 endif
205 endif
206endfun
207
208" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000209" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200210call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000211if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100212 call s:NetrwInit("s:THINLIST",0)
213 call s:NetrwInit("s:LONGLIST",1)
214 call s:NetrwInit("s:WIDELIST",2)
215 call s:NetrwInit("s:TREELIST",3)
216 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000217endif
218
219" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200220" Default option values: {{{2
221let g:netrw_localcopycmdopt = ""
222let g:netrw_localcopydircmdopt = ""
223let g:netrw_localmkdiropt = ""
224let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200225
226" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000227" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200228if (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")
229 call s:NetrwInit("g:netrw_use_errorwindow",2)
230else
231 call s:NetrwInit("g:netrw_use_errorwindow",1)
232endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200233
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000234if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100235 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000236 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100237 elseif executable("curl")
238 let g:netrw_dav_cmd = "curl"
239 else
240 let g:netrw_dav_cmd = ""
241 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000242endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000243if !exists("g:netrw_fetch_cmd")
244 if executable("fetch")
245 let g:netrw_fetch_cmd = "fetch -o"
246 else
247 let g:netrw_fetch_cmd = ""
248 endif
249endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100250if !exists("g:netrw_file_cmd")
251 if executable("elinks")
252 call s:NetrwInit("g:netrw_file_cmd","elinks")
253 elseif executable("links")
254 call s:NetrwInit("g:netrw_file_cmd","links")
255 endif
256endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000257if !exists("g:netrw_ftp_cmd")
258 let g:netrw_ftp_cmd = "ftp"
259endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200260let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200261if !exists("g:netrw_ftp_options")
262 let g:netrw_ftp_options= "-i -n"
263endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000264if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100265 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100266 let g:netrw_http_cmd = "wget"
267 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100268 elseif executable("curl")
269 let g:netrw_http_cmd = "curl"
270 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200271 elseif executable("elinks")
272 let g:netrw_http_cmd = "elinks"
273 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000274 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100275 let g:netrw_http_cmd = "fetch"
276 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200277 elseif executable("links")
278 let g:netrw_http_cmd = "links"
279 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000280 else
281 let g:netrw_http_cmd = ""
282 endif
283endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100284call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100285call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100286call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
287call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200288call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200289if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200290 if executable("scp")
291 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
292 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200293 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200294 else
295 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
296 endif
297endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100298call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
299call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000300
Nir Lichtman1e34b952024-05-08 19:19:34 +0200301if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000302 \ && exists("g:netrw_use_nt_rcp")
303 \ && g:netrw_use_nt_rcp
304 \ && executable( $SystemRoot .'/system32/rcp.exe')
305 let s:netrw_has_nt_rcp = 1
306 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000307else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000308 let s:netrw_has_nt_rcp = 0
309 let s:netrw_rcpmode = ''
310endif
311
312" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000313" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000314" Cygwin Detection ------- {{{3
315if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200316 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
317 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000318 else
319 let g:netrw_cygwin= 0
320 endif
321endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000322" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100323call s:NetrwInit("g:netrw_alto" , &sb)
324call s:NetrwInit("g:netrw_altv" , &spr)
325call s:NetrwInit("g:netrw_banner" , 1)
326call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200327call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100328call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200329call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100330call s:NetrwInit("g:netrw_compress" , "gzip")
331call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200332if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
333 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
334 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000335endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200336call s:NetrwInit("g:netrw_cursor" , 2)
337let s:netrw_usercul = &cursorline
338let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200339"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100340call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000341" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200342call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200343call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200344call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100345call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200346call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100347call s:NetrwInit("g:netrw_fastbrowse" , 1)
348call 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 +0000349if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000350 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
351 let g:netrw_ftp_list_cmd = "ls -lF"
352 let g:netrw_ftp_timelist_cmd = "ls -tlF"
353 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000354 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000355 let g:netrw_ftp_list_cmd = "dir"
356 let g:netrw_ftp_timelist_cmd = "dir"
357 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000358 endif
359endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100360call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000361" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100362call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000363if !exists("g:netrw_ignorenetrc")
364 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
365 let g:netrw_ignorenetrc= 1
366 else
367 let g:netrw_ignorenetrc= 0
368 endif
369endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100370call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000371if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000372 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100373 if exists("g:netrw_list_cmd_options")
374 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
375 else
376 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
377 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000378 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200379 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100380 if exists("g:netrw_list_cmd_options")
381 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
382 else
383 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
384 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000385 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100386" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000387 let g:netrw_list_cmd= ""
388 endif
389endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100390call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000391" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200392if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200393 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200394 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
395endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100396if !exists("g:netrw_localcmdshell")
397 let g:netrw_localcmdshell= ""
398endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000399if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200400 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000401 if g:netrw_cygwin
402 let g:netrw_localcopycmd= "cp"
403 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000404 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200405 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000406 endif
407 elseif has("unix") || has("macunix")
408 let g:netrw_localcopycmd= "cp"
409 else
410 let g:netrw_localcopycmd= ""
411 endif
412endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100413if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200414 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100415 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200416 let g:netrw_localcopydircmd = "cp"
417 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100418 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000419 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200420 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100421 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200422 elseif has("unix")
423 let g:netrw_localcopydircmd = "cp"
424 let g:netrw_localcopydircmdopt= " -R"
425 elseif has("macunix")
426 let g:netrw_localcopydircmd = "cp"
427 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100428 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200429 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100430 endif
431endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200432if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100433 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200434 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
435endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200436if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200437 if g:netrw_cygwin
438 call s:NetrwInit("g:netrw_localmkdir","mkdir")
439 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000440 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200441 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200442 endif
443else
444 call s:NetrwInit("g:netrw_localmkdir","mkdir")
445endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200446call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200447if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200448 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200449 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
450endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000451if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200452 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000453 if g:netrw_cygwin
454 let g:netrw_localmovecmd= "mv"
455 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000456 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200457 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000458 endif
459 elseif has("unix") || has("macunix")
460 let g:netrw_localmovecmd= "mv"
461 else
462 let g:netrw_localmovecmd= ""
463 endif
464endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100465" following serves as an example for how to insert a version&patch specific test
466"if v:version < 704 || (v:version == 704 && !has("patch1107"))
467"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100468call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
469" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000470if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000471 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000472endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000473if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000474 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
475endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000476" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100477call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
478call s:NetrwInit("g:netrw_maxfilenamelen", 32)
479call s:NetrwInit("g:netrw_menu" , 1)
480call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200481call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100482call s:NetrwInit("g:netrw_retmap" , 0)
483if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
484 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200485elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100486 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
487else
488 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000489endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100490call s:NetrwInit("g:netrw_preview" , 0)
491call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100492call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100493call s:NetrwInit("g:netrw_sshport" , "-p")
494call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
495call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
496call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100497call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
498" Default values - q-s ---------- {{{3
499call s:NetrwInit("g:netrw_quickhelp",0)
500let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100501 \ "(create new) %:file d:directory",
502 \ "(windows split&open) o:horz v:vert p:preview",
503 \ "i:style qf:file info O:obtain r:reverse",
504 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
505 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
506 \ "(history) qb:list u:go up U:go down",
507 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100508" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
509call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100510if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
511 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
512else
513 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
514endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100515call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
516call s:NetrwInit("g:netrw_sort_options" , "")
517call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000518if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100519 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200520 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100521 else
522 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000523 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000524endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100525call s:NetrwInit("g:netrw_special_syntax" , 0)
526call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200527call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100528call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100529call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000530" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100531call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200532if !exists("g:netrw_xstrlen")
533 if exists("g:Align_xstrlen")
534 let g:netrw_xstrlen= g:Align_xstrlen
535 elseif exists("g:drawit_xstrlen")
536 let g:netrw_xstrlen= g:drawit_xstrlen
537 elseif &enc == "latin1" || !has("multi_byte")
538 let g:netrw_xstrlen= 0
539 else
540 let g:netrw_xstrlen= 1
541 endif
542endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100543call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200544call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100545call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200546if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000547" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000548" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100549call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200550if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200551 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200552else
Bram Moolenaarff034192013-04-24 18:51:19 +0200553 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200554endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200555call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100556call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
557call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100558if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100559 let s:treedepthstring= "│ "
560else
561 let s:treedepthstring= "| "
562endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200563call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000564
565" BufEnter event ignored by decho when following variable is true
566" Has a side effect that doau BufReadPost doesn't work, so
567" files read by network transfer aren't appropriately highlighted.
568"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569
Bram Moolenaaradc21822011-04-01 18:03:16 +0200570" ======================
571" Netrw Initialization: {{{1
572" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200573if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100574" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100575 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200576" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100577 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100578 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
579 au VimEnter * let s:initbeval= &beval
580"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100581" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
582" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
583" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
584" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
585" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
586" 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 +0200587endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200588au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200589
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200590if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100591 com! -nargs=* NetrwKeepj keepj <args>
592else
593 let g:netrw_keepj= ""
594 com! -nargs=* NetrwKeepj <args>
595endif
596
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000597" ==============================
598" Netrw Utility Functions: {{{1
599" ==============================
600
Bram Moolenaaradc21822011-04-01 18:03:16 +0200601" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100602" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100603if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100604" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100605 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100606 if &ft != "netrw"
607 return ""
608 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200609 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
610 " popup error window is still showing
611 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
612 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
613 " text under mouse hasn't changed; only close window when it changes
614 call popup_close(s:popuperr_id)
615 unlet s:popuperr_text
616 else
617 let s:popuperr_text= v:beval_text
618 endif
619 let mesg= ""
620 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 +0100621 let mesg= ""
622 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
623 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
624 elseif getline(v:beval_lnum) =~ '^"\s*/'
625 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
626 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100627 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100628 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
629 let mesg = "S: edit sorting sequence"
630 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
631 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
632 elseif v:beval_text == "Quick" || v:beval_text == "Help"
633 let mesg = "Help: press <F1>"
634 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
635 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
636 else
637 let mesg= ""
638 endif
639 return mesg
640 endfun
641"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100642" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
643" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
644" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
645" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
646" 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 +0200647endif
648
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200650" netrw#Explore: launch the local browser in the directory of the current file {{{2
651" indx: == -1: Nexplore
652" == -2: Pexplore
653" == +: this is overloaded:
654" * If Nexplore/Pexplore is in use, then this refers to the
655" indx'th item in the w:netrw_explore_list[] of items which
656" matched the */pattern **/pattern *//pattern **//pattern
657" * If Hexplore or Vexplore, then this will override
658" g:netrw_winsize to specify the qty of rows or columns the
659" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100660" 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 +0200661" dosplit==1: the window will be split before running the local browser
662" style == 0: Explore style == 1: Explore!
663" == 2: Hexplore style == 3: Hexplore!
664" == 4: Vexplore style == 5: Vexplore!
665" == 6: Texplore
666fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100667" 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 +0100668" 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 +0200669 if !exists("b:netrw_curdir")
670 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100671" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200672 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100673
674 " record current file for Rexplore's benefit
675 if &ft != "netrw"
676 let w:netrw_rexfile= expand("%:p")
677 endif
678
679 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200680 let curdir = simplify(b:netrw_curdir)
681 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200682 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200683 let curdir= substitute(curdir,'\','/','g')
684 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100685" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100686
687 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
688 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
689 " try Explore again.
690 if a:0 > 0
691" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100692 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
693 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
694 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
695 \ '~'.expand("<slnum>"))
696 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
697" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100698 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
699" call Dret("netrw#Explore : returning from retry")
700 return
701" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100702" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100703 endif
704 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200705
706 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200707 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100708" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100709 sil! let keepregstar = @*
710 sil! let keepregplus = @+
711 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200712 sil! let keepregslash= @/
713
Bram Moolenaar8d043172014-01-23 14:24:41 +0100714 " if dosplit
715 " -or- file has been modified AND file not hidden when abandoned
716 " -or- Texplore used
717 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100718" 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 +0200719 call s:SaveWinVars()
720 let winsz= g:netrw_winsize
721 if a:indx > 0
722 let winsz= a:indx
723 endif
724
725 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100726" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200727 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200728 if winsz == 0|let winsz= ""|endif
729 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100730" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200731
732 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100733" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200734 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200735 if winsz == 0|let winsz= ""|endif
736 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100737" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200738
739 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100740" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200741 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200742 if winsz == 0|let winsz= ""|endif
743 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100744" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200745
746 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100747" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200748 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200749 if winsz == 0|let winsz= ""|endif
750 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100751" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200752
753 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100754" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200755 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200756 if winsz == 0|let winsz= ""|endif
757 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100758" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200759
760 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100761" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200762 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200763 if winsz == 0|let winsz= ""|endif
764 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100765" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200766
767 elseif a:style == 6 " Texplore
768 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100769" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200770 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100771" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200772 call s:RestoreBufVars()
773 endif
774 call s:RestoreWinVars()
775" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100776" 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 +0200777 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100778 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200779
780 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100783" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100785" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100787" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200788 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
789 if dirname !~ '/$'
790 let dirname= dirname."/"
791 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100796" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200797 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100798" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200799 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100800" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200801 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100802" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200803 let dirname= a:1
804 endif
805 else
806 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100807" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200808 call s:NetrwClearExplore()
809" call Dret("netrw#Explore : cleared list")
810 return
811 endif
812
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100813" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200814 if dirname =~ '\.\./\=$'
815 let dirname= simplify(fnamemodify(dirname,':p:h'))
816 elseif dirname =~ '\.\.' || dirname == '.'
817 let dirname= simplify(fnamemodify(dirname,':p'))
818 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100819" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200820
821 if dirname =~ '^\*//'
822 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100823" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200824 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
825 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100826" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200827 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
828
829 elseif dirname =~ '^\*\*//'
830 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100831" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200832 let pattern= substitute(dirname,'^\*\*//','','')
833 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100834" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200835
836 elseif dirname =~ '/\*\*/'
837 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100838" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200839 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200840 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200841 let b:netrw_curdir = prefixdir
842 else
843 let b:netrw_curdir= getcwd().'/'.prefixdir
844 endif
845 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
846 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100847" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
848" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200849
850 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200851 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200852 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100853" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200854
855 elseif dirname=~ '^\*\*/'
856 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
857 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100858" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200859
860 else
861 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100862" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200863 endif
864
865 if starpat == 0 && a:indx >= 0
866 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100867" 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 +0200868 if dirname == ""
869 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100870" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200871 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200872 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200873 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200874 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200875 if dirname == ""
876 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200877 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100878 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100879 " depending on whether backslashes have been converted to forward slashes by earlier code).
880 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200881 let dirname= b:netrw_curdir."/".dirname
882 endif
883 elseif dirname !~ '^/'
884 let dirname= b:netrw_curdir."/".dirname
885 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100886" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200887 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100888" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
889" 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 +0200890 endif
891 if exists("w:netrw_bannercnt")
892 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
893 " If one wants to return the same place in the netrw window, use :Rex instead.
894 exe w:netrw_bannercnt
895 endif
896
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100897" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200898 " ---------------------------------------------------------------------
899 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
900" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100901" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200902" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100903" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200904" endif
905 " ---------------------------------------------------------------------
906
907 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
908 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
909 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
910 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
911 elseif a:indx <= 0
912 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100913" 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 +0200914 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100915" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200916 let s:didstarstar= 1
917 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
918 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
919 endif
920
921 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100922" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200923 if !exists("w:netrw_explore_indx")
924 let w:netrw_explore_indx= 0
925 endif
926
927 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100928" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200929
930 if indx == -1
931 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100932" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200933 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100934 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 +0200935 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100936" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100937 if @* != keepregstar | sil! let @* = keepregstar | endif
938 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100939 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200940 sil! let @/ = keepregslash
941" call Dret("netrw#Explore")
942 return
943 endif
944 let indx= w:netrw_explore_indx
945 if indx < 0 | let indx= 0 | endif
946 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
947 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100948" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200949 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
950 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100951" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200952 endwhile
953 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100954" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200955
956 elseif indx == -2
957 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100958" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200959 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100960 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 +0200961 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100962" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100963 if @* != keepregstar | sil! let @* = keepregstar | endif
964 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100965 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200966 sil! let @/ = keepregslash
967" call Dret("netrw#Explore")
968 return
969 endif
970 let indx= w:netrw_explore_indx
971 if indx < 0 | let indx= 0 | endif
972 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
973 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100974" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200975 while indx >= 0 && curfile == w:netrw_explore_list[indx]
976 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100977" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200978 endwhile
979 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100980" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200981
982 else
983 " Explore -- initialize
984 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100985" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100986 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200987 let w:netrw_explore_indx= 0
988 if !exists("b:netrw_curdir")
989 let b:netrw_curdir= getcwd()
990 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100991" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200992
993 " switch on starpat to build the w:netrw_explore_list of files
994 if starpat == 1
995 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100996" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
997" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200998 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100999 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001000 catch /^Vim\%((\a\+)\)\=:E480/
1001 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1002" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1003 return
1004 endtry
1005 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1006 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1007
1008 elseif starpat == 2
1009 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001010" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1011" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001012 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001013 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001014 catch /^Vim\%((\a\+)\)\=:E480/
1015 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1016 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001017 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001018" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001019 if @* != keepregstar | sil! let @* = keepregstar | endif
1020 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001021 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001022 sil! let @/ = keepregslash
1023" call Dret("netrw#Explore : no files matched pattern")
1024 return
1025 endtry
1026 let s:netrw_curdir = b:netrw_curdir
1027 let w:netrw_explore_list = getqflist()
1028 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1029 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1030
1031 elseif starpat == 3
1032 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001033" 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 +02001034 let filepat= substitute(dirname,'^\*/','','')
1035 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001036" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1037" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001038 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1039 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1040
1041 elseif starpat == 4
1042 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001043" 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 +02001044 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1045 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1046 endif " switch on starpat to build w:netrw_explore_list
1047
1048 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001049" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1050" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001051
1052 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001053 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001054 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001055" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001056 if @* != keepregstar | sil! let @* = keepregstar | endif
1057 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001058 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001059 sil! let @/ = keepregslash
1060" call Dret("netrw#Explore : no files matched")
1061 return
1062 endif
1063 endif " if indx ... endif
1064
1065 " NetrwStatusLine support - for exploring support
1066 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001067" 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 +02001068
1069 " wrap the indx around, but issue a note
1070 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001071" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001072 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1073 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001074 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 endif
1076
1077 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001078" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001079 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001080" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001081
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001082" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001083 call netrw#LocalBrowseCheck(newdir)
1084 if !exists("w:netrw_liststyle")
1085 let w:netrw_liststyle= g:netrw_liststyle
1086 endif
1087 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001088 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001089 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001090 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001091 endif
1092 let w:netrw_explore_mtchcnt = indx + 1
1093 let w:netrw_explore_bufnr = bufnr("%")
1094 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001095 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001096" 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 +02001097
1098 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001099" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001100 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001101 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 +02001102 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001103 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001104" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001105 if @* != keepregstar | sil! let @* = keepregstar | endif
1106 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001107 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001108 sil! let @/ = keepregslash
1109" call Dret("netrw#Explore : missing +path_extra")
1110 return
1111 endif
1112
1113 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001114" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001115 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1116 sil! unlet w:netrw_treedict
1117 sil! unlet w:netrw_treetop
1118 endif
1119 let newdir= dirname
1120 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001121 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001122 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001123 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001124 endif
1125 endif
1126
1127 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001128" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1129" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001130 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001131" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001132 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001133 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001134" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001135 let s:explore_prvdir = b:netrw_curdir
1136 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001137 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001138 if b:netrw_curdir !~ '/$'
1139 let dirlen= dirlen + 1
1140 endif
1141 let prvfname= ""
1142 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001143" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001144 if fname =~ '^'.b:netrw_curdir
1145 if s:explore_match == ""
1146 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1147 else
1148 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1149 endif
1150 elseif fname !~ '^/' && fname != prvfname
1151 if s:explore_match == ""
1152 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1153 else
1154 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1155 endif
1156 endif
1157 let prvfname= fname
1158 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001159" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001160 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1161 exe "2match netrwMarkFile /".s:explore_match."/"
1162 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001163 endif
1164 echo "<s-up>==Pexplore <s-down>==Nexplore"
1165 else
1166 2match none
1167 if exists("s:explore_match") | unlet s:explore_match | endif
1168 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001169" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001170 endif
1171
Bram Moolenaara6878372014-03-22 21:02:50 +01001172 " since Explore may be used to initialize netrw's browser,
1173 " there's no danger of a late FocusGained event on initialization.
1174 " Consequently, set s:netrw_events to 2.
1175 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001176 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001177" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001178 if @* != keepregstar | sil! let @* = keepregstar | endif
1179 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001180 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001181 sil! let @/ = keepregslash
1182" call Dret("netrw#Explore : @/<".@/.">")
1183endfun
1184
1185" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001186" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001187" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1188" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1189" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1190" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1191" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001192fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001193" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001194 let curwin= winnr()
1195
Bram Moolenaara6878372014-03-22 21:02:50 +01001196 if a:0 > 0 && a:1 != ""
1197 " if a netrw window is already on the left-side of the tab
1198 " and a directory has been specified, explore with that
1199 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001200" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001201 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001202" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001203 exe "1wincmd w"
1204 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001205" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001206 exe "Explore ".fnameescape(a1)
1207 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001208 let s:lexplore_win= curwin
1209 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001210 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001211" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001212 unlet t:netrw_lexposn
1213 endif
1214" call Dret("netrw#Lexplore")
1215 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001216 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001217 exe curwin."wincmd w"
1218 else
1219 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001220" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001221 endif
1222
Bram Moolenaar8d043172014-01-23 14:24:41 +01001223 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001224 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001225 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001226" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001227 else
1228 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001229" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001230 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001231" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001232
1233 if lexwinnr > 0
1234 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001235" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001236 exe lexwinnr."wincmd w"
1237 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001238 let t:netrw_lexposn = winsaveview()
1239" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001240" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001241 close
1242 if lexwinnr < curwin
1243 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001244 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001245 if lexwinnr != curwin
1246 exe curwin."wincmd w"
1247 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001248 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001249" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001250
1251 else
1252 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001253" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001254 exe "1wincmd w"
1255 let keep_altv = g:netrw_altv
1256 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001257 if a:count != 0
1258 let netrw_winsize = g:netrw_winsize
1259 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001260 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001261 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001262" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001263 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 +02001264" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001265 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001266" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001267 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001268 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001269 elseif curfile =~ '^\a\{3,}://'
1270" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001271 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001272 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001273" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001274 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001275 endif
1276 if a:count != 0
1277 let g:netrw_winsize = netrw_winsize
1278 endif
1279 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001280 let g:netrw_altv = keep_altv
1281 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001282 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1283 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001284 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001285 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001286" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1287" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001288 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001289" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001290" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1291 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001292 unlet t:netrw_lexposn
1293 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001294 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001295
1296 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001297 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001298 if a:rightside
1299 let g:netrw_chgwin= 1
1300 else
1301 let g:netrw_chgwin= 2
1302 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001303" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001304 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001305
Bram Moolenaar8d043172014-01-23 14:24:41 +01001306" call Dret("netrw#Lexplore")
1307endfun
1308
1309" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001310" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001311" supports :NetrwClean -- remove netrw from first directory on runtimepath
1312" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001313fun! netrw#Clean(sys)
1314" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001315
1316 if a:sys
1317 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1318 else
1319 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1320 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001321" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001322 let diddel= 0
1323 let diddir= ""
1324
1325 if choice == 1
1326 for dir in split(&rtp,',')
1327 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001328" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001329 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1330 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1331 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1332 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1333 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1334 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 +00001335 let diddir= dir
1336 let diddel= diddel + 1
1337 if !a:sys|break|endif
1338 endif
1339 endfor
1340 endif
1341
1342 echohl WarningMsg
1343 if diddel == 0
1344 echomsg "netrw is either not installed or not removable"
1345 elseif diddel == 1
1346 echomsg "removed one copy of netrw from <".diddir.">"
1347 else
1348 echomsg "removed ".diddel." copies of netrw"
1349 endif
1350 echohl None
1351
Bram Moolenaara6878372014-03-22 21:02:50 +01001352" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001353endfun
1354
Bram Moolenaar5c736222010-01-06 20:54:52 +01001355" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001356" netrw#MakeTgt: make a target out of the directory name provided {{{2
1357fun! netrw#MakeTgt(dname)
1358" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1359 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001360 let svpos = winsaveview()
1361" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001362 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1363" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001364 if s:netrwmftgt_islocal
1365 let netrwmftgt= simplify(a:dname)
1366 else
1367 let netrwmftgt= a:dname
1368 endif
1369 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1370 " re-selected target, so just clear it
1371 unlet s:netrwmftgt s:netrwmftgt_islocal
1372 else
1373 let s:netrwmftgt= netrwmftgt
1374 endif
1375 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001376 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001377 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001378" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1379 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001380" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001381endfun
1382
Bram Moolenaara6878372014-03-22 21:02:50 +01001383" ---------------------------------------------------------------------
1384" netrw#Obtain: {{{2
1385" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001386" islocal=0 obtain from remote source
1387" =1 obtain from local source
1388" fname : a filename or a list of filenames
1389" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001390fun! netrw#Obtain(islocal,fname,...)
1391" 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 +02001392 " NetrwStatusLine support - for obtaining support
1393
1394 if type(a:fname) == 1
1395 let fnamelist= [ a:fname ]
1396 elseif type(a:fname) == 3
1397 let fnamelist= a:fname
1398 else
1399 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 +01001400" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001401 return
1402 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001403" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001404 if a:0 > 0
1405 let tgtdir= a:1
1406 else
1407 let tgtdir= getcwd()
1408 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001409" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001410
1411 if exists("b:netrw_islocal") && b:netrw_islocal
1412 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001413" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001414 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1415 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001416 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001417 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001418" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001419 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001420" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001421 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001422 if v:shell_error != 0
1423 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 +01001424" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001425 return
1426 endif
1427 endfor
1428 else
1429 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001430" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1431 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1432" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001433 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001434 if v:shell_error != 0
1435 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 +01001436" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001437 return
1438 endif
1439 endif
1440 elseif !exists("b:netrw_curdir")
1441 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1442 else
1443 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1444 endif
1445
1446 else
1447 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001448" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001449 if type(a:fname) == 1
1450 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1451 endif
1452 call s:NetrwMethod(b:netrw_curdir)
1453
1454 if b:netrw_method == 4
1455 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001456" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001457 if exists("g:netrw_port") && g:netrw_port != ""
1458 let useport= " ".g:netrw_scpport." ".g:netrw_port
1459 else
1460 let useport= ""
1461 endif
1462 if b:netrw_fname =~ '/'
1463 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1464 else
1465 let path= ""
1466 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001467 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001468 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 +02001469
1470 elseif b:netrw_method == 2
1471 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001472" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001473 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001474 let tmpbufnr= bufnr("%")
1475 setl ff=unix
1476 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001477 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001478" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001479 endif
1480
1481 if exists("b:netrw_fname") && b:netrw_fname != ""
1482 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001483" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001484 endif
1485
1486 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001487 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001488" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001489 endif
1490 for fname in fnamelist
1491 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001492" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001493 endfor
1494 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001495 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 +02001496 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001497 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001498 endif
1499 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1500 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1501 let debugkeep= &debug
1502 setl debug=msg
1503 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1504 let &debug= debugkeep
1505 endif
1506
1507 elseif b:netrw_method == 3
1508 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001509" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001510 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001511 let tmpbufnr= bufnr("%")
1512 setl ff=unix
1513
1514 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001515 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001516" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001517 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001518 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001519" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001520 endif
1521
1522 if exists("g:netrw_uid") && g:netrw_uid != ""
1523 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001524 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001525" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001526 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001527 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001528 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001529" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001530 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001531 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001532" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001533 endif
1534 endif
1535
1536 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001537 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001538" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001539 endif
1540
1541 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001542 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001543" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001544 endif
1545
1546 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001547 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001548" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001549 endif
1550
1551 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001552 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001553" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001554 endif
1555 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001556 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001557 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001558" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001559
1560 " perform ftp:
1561 " -i : turns off interactive prompting from ftp
1562 " -n unix : DON'T use <.netrc>, even though it exists
1563 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001564 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1565 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001566 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001567 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1568 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001569" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001570 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001571 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001572 endif
1573 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001574
1575 elseif b:netrw_method == 9
1576 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001577" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001578 if a:fname =~ '/'
1579 let localfile= substitute(a:fname,'^.*/','','')
1580 else
1581 let localfile= a:fname
1582 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001583 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 +02001584
Bram Moolenaarff034192013-04-24 18:51:19 +02001585 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001586 " probably a badly formed url; protocol not recognized
1587" call Dret("netrw#Obtain : unsupported method")
1588 return
1589
1590 else
1591 " protocol recognized but not supported for Obtain (yet?)
1592 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001593 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001594 endif
1595" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001596 return
1597 endif
1598
1599 " restore status line
1600 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001601 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001602 endif
1603
1604 endif
1605
1606 " cleanup
1607 if exists("tmpbufnr")
1608 if bufnr("%") != tmpbufnr
1609 exe tmpbufnr."bw!"
1610 else
1611 q!
1612 endif
1613 endif
1614
Bram Moolenaara6878372014-03-22 21:02:50 +01001615" call Dret("netrw#Obtain")
1616endfun
1617
1618" ---------------------------------------------------------------------
1619" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1620fun! netrw#Nread(mode,fname)
1621" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001622 let svpos= winsaveview()
1623" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001624 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001625" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1626 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001627
1628 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1629 if exists("w:netrw_bannercnt")
1630 " start with cursor just after the banner
1631 exe w:netrw_bannercnt
1632 endif
1633 endif
1634" call Dret("netrw#Nread")
1635endfun
1636
1637" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001638" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1639" Options get restored by s:NetrwOptionsRestore()
1640"
1641" Option handling:
1642" * save user's options (s:NetrwOptionsSave)
1643" * set netrw-safe options (s:NetrwOptionsSafe)
1644" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1645" * restore user's options (s:netrwOPtionsRestore)
1646" - restore a user option when != safe option (s:NetrwRestoreSetting)
1647" vt: (variable type) normally its either "w:" or "s:"
1648fun! s:NetrwOptionsSave(vt)
1649" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1650" 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 +02001651" 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>"))
1652" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001653
1654 if !exists("{a:vt}netrw_optionsave")
1655 let {a:vt}netrw_optionsave= 1
1656 else
1657" call Dret("s:NetrwOptionsSave : options already saved")
1658 return
1659 endif
1660" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1661
1662 " Save current settings and current directory
1663" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1664 let s:yykeep = @@
1665 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1666 let {a:vt}netrw_aikeep = &l:ai
1667 let {a:vt}netrw_awkeep = &l:aw
1668 let {a:vt}netrw_bhkeep = &l:bh
1669 let {a:vt}netrw_blkeep = &l:bl
1670 let {a:vt}netrw_btkeep = &l:bt
1671 let {a:vt}netrw_bombkeep = &l:bomb
1672 let {a:vt}netrw_cedit = &cedit
1673 let {a:vt}netrw_cikeep = &l:ci
1674 let {a:vt}netrw_cinkeep = &l:cin
1675 let {a:vt}netrw_cinokeep = &l:cino
1676 let {a:vt}netrw_comkeep = &l:com
1677 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001678 let {a:vt}netrw_cuckeep = &l:cuc
1679 let {a:vt}netrw_culkeep = &l:cul
1680" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001681 let {a:vt}netrw_diffkeep = &l:diff
1682 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001683 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1684 let {a:vt}netrw_ffkeep = &l:ff
1685 endif
1686 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1687 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001688 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001689 let {a:vt}netrw_hidkeep = &l:hidden
1690 let {a:vt}netrw_imkeep = &l:im
1691 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001692 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001693 let {a:vt}netrw_lskeep = &l:ls
1694 let {a:vt}netrw_makeep = &l:ma
1695 let {a:vt}netrw_magickeep = &l:magic
1696 let {a:vt}netrw_modkeep = &l:mod
1697 let {a:vt}netrw_nukeep = &l:nu
1698 let {a:vt}netrw_rnukeep = &l:rnu
1699 let {a:vt}netrw_repkeep = &l:report
1700 let {a:vt}netrw_rokeep = &l:ro
1701 let {a:vt}netrw_selkeep = &l:sel
1702 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001703 if !g:netrw_use_noswf
1704 let {a:vt}netrw_swfkeep = &l:swf
1705 endif
1706 let {a:vt}netrw_tskeep = &l:ts
1707 let {a:vt}netrw_twkeep = &l:tw " textwidth
1708 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1709 let {a:vt}netrw_wrapkeep = &l:wrap
1710 let {a:vt}netrw_writekeep = &l:write
1711
1712 " save a few selected netrw-related variables
1713" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1714 if g:netrw_keepdir
1715 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001716" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001717 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001718 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001719 sil! let {a:vt}netrw_starkeep = @*
1720 sil! let {a:vt}netrw_pluskeep = @+
1721 endif
1722 sil! let {a:vt}netrw_slashkeep= @/
1723
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001724" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001725" 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>"))
1726" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1727endfun
1728
1729" ---------------------------------------------------------------------
1730" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1731" Use s:NetrwSaveOptions() to save user settings
1732" Use s:NetrwOptionsRestore() to restore user settings
1733fun! s:NetrwOptionsSafe(islocal)
1734" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1735" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1736" 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>"))
1737 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1738 call s:NetrwSetSafeSetting("&l:ai",0)
1739 call s:NetrwSetSafeSetting("&l:aw",0)
1740 call s:NetrwSetSafeSetting("&l:bl",0)
1741 call s:NetrwSetSafeSetting("&l:bomb",0)
1742 if a:islocal
1743 call s:NetrwSetSafeSetting("&l:bt","nofile")
1744 else
1745 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1746 endif
1747 call s:NetrwSetSafeSetting("&l:ci",0)
1748 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001749 if g:netrw_fastbrowse > a:islocal
1750 call s:NetrwSetSafeSetting("&l:bh","hide")
1751 else
1752 call s:NetrwSetSafeSetting("&l:bh","delete")
1753 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001754 call s:NetrwSetSafeSetting("&l:cino","")
1755 call s:NetrwSetSafeSetting("&l:com","")
1756 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1757 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1758 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001759 if &go =~ 'a' | set go-=a | endif
1760 if &go =~ 'A' | set go-=A | endif
1761 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001762 call s:NetrwSetSafeSetting("&l:hid",0)
1763 call s:NetrwSetSafeSetting("&l:im",0)
1764 setl isk+=@ isk+=* isk+=/
1765 call s:NetrwSetSafeSetting("&l:magic",1)
1766 if g:netrw_use_noswf
1767 call s:NetrwSetSafeSetting("swf",0)
1768 endif
1769 call s:NetrwSetSafeSetting("&l:report",10000)
1770 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1771 call s:NetrwSetSafeSetting("&l:spell",0)
1772 call s:NetrwSetSafeSetting("&l:tw",0)
1773 call s:NetrwSetSafeSetting("&l:wig","")
1774 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001775
1776 " set up cuc and cul based on g:netrw_cursor and listing style
1777 " COMBAK -- cuc cul related
1778 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001779
1780 " allow the user to override safe options
1781" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1782 if &ft == "netrw"
1783" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1784 keepalt NetrwKeepj doau FileType netrw
1785 endif
1786
1787" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1788" 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>"))
1789" call Dret("s:NetrwOptionsSafe")
1790endfun
1791
1792" ---------------------------------------------------------------------
1793" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1794fun! s:NetrwOptionsRestore(vt)
1795" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001796" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001797" 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 +01001798 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001799" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001800
1801 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1802 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001803" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001804 filetype detect
1805" 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>"))
1806 else
1807 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001808 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001809" 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 +02001810" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001811 return
1812 endif
1813 unlet {a:vt}netrw_optionsave
1814
1815 if exists("+acd")
1816 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001817" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001818 let curdir = getcwd()
1819 let &l:acd = {a:vt}netrw_acdkeep
1820 unlet {a:vt}netrw_acdkeep
1821 if &l:acd
1822 call s:NetrwLcd(curdir)
1823 endif
1824 endif
1825 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001826" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001827 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1828 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1829 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1830 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1831 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001832" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001833 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1834 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1835 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1836 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1837 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001838" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001839 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1840 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1841 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1842 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1843 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001844 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001845" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1846 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1847 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001848 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001849 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1850" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1851 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1852 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1853" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1854 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1855" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1856 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1857 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001858 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001859 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1860 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1861" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1862 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1863 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1864 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1865 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1866" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001867 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001868 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1869 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1870 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001871 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001872" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001873 call s:NetrwRestoreSetting("s:yykeep","@@")
1874 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1875 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1876 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1877 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1878
Bram Moolenaara6878372014-03-22 21:02:50 +01001879 if exists("{a:vt}netrw_swfkeep")
1880 if &directory == ""
1881 " user hasn't specified a swapfile directory;
1882 " netrw will temporarily set the swapfile directory
1883 " to the current directory as returned by getcwd().
1884 let &l:directory= getcwd()
1885 sil! let &l:swf = {a:vt}netrw_swfkeep
1886 setl directory=
1887 unlet {a:vt}netrw_swfkeep
1888 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001889 if !g:netrw_use_noswf
1890 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1891 sil! let &l:swf= {a:vt}netrw_swfkeep
1892 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001893 unlet {a:vt}netrw_swfkeep
1894 endif
1895 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001896 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001897 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1898 if exists("{a:vt}netrw_dirkeep")
1899 call s:NetrwLcd(dirkeep)
1900 unlet {a:vt}netrw_dirkeep
1901 endif
1902 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001903 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001904" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001905 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1906 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001907 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001908 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001909
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001910" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1911" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1912" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1913" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1914" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001915 " Moved the filetype detect here from NetrwGetFile() because remote files
1916 " were having their filetype detect-generated settings overwritten by
1917 " NetrwOptionRestore.
1918 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001919" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1920 filetype detect
1921" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001922 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001923" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001924" 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 +02001925" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001926endfun
1927
1928" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001929" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1930" but only when the options' value and the safe setting differ
1931" Doing this means that netrw will not come up as having changed a
1932" setting last when it really didn't actually change it.
1933"
1934" Called from s:NetrwOptionsSafe
1935" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1936fun! s:NetrwSetSafeSetting(setting,safesetting)
1937" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001938
Bram Moolenaar85850f32019-07-19 22:05:51 +02001939 if a:setting =~ '^&'
1940" call Decho("fyi: a:setting starts with &")
1941 exe "let settingval= ".a:setting
1942" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001943
Bram Moolenaar85850f32019-07-19 22:05:51 +02001944 if settingval != a:safesetting
1945" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1946 if type(a:safesetting) == 0
1947 exe "let ".a:setting."=".a:safesetting
1948 elseif type(a:safesetting) == 1
1949 exe "let ".a:setting."= '".a:safesetting."'"
1950 else
1951 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1952 endif
1953 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001954 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001955
Bram Moolenaar85850f32019-07-19 22:05:51 +02001956" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001957endfun
1958
1959" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001960" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1961" but only if the setting value differs from the associated keepvar.
1962" Doing this means that netrw will not come up as having changed a
1963" setting last when it really didn't actually change it.
1964"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001965" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001966" keepvars are set up by s:NetrwOptionsSave
1967fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001968""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001969
Bram Moolenaar85850f32019-07-19 22:05:51 +02001970 " typically called from s:NetrwOptionsRestore
1971 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1972 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001973 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001974 if exists(a:keepvar)
1975 exe "let keepvarval= ".a:keepvar
1976 exe "let setting= ".a:setting
1977
1978"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1979"" call Decho("fyi: keepvarval=".keepvarval)
1980"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1981
1982 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001983"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001984 if type(a:setting) == 0
1985 exe "let ".a:setting."= ".keepvarval
1986 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001987 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001988 else
1989 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1990 endif
1991 endif
1992
1993 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001994 endif
1995
Bram Moolenaar85850f32019-07-19 22:05:51 +02001996"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001997endfun
1998
1999" ---------------------------------------------------------------------
2000" NetrwStatusLine: {{{2
2001fun! NetrwStatusLine()
2002
2003" vvv NetrwStatusLine() debugging vvv
2004" let g:stlmsg=""
2005" if !exists("w:netrw_explore_bufnr")
2006" let g:stlmsg="!X<explore_bufnr>"
2007" elseif w:netrw_explore_bufnr != bufnr("%")
2008" let g:stlmsg="explore_bufnr!=".bufnr("%")
2009" endif
2010" if !exists("w:netrw_explore_line")
2011" let g:stlmsg=" !X<explore_line>"
2012" elseif w:netrw_explore_line != line(".")
2013" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2014" endif
2015" if !exists("w:netrw_explore_list")
2016" let g:stlmsg=" !X<explore_list>"
2017" endif
2018" ^^^ NetrwStatusLine() debugging ^^^
2019
2020 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")
2021 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002022 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002023 let &laststatus = s:netrw_users_ls
2024 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2025 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2026 return ""
2027 else
2028 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2029 endif
2030endfun
2031
Bram Moolenaar85850f32019-07-19 22:05:51 +02002032" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002033" Netrw Transfer Functions: {{{1
2034" ===============================
2035
Bram Moolenaar071d4272004-06-13 20:20:40 +00002036" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002037" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002038" mode: =0 read remote file and insert before current line
2039" =1 read remote file and insert after current line
2040" =2 replace with remote file
2041" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002042fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002043" 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 +00002044
Bram Moolenaar5c736222010-01-06 20:54:52 +01002045 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002046 call s:NetrwOptionsSave("w:")
2047 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002048 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002049 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2050 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2051 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002052" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002053
Bram Moolenaar5c736222010-01-06 20:54:52 +01002054 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002055 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002056 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002057 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002058 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002059 elseif a:mode == 2 " replace with remote file
2060 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002061 elseif a:mode == 3 " skip read of file (leave as temporary)
2062 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002063 else
2064 exe a:mode
2065 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002066 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002067 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002068" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002069
Bram Moolenaar5c736222010-01-06 20:54:52 +01002070 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002071 let tmpfile= s:GetTempfile("")
2072 if tmpfile == ""
2073" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002074 return
2075 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002076
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002078
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002079 " attempt to repeat with previous host-file-etc
2080 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002081" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002082 let choice = b:netrw_lastfile
2083 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002084
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002085 else
2086 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002087" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002088
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002089 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002090 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002091 echomsg 'NetRead Usage:'
2092 echomsg ':Nread machine:path uses rcp'
2093 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2094 echomsg ':Nread "machine id password path" uses ftp'
2095 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2096 echomsg ':Nread fetch://machine/path uses fetch'
2097 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2098 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002099 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002100 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002101 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2102 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2103 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2104 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002105 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002106 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002107
Bram Moolenaar9964e462007-05-05 17:54:07 +00002108 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002109 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002110" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002111 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002113 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002114 else
2115 " case "... ... ..."
2116 let choice = strpart(choice,1,strlen(choice)-1)
2117 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002118
Bram Moolenaar9964e462007-05-05 17:54:07 +00002119 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002120 let wholechoice = wholechoice . " " . choice
2121 let ichoice = ichoice + 1
2122 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002123 if !exists("g:netrw_quiet")
2124 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2125 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002126" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002127 return
2128 endif
2129 let choice= a:{ichoice}
2130 endwhile
2131 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2132 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002133 endif
2134 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002136" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002137 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002138
Bram Moolenaar5c736222010-01-06 20:54:52 +01002139 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002140 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002141 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002142" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002143 return
2144 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002145 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002146
Bram Moolenaar8d043172014-01-23 14:24:41 +01002147 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002148" 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 +02002149 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002150" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002151 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002152" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002153 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002155
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002156 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002157 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002158 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002159 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2160 echo "(netrw) Processing your read request..."
2161 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002162
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002163 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002164 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002165 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002166" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002167 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002168 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002169 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002170 " ER: the tmpfile is full path: rcp sees C:\... as host C
2171 if s:netrw_has_nt_rcp == 1
2172 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2173 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2174 else
2175 " Any way needed it machine contains a '.'
2176 let uid_machine = g:netrw_machine .'.'. $USERNAME
2177 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002178 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002179 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2180 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2181 else
2182 let uid_machine = g:netrw_machine
2183 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002184 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002185 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 +00002186 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002187 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002188
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002189 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002190 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002191 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002192" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002193 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002194 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002195 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002196 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002197 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002198" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002199 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002200 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002201" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002202 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002203 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002204" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002205 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002206 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 +00002207 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002208 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002209 endif
2210 " 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 +00002211 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002212 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002213 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002214 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002215 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002216 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002217 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002218 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002219 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2220 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002221 q!
2222 endif
2223 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002224 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002225 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002226
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002227 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002228 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2230 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002231" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002232 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002233 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002234 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002235 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002236 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002237 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002238" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002239 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002240 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002241" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002242 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002243
Bram Moolenaar97d62492012-11-15 21:28:22 +01002244 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002245 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002246 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002247" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002248 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002249 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002250 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002251" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002252 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002253 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002255 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002256 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002257
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002258 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002259 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002260" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002261 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002262 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002263 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002264" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002265 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002266 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002267" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002268
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002269 " perform ftp:
2270 " -i : turns off interactive prompting from ftp
2271 " -n unix : DON'T use <.netrc>, even though it exists
2272 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002273 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002274 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002275 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2276 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002277" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002278 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002279 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002280 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002281 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002282 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002283 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002285
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002286 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002287 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002288 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002289" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002290 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002291 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002292 else
2293 let useport= ""
2294 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002295 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2296 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002297 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002298 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2299 else
2300 let tmpfile_get = tmpfile
2301 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002302 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 +00002303 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002304 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002305
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002306 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002307 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002308 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002309" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002310 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002311 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002312 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002313 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002314" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002315 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002316 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002317
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002318 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2319 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002320" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002321 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002322 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 +00002323 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002324 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 +00002325 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002326 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002327
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002328 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002329 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002330" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002331 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2332 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002333" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2334" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2335 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 +00002336 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002337" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002338 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002339 endif
2340 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002341" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002342 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002343
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002344 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002345 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002346 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002347" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002348
Bram Moolenaar5c736222010-01-06 20:54:52 +01002349 if !executable(g:netrw_dav_cmd)
2350 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2351" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2352 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002353 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002354 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002355 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 +01002356 else
2357 " Construct execution string (four lines) which will be passed through filter
2358 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2359 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002360 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002361 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002362 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002363 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002364 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002365 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002366 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002367 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002368 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002369 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2370 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002371
Bram Moolenaar5c736222010-01-06 20:54:52 +01002372 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002373 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002374 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002375 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002376 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002377 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002378 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002379
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002380 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002381 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002382 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002383" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002384 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 +00002385 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002387
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002388 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002389 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002390 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002391 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002392" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002394 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002395 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002396 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002397" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002398 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002399 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002400 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002401 let netrw_option= "http"
2402 else
2403 let netrw_option= "ftp"
2404 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002405" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002406
Bram Moolenaar446cb832008-06-24 21:56:24 +00002407 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002408 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 +00002409 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002410 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 +00002411 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002412
Bram Moolenaar446cb832008-06-24 21:56:24 +00002413 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002414 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002415" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002416 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002417
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002418 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002419 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002420 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002421" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2422 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 +00002423 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002424 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002425
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002426 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002427 " NetRead: (file) NetRead Method #10 {{{3
2428 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002429" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2430 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002431 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2432 let b:netrw_lastfile = choice
2433
2434 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002435 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002436 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002437 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002438 endif
2439 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002440
Bram Moolenaar5c736222010-01-06 20:54:52 +01002441 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002442 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002443" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002444 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002445 unlet b:netrw_fname
2446 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002447 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 +01002448" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002449 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002450 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002451 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002452
Bram Moolenaar9964e462007-05-05 17:54:07 +00002453" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002454endfun
2455
2456" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002457" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002458fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002459" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002460
Bram Moolenaar5c736222010-01-06 20:54:52 +01002461 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002462 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002463 call s:NetrwOptionsSave("w:")
2464 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002465
Bram Moolenaar5c736222010-01-06 20:54:52 +01002466 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002467 let tmpfile= s:GetTempfile("")
2468 if tmpfile == ""
2469" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002470 return
2471 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002472
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002473 if a:0 == 0
2474 let ichoice = 0
2475 else
2476 let ichoice = 1
2477 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002478
Bram Moolenaar9964e462007-05-05 17:54:07 +00002479 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002480" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002481 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002482 " For binary writes, always write entire file.
2483 " (line numbers don't really make sense for that).
2484 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002485" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002486 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002487 elseif g:netrw_cygwin
2488 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002489 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002490" 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 +01002491 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002492 else
2493 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002494" 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 +01002495 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002496 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002497
Bram Moolenaar9964e462007-05-05 17:54:07 +00002498 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002499 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002500 " on the temporary file's name. Deletion of the temporary file during
2501 " cleanup then causes an error message.
2502 0file!
2503 endif
2504
Bram Moolenaar5c736222010-01-06 20:54:52 +01002505 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002506 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002507
Bram Moolenaar9964e462007-05-05 17:54:07 +00002508 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002509 " attempt to repeat with previous host-file-etc
2510 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002511" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002512 let choice = b:netrw_lastfile
2513 let ichoice= ichoice + 1
2514 else
2515 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002516
Bram Moolenaar8d043172014-01-23 14:24:41 +01002517 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002518 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002519 echomsg 'NetWrite Usage:"'
2520 echomsg ':Nwrite machine:path uses rcp'
2521 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2522 echomsg ':Nwrite "machine id password path" uses ftp'
2523 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2524 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2525 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2526 echomsg ':Nwrite rcp://machine/path uses rcp'
2527 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2528 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2529 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002530 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002531 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002532
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002533 elseif match(choice,"^\"") != -1
2534 if match(choice,"\"$") != -1
2535 " case "..."
2536 let choice=strpart(choice,1,strlen(choice)-2)
2537 else
2538 " case "... ... ..."
2539 let choice = strpart(choice,1,strlen(choice)-1)
2540 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002541
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002542 while match(choice,"\"$") == -1
2543 let wholechoice= wholechoice . " " . choice
2544 let ichoice = ichoice + 1
2545 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002546 if !exists("g:netrw_quiet")
2547 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2548 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002549" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002550 return
2551 endif
2552 let choice= a:{ichoice}
2553 endwhile
2554 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2555 endif
2556 endif
2557 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002558 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002559" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002560
Bram Moolenaar9964e462007-05-05 17:54:07 +00002561 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002562 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002563 if !exists("b:netrw_method") || b:netrw_method < 0
2564" call Dfunc("netrw#NetWrite : unsupported method")
2565 return
2566 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002567
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002568 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002569 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002570 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002571 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2572 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002573" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002574 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002575
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002576 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002577 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002578 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002579" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002580 if s:netrw_has_nt_rcp == 1
2581 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2582 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2583 else
2584 let uid_machine = g:netrw_machine .'.'. $USERNAME
2585 endif
2586 else
2587 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2588 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2589 else
2590 let uid_machine = g:netrw_machine
2591 endif
2592 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002593 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 +00002594 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002595
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002596 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002597 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002598 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002599" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002600 let netrw_fname = b:netrw_fname
2601
2602 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2603 let bhkeep = &l:bh
2604 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002605 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002607
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002608" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002609 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002610 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002612 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002613 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002614" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002615 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002616 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002617" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002619 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 +00002620 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002621" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2622 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 endif
2624 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2625 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002626 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002627 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002628 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002629 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002631
2632 " remove enew buffer (quietly)
2633 let filtbuf= bufnr("%")
2634 exe curbuf."b!"
2635 let &l:bh = bhkeep
2636 exe filtbuf."bw!"
2637
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002639
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002640 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002641 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002642 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002643 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002644" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002645 let netrw_fname = b:netrw_fname
2646 let bhkeep = &l:bh
2647
2648 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2649 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002650 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002651 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002652 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002653
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002654 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002655 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002656" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002657 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002658 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002659" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002660 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002661 if exists("g:netrw_uid") && g:netrw_uid != ""
2662 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002663 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002664" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002665 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002666 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002667 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002668" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002669 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002670 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002671" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002672 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002673 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002674 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002675" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002676 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002677 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002678" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002679 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002680 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002681" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002682 " save choice/id/password for future use
2683 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002684
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002685 " perform ftp:
2686 " -i : turns off interactive prompting from ftp
2687 " -n unix : DON'T use <.netrc>, even though it exists
2688 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002689 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002690 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002691 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2692 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002693 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002694 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002695 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002696 let mod=1
2697 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002698
2699 " remove enew buffer (quietly)
2700 let filtbuf= bufnr("%")
2701 exe curbuf."b!"
2702 let &l:bh= bhkeep
2703 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002704
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002705 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002706 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002707 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002708" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002709 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002710 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002711 else
2712 let useport= ""
2713 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002714 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 +00002715 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002716
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002717 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002718 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002719 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002720" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002721 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2722 if executable(curl)
2723 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002724 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 +01002725 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002726 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002727 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002728
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002729 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002730 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002731 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002732" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002733
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002734 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002735 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2736 let bhkeep = &l:bh
2737
2738 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2739 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002740 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002741 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002742
Bram Moolenaarff034192013-04-24 18:51:19 +02002743 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002744 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002745 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002746 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002747 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002748 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002749 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002750 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002751 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002752 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002753
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002754 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002755 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002756 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002757
2758 " remove enew buffer (quietly)
2759 let filtbuf= bufnr("%")
2760 exe curbuf."b!"
2761 let &l:bh = bhkeep
2762 exe filtbuf."bw!"
2763
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002764 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002765
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002766 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002767 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002768 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002769" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002770 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 +00002771 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002772
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002773 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002774 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002775 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002776" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002777 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2779 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2780 else
2781 let uid_machine = g:netrw_machine
2782 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002783
2784 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2785 let bhkeep = &l:bh
2786 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002787 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002788 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002789
Bram Moolenaarff034192013-04-24 18:51:19 +02002790 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002791 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002792" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002793 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002794 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002795 let filtbuf= bufnr("%")
2796 exe curbuf."b!"
2797 let &l:bh = bhkeep
2798 exe filtbuf."bw!"
2799 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002800
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002801 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002802 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002803 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002804 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002805 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002807 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002808
Bram Moolenaar5c736222010-01-06 20:54:52 +01002809 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002810" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002811 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002812" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002813 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002814 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002815 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002816
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002817 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002818 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002819 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002820" 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 +02002821 elseif !exists("leavemod")
2822 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002823" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002824 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002825" 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 +00002826 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002827
Bram Moolenaar9964e462007-05-05 17:54:07 +00002828" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002829endfun
2830
2831" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002832" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002833" uses NetRead to get a copy of the file into a temporarily file,
2834" then sources that file,
2835" then removes that file.
2836fun! netrw#NetSource(...)
2837" call Dfunc("netrw#NetSource() a:0=".a:0)
2838 if a:0 > 0 && a:1 == '?'
2839 " give help
2840 echomsg 'NetSource Usage:'
2841 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2842 echomsg ':Nsource fetch://machine/path uses fetch'
2843 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002844 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002845 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2846 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2847 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2848 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2849 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002850 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002851 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002852 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002853 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002854" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002855 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002856" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002857 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002858" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002859 if delete(s:netrw_tmpfile)
2860 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2861 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002862 unlet s:netrw_tmpfile
2863 else
2864 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2865 endif
2866 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002867 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002868 endif
2869" call Dret("netrw#NetSource")
2870endfun
2871
Bram Moolenaar8d043172014-01-23 14:24:41 +01002872" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002873" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2874" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002875fun! netrw#SetTreetop(iscmd,...)
2876" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2877" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002878
Bram Moolenaar85850f32019-07-19 22:05:51 +02002879 " iscmd==0: netrw#SetTreetop called using gn mapping
2880 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2881" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002882 " clear out the current tree
2883 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002884" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002885 let inittreetop= w:netrw_treetop
2886 unlet w:netrw_treetop
2887 endif
2888 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002889" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002890 unlet w:netrw_treedict
2891 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002892" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002893
Bram Moolenaar85850f32019-07-19 22:05:51 +02002894 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002895 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002896" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002897 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002898 if isdirectory(s:NetrwFile(a:1))
2899" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002900 let treedir = a:1
2901 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002902 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002903 let treedir = b:netrw_curdir."/".a:1
2904 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002905" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002906 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002907 " normally the cursor is left in the message window.
2908 " However, here this results in the directory being listed in the message window, which is not wanted.
2909 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002910 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002911 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002912 let treedir = "."
2913 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002914 endif
2915 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002916" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002917
2918 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002919 let islocal= expand("%") !~ '^\a\{3,}://'
2920" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002921
2922 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002923 if islocal
2924 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2925 else
2926 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2927 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002928
Bram Moolenaara6878372014-03-22 21:02:50 +01002929" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002930endfun
2931
Bram Moolenaar9964e462007-05-05 17:54:07 +00002932" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002933" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002934" readcmd == %r : replace buffer with newly read file
2935" == 0r : read file at top of buffer
2936" == r : read file after current line
2937" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002938fun! s:NetrwGetFile(readcmd, tfile, method)
2939" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002940
2941 " readcmd=='t': simply do nothing
2942 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002943" 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 +01002944" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002945 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002946 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002947
Bram Moolenaar9964e462007-05-05 17:54:07 +00002948 " get name of remote filename (ie. url and all)
2949 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002950" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002951
Bram Moolenaar9964e462007-05-05 17:54:07 +00002952 if exists("*NetReadFixup")
2953 " for the use of NetReadFixup (not otherwise used internally)
2954 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002955 endif
2956
Bram Moolenaar9964e462007-05-05 17:54:07 +00002957 if a:readcmd[0] == '%'
2958 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002959" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002960
2961 " rename the current buffer to the temp file (ie. tfile)
2962 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002963 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002964 else
2965 let tfile= a:tfile
2966 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002967 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002968
2969 " edit temporary file (ie. read the temporary file in)
2970 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002971" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002972 call zip#Browse(tfile)
2973 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002974" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.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\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002977" call Decho("handling remote gzip-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\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002981 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002982 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002983" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002984 call tar#Browse(tfile)
2985 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002986" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002987 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002988 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002989" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002990 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002991 endif
2992
2993 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002994 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002995
Bram Moolenaar71badf92023-04-22 22:40:14 +01002996 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002997 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002998 " Note that isk must not include a "/" for scripts.vim
2999 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01003000" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
3001" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003002" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003003" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3004 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003005 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003006 filetype detect
3007" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003008 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003009" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003010 let line1 = 1
3011 let line2 = line("$")
3012
Bram Moolenaar8d043172014-01-23 14:24:41 +01003013 elseif !&ma
3014 " 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 +01003015 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003016" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003017 return
3018
Bram Moolenaar9964e462007-05-05 17:54:07 +00003019 elseif s:FileReadable(a:tfile)
3020 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003021" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003022 let curline = line(".")
3023 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003024" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003025 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003026 let line1= curline + 1
3027 let line2= line("$") - lastline + 1
3028
3029 else
3030 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003031" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3032" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003033 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003034" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003035 return
3036 endif
3037
3038 " User-provided (ie. optional) fix-it-up command
3039 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003040" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003041 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003042" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003043" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003044 endif
3045
Bram Moolenaaradc21822011-04-01 18:03:16 +02003046 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003047 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003048 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003049 endif
3050
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003051" 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 +00003052
3053 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003054" redraw!
3055
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003056" 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 +00003057" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003058endfun
3059
Bram Moolenaar9964e462007-05-05 17:54:07 +00003060" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003061" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003062" Input:
3063" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3064" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003065" b:netrw_method= 1: rcp
3066" 2: ftp + <.netrc>
3067" 3: ftp + machine, id, password, and [path]filename
3068" 4: scp
3069" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003070" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003071" 7: rsync
3072" 8: fetch
3073" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003074" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003075" g:netrw_machine= hostname
3076" b:netrw_fname = filename
3077" g:netrw_port = optional port number (for ftp)
3078" g:netrw_choice = copy of input url (choice)
3079fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003080" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003081
Bram Moolenaar251e1912011-06-19 05:09:16 +02003082 " sanity check: choice should have at least three slashes in it
3083 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3084 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3085 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003086" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003087 return
3088 endif
3089
Bram Moolenaar5c736222010-01-06 20:54:52 +01003090 " record current g:netrw_machine, if any
3091 " curmachine used if protocol == ftp and no .netrc
3092 if exists("g:netrw_machine")
3093 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003094" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003095 else
3096 let curmachine= "N O T A HOST"
3097 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003098 if exists("g:netrw_port")
3099 let netrw_port= g:netrw_port
3100 endif
3101
3102 " insure that netrw_ftp_cmd starts off every method determination
3103 " with the current g:netrw_ftp_cmd
3104 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003105
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003106 " initialization
3107 let b:netrw_method = 0
3108 let g:netrw_machine = ""
3109 let b:netrw_fname = ""
3110 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003111 let g:netrw_choice = a:choice
3112
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003113 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003114 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003115 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3116 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003117 " rcpurm : rcp://[user@]host/filename Use rcp
3118 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003119 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003120 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003121 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003122 " rsyncurm : rsync://host[:port]/path Use rsync
3123 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3124 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003125 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3127 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003128 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3129 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003130 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003131 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003132 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003133 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003135 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003136 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003137 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003138
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003139" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003140 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003141 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003142 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003143" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003144 let b:netrw_method = 1
3145 let userid = substitute(a:choice,rcpurm,'\1',"")
3146 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3147 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003148 if userid != ""
3149 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003151
Bram Moolenaaradc21822011-04-01 18:03:16 +02003152 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003153 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003154" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003155 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003156 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3157 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3158 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003159
Bram Moolenaar15146672011-10-20 22:22:38 +02003160 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003161 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003162" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003163 let b:netrw_method = 5
3164 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3165 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003166 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003167
Bram Moolenaaradc21822011-04-01 18:03:16 +02003168 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003169 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003170" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003171 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003172 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003173 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3174 else
3175 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3176 endif
3177 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003178
Bram Moolenaaradc21822011-04-01 18:03:16 +02003179 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003180 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003181" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003182 let b:netrw_method = 7
3183 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3184 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003185
Bram Moolenaaradc21822011-04-01 18:03:16 +02003186 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003187 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003188" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003189 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003190 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3191 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3192 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003193" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003194 if userid != ""
3195 let g:netrw_uid= userid
3196 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003197
Bram Moolenaaradc21822011-04-01 18:03:16 +02003198 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003199 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003200 call NetUserPass("ftp:".g:netrw_machine)
3201 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003202 " if there's a change in hostname, require password re-entry
3203 unlet s:netrw_passwd
3204 endif
3205 if exists("netrw_port")
3206 unlet netrw_port
3207 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003208 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003209
Bram Moolenaar446cb832008-06-24 21:56:24 +00003210 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003211 let b:netrw_method = 3
3212 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003213 let host= substitute(g:netrw_machine,'\..*$','','')
3214 if exists("s:netrw_hup[host]")
3215 call NetUserPass("ftp:".host)
3216
Nir Lichtman1e34b952024-05-08 19:19:34 +02003217 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003218" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3219" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003220 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003221 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003222" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003223 endif
3224 let b:netrw_method= 2
3225 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003226" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003227 let b:netrw_method= 2
3228 else
3229 if !exists("g:netrw_uid") || g:netrw_uid == ""
3230 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003231 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003232 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003233 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003234 endif
3235 let b:netrw_method= 3
3236 endif
3237 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003238
Bram Moolenaaradc21822011-04-01 18:03:16 +02003239 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003240 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003241" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003242 let b:netrw_method = 8
3243 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3244 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3245 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3246 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003247
Bram Moolenaaradc21822011-04-01 18:03:16 +02003248 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003249 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003250" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003252 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3253 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003254 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003255 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003256 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003257
Bram Moolenaaradc21822011-04-01 18:03:16 +02003258 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003259 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003260" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003261 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003262 let b:netrw_method = 3
3263 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3264 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003265
Bram Moolenaar9964e462007-05-05 17:54:07 +00003266 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003267 let b:netrw_method = 2
3268 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3269 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3270 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003271
Bram Moolenaaradc21822011-04-01 18:03:16 +02003272 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003273 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003274" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003275 let b:netrw_method = 9
3276 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3277 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003278
Bram Moolenaaradc21822011-04-01 18:03:16 +02003279 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003280 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003281" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003282 let b:netrw_method = 1
3283 let userid = substitute(a:choice,rcphf,'\2',"")
3284 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3285 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003286" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3287" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3288" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3289" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003290 if userid != ""
3291 let g:netrw_uid= userid
3292 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003293
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003294 " Method#10: file://user@hostname/...path-to-file {{{3
3295 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003296" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003297 let b:netrw_method = 10
3298 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003299" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003300
Bram Moolenaaradc21822011-04-01 18:03:16 +02003301 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003302 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003303 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003304 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003305 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003306 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003308 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003309
Bram Moolenaar81695252004-12-29 20:58:21 +00003310 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003311 " remove any leading [:#] from port number
3312 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3313 elseif exists("netrw_port")
3314 " retain port number as implicit for subsequent ftp operations
3315 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003316 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003317
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003318" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3319" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3320" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3321" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003322" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003323" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003324" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003325" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003326" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003327" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003328" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003329" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331
Bram Moolenaar9964e462007-05-05 17:54:07 +00003332" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003333" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003334" Usage: :call NetUserPass() -- will prompt for userid and password
3335" :call NetUserPass("uid") -- will prompt for password
3336" :call NetUserPass("uid","password") -- sets global userid and password
3337" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3338" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339fun! NetUserPass(...)
3340
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003341" call Dfunc("NetUserPass() a:0=".a:0)
3342
3343 if !exists('s:netrw_hup')
3344 let s:netrw_hup= {}
3345 endif
3346
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003348 " case: no input arguments
3349
3350 " change host and username if not previously entered; get new password
3351 if !exists("g:netrw_machine")
3352 let g:netrw_machine= input('Enter hostname: ')
3353 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003355 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356 let g:netrw_uid= input('Enter username: ')
3357 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003358 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003359 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003360
3361 " set up hup database
3362 let host = substitute(g:netrw_machine,'\..*$','','')
3363 if !exists('s:netrw_hup[host]')
3364 let s:netrw_hup[host]= {}
3365 endif
3366 let s:netrw_hup[host].uid = g:netrw_uid
3367 let s:netrw_hup[host].passwd = s:netrw_passwd
3368
3369 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003370 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003371
3372 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003373 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003374 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003375" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003376 let host = substitute(a:1,'^ftp:','','')
3377 let host = substitute(host,'\..*','','')
3378 if exists("s:netrw_hup[host]")
3379 let g:netrw_uid = s:netrw_hup[host].uid
3380 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003381" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3382" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003383 else
3384 let g:netrw_uid = input("Enter UserId: ")
3385 let s:netrw_passwd = inputsecret("Enter Password: ")
3386 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003387
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003388 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003389 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003390" 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 +02003391 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003392 if g:netrw_machine =~ '[0-9.]\+'
3393 let host= g:netrw_machine
3394 else
3395 let host= substitute(g:netrw_machine,'\..*$','','')
3396 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003397 else
3398 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003399 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003400 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003401" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003402 if exists("g:netrw_passwd")
3403 " ask for password if one not previously entered
3404 let s:netrw_passwd= g:netrw_passwd
3405 else
3406 let s:netrw_passwd = inputsecret("Enter Password: ")
3407 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003408 endif
3409
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003410" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003411 if exists("host")
3412 if !exists('s:netrw_hup[host]')
3413 let s:netrw_hup[host]= {}
3414 endif
3415 let s:netrw_hup[host].uid = g:netrw_uid
3416 let s:netrw_hup[host].passwd = s:netrw_passwd
3417 endif
3418
3419 elseif a:0 == 2
3420 let g:netrw_uid = a:1
3421 let s:netrw_passwd = a:2
3422
3423 elseif a:0 == 3
3424 " enter hostname, user-id, and password into the hup dictionary
3425 let host = substitute(a:1,'^\a\+:','','')
3426 let host = substitute(host,'\..*$','','')
3427 if !exists('s:netrw_hup[host]')
3428 let s:netrw_hup[host]= {}
3429 endif
3430 let s:netrw_hup[host].uid = a:2
3431 let s:netrw_hup[host].passwd = a:3
3432 let g:netrw_uid = s:netrw_hup[host].uid
3433 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003434" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3435" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003436 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003437
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003438" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440
Bram Moolenaar85850f32019-07-19 22:05:51 +02003441" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003442" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003443" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003444
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003445" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003446" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3447fun! s:ExplorePatHls(pattern)
3448" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3449 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003450" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003451 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003452" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003453 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3454" call Dret("s:ExplorePatHls repat<".repat.">")
3455 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003456endfun
3457
3458" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003459" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003460" 0: (user: <mb>) bookmark current directory
3461" 1: (user: <gb>) change to the bookmarked directory
3462" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003463" 3: (browsing) records current directory history
3464" 4: (user: <u>) go up (previous) directory, using history
3465" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003466" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003467fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003468" 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 +02003469 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3470" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3471 return
3472 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003473
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003474 let ykeep = @@
3475 let curbufnr = bufnr("%")
3476
Bram Moolenaar9964e462007-05-05 17:54:07 +00003477 if a:chg == 0
3478 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003479" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003480 if exists("s:netrwmarkfilelist_{curbufnr}")
3481 call s:NetrwBookmark(0)
3482 echo "bookmarked marked files"
3483 else
3484 call s:MakeBookmark(a:curdir)
3485 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003486 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003487
KSR-Yasudaf4498252023-10-06 03:34:17 +09003488 try
3489 call s:NetrwBookHistSave()
3490 catch
3491 endtry
3492
Bram Moolenaar9964e462007-05-05 17:54:07 +00003493 elseif a:chg == 1
3494 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003495" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003496 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003497" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003498 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003499 else
3500 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3501 endif
3502
3503 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003504" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003505 let didwork= 0
3506 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003507" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003508 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003509" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003510 let cnt= 1
3511 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003512" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003513 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003514 let didwork = 1
3515 let cnt = cnt + 1
3516 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003517 endif
3518
3519 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003520 " Note: history is saved only when PerformListing is done;
3521 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3522 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003523 let first = 1
3524 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003525 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003526 while ( first || cnt != g:netrw_dirhistcnt )
3527" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003528 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003529" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003530 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003531 let didwork= 1
3532 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003533 let histcnt = histcnt + 1
3534 let first = 0
3535 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003536 if cnt < 0
3537 let cnt= cnt + g:netrw_dirhistmax
3538 endif
3539 endwhile
3540 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003541 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003542 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003543 if didwork
3544 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3545 endif
3546
3547 elseif a:chg == 3
3548 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003549" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003550 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 +02003551 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003552 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3553 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003554 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003555" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003556 endif
3557
3558 elseif a:chg == 4
3559 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003560" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003561 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003562 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3563 if g:netrw_dirhistcnt < 0
3564 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003565 endif
3566 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003567 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003568 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003569 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3570" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003571 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003572 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003573" call Decho("setl ma noro",'~'.expand("<slnum>"))
3574 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003575 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003576" call Decho("setl nomod",'~'.expand("<slnum>"))
3577" 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 +00003578 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003579" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3580 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003581 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003582 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003583 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003584 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003585 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003586 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003587 echo "Sorry, no predecessor directory exists yet"
3588 endif
3589
3590 elseif a:chg == 5
3591 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003592" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003593 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003594 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3595 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3596" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003597 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003598" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003599 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003600 sil! NetrwKeepj %d _
3601" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3602" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003603 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003604" 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 +02003605 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003606" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3607 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003608 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003609 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3610 if g:netrw_dirhistcnt < 0
3611 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003612 endif
3613 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003614 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003615 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003616 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003617 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003618 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003619
3620 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003621" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003622 if exists("s:netrwmarkfilelist_{curbufnr}")
3623 call s:NetrwBookmark(1)
3624 echo "removed marked files from bookmarks"
3625 else
3626 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003627 let iremove = v:count
3628 let dremove = g:netrw_bookmarklist[iremove - 1]
3629" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003630 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003631" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3632 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3633 echo "removed ".dremove." from g:netrw_bookmarklist"
3634" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003635 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003636" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003637
3638 try
3639 call s:NetrwBookHistSave()
3640 catch
3641 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003642 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003643 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003644 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003645 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003646" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003647endfun
3648
3649" ---------------------------------------------------------------------
3650" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003651" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003652" Sister function: s:NetrwBookHistSave()
3653fun! s:NetrwBookHistRead()
3654" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003655 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003656" 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 +02003657 return
3658 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003659 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003660
3661 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003662 if !exists("s:netrw_initbookhist")
3663 let home = s:NetrwHome()
3664 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003665 if filereadable(s:NetrwFile(savefile))
3666" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003667 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003668 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003669
3670 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003671 if g:netrw_dirhistmax > 0
3672 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003673 if filereadable(s:NetrwFile(savefile))
3674" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003675 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003676 endif
3677 let s:netrw_initbookhist= 1
3678 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003679 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003680 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003681
Bram Moolenaar97d62492012-11-15 21:28:22 +01003682 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003683" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3684" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003685" call Dret("s:NetrwBookHistRead")
3686endfun
3687
3688" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003689" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003690" Sister function: s:NetrwBookHistRead()
3691" I used to do this via viminfo but that appears to
3692" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003693" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3694" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003695" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003696fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003697" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003698 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003699" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003700 return
3701 endif
3702
Bram Moolenaar5c736222010-01-06 20:54:52 +01003703 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003704" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003705 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003706
3707 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003708 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003709" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003710 if g:netrw_use_noswf
3711 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3712 else
3713 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3714 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003715 setl nocin noai noci magic nospell nohid wig= noaw
3716 setl ma noro write
3717 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003718 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003719
Bram Moolenaar85850f32019-07-19 22:05:51 +02003720 " rename enew'd file: .netrwhist -- no attempt to merge
3721 " record dirhistmax and current dirhistcnt
3722 " save history
3723" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003724 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003725 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003726 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3727 if g:netrw_dirhistmax > 0
3728 let lastline = line("$")
3729 let cnt = g:netrw_dirhistcnt
3730 let first = 1
3731 while ( first || cnt != g:netrw_dirhistcnt )
3732 let lastline= lastline + 1
3733 if exists("g:netrw_dirhist_{cnt}")
3734 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3735" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3736 endif
3737 let first = 0
3738 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3739 if cnt < 0
3740 let cnt= cnt + g:netrw_dirhistmax
3741 endif
3742 endwhile
3743 exe "sil! w! ".savefile
3744" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3745 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003746
Bram Moolenaar85850f32019-07-19 22:05:51 +02003747 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003748 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003749 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003750" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003751 " merge and write .netrwbook
3752 let savefile= s:NetrwHome()."/.netrwbook"
3753
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003754 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003755 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003756 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003757 for bdm in booklist
3758 if index(g:netrw_bookmarklist,bdm) == -1
3759 call add(g:netrw_bookmarklist,bdm)
3760 endif
3761 endfor
3762 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003763 endif
3764
3765 " construct and save .netrwbook
3766 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003767 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003768" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003769 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003770
3771 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003772 let bgone= bufnr("%")
3773 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003774 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003775
3776" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003777endfun
3778
3779" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003780" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3781" list of the contents of a local or remote directory. It is assumed that the
3782" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3783" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003784" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003785fun! s:NetrwBrowse(islocal,dirname)
3786 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003787" 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 +02003788" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3789" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3790" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003791
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003792 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3793 " This is useful when one edits a local file, then :e ., then :Rex
3794 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3795 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003796" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003797 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003798
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003799 " s:NetrwBrowse : initialize history {{{3
3800 if !exists("s:netrw_initbookhist")
3801 NetrwKeepj call s:NetrwBookHistRead()
3802 endif
3803
3804 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003805 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003806 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003807" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003808 else
3809 let dirname= a:dirname
3810 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003811
Bram Moolenaar85850f32019-07-19 22:05:51 +02003812 " repoint t:netrw_lexbufnr if appropriate
3813 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3814" call Decho("set repointlexbufnr to true!")
3815 let repointlexbufnr= 1
3816 endif
3817
3818 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003819 if exists("s:netrw_skipbrowse")
3820 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003821" 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 +01003822" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003823 return
3824 endif
3825 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003826 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003827" call Dret("s:NetrwBrowse : missing shellescape()")
3828 return
3829 endif
3830 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003831 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003832" call Dret("s:NetrwBrowse : missing fnameescape()")
3833 return
3834 endif
3835
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003836 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003837 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003838
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003839 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003840 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3841 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3842" call Decho("clearing marked files",'~'.expand("<slnum>"))
3843 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3844 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003845 endif
3846
3847 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003848 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003849" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3850" 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 +02003851 if s:NetrwLcd(dirname)
3852" call Dret("s:NetrwBrowse : lcd failure")
3853 return
3854 endif
3855 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003856" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003857
Bram Moolenaar5c736222010-01-06 20:54:52 +01003858 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003859 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003860" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003861 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003862" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003863 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003864 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003865 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003866" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003867
3868 " remove any filetype indicator from end of dirname, except for the
3869 " "this is a directory" indicator (/).
3870 " There shouldn't be one of those here, anyway.
3871 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003872" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003873 call s:RemotePathAnalysis(dirname)
3874
3875 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3876 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003877 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003878 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003879" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003880 let b:netrw_curdir = dirname
3881 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003882 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003883 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3884 sil call netrw#NetRead(2,url)
3885 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003886" call Decho("url<".url.">",'~'.expand("<slnum>"))
3887" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3888" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003889 if s:path =~ '.bz2'
3890 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3891 elseif s:path =~ '.gz'
3892 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3893 elseif s:path =~ '.gz'
3894 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3895 else
3896 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3897 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003898 endif
3899
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003900 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003901 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003902 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003903" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003904 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003905" 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 +00003906
Bram Moolenaar446cb832008-06-24 21:56:24 +00003907" call Dret("s:NetrwBrowse : file<".s:fname.">")
3908 return
3909 endif
3910
Bram Moolenaaradc21822011-04-01 18:03:16 +02003911 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003912 call s:UseBufWinVars()
3913
3914 " set up some variables {{{3
3915 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003916 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003917 let s:last_sort_by = g:netrw_sort_by
3918
3919 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003920 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003921
Bram Moolenaar97d62492012-11-15 21:28:22 +01003922 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003923" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003924 let svpos = winsaveview()
3925" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003926 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003927
Bram Moolenaar446cb832008-06-24 21:56:24 +00003928 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003929 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3930 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3931" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3932" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3933 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3934 else
3935" " call Decho("2match none",'~'.expand("<slnum>"))
3936 2match none
3937 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003938 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003939 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003940 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003941" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003942 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003943" 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 +01003944" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003945 return
3946 endif
3947
3948 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003949" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003950 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003951 if b:netrw_curdir =~ '[/\\]$'
3952 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3953 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003954 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003955 let b:netrw_curdir= b:netrw_curdir."/"
3956 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003957 if b:netrw_curdir == ''
3958 if has("amiga")
3959 " On the Amiga, the empty string connotes the current directory
3960 let b:netrw_curdir= getcwd()
3961 else
3962 " under unix, when the root directory is encountered, the result
3963 " from the preceding substitute is an empty string.
3964 let b:netrw_curdir= '/'
3965 endif
3966 endif
3967 if !a:islocal && b:netrw_curdir !~ '/$'
3968 let b:netrw_curdir= b:netrw_curdir.'/'
3969 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003970" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003971
3972 " ------------
3973 " (local only) {{{3
3974 " ------------
3975 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003976" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003977
3978 " Set up ShellCmdPost handling. Append current buffer to browselist
3979 call s:LocalFastBrowser()
3980
3981 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3982 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003983" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3984" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003985 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003986 if s:NetrwLcd(b:netrw_curdir)
3987" call Dret("s:NetrwBrowse : lcd failure")
3988 return
3989 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003990 endif
3991 endif
3992
3993 " --------------------------------
3994 " remote handling: {{{3
3995 " --------------------------------
3996 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003997" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003998
Bram Moolenaar97d62492012-11-15 21:28:22 +01003999 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004000" 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 +02004001 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004002 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004003" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004004 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4005 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4006 if dirname !~ '/$'
4007 let dirname= dirname.'/'
4008 endif
4009 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004010" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004011 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004012 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004013" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004014 endif
4015
4016 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4017 if dirname !~ dirpat
4018 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004019 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004020 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004021 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004022" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004023 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004024" 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 +00004025" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4026 return
4027 endif
4028 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004029" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004030 endif " (additional remote handling)
4031
Bram Moolenaar85850f32019-07-19 22:05:51 +02004032 " -------------------------------
4033 " Perform Directory Listing: {{{3
4034 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004035 NetrwKeepj call s:NetrwMaps(a:islocal)
4036 NetrwKeepj call s:NetrwCommands(a:islocal)
4037 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004038
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004039 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004040 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004041" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4042
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004043 " If there is a rexposn: restore position with rexposn
4044 " Otherwise : set rexposn
4045 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004046" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4047 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4048 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4049 NetrwKeepj exe w:netrw_bannercnt
4050 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004051 else
4052 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4053 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004054 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004055 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004056" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004057 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004058 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004059
Bram Moolenaar85850f32019-07-19 22:05:51 +02004060 " repoint t:netrw_lexbufnr if appropriate
4061 if exists("repointlexbufnr")
4062 let t:netrw_lexbufnr= bufnr("%")
4063" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4064 endif
4065
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004066 " restore position
4067 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004068" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4069 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004070 endif
4071
Bram Moolenaara6878372014-03-22 21:02:50 +01004072 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004073 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4074 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004075" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4076" 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 +02004077" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004078 return
4079endfun
4080
4081" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004082" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4083" may not apply correctly; ie. netrw's idea of the current directory may
4084" differ from vim's. This function insures that netrw's idea of the current
4085" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004086" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004087fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004088" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4089" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4090" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4091" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4092" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004093
4094 " clean up any leading treedepthstring
4095 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4096 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004097" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004098 else
4099 let fname= a:fname
4100 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004101
4102 if g:netrw_keepdir
4103 " vim's idea of the current directory possibly may differ from netrw's
4104 if !exists("b:netrw_curdir")
4105 let b:netrw_curdir= getcwd()
4106 endif
4107
Nir Lichtman1e34b952024-05-08 19:19:34 +02004108 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004109 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004110 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004111 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004112" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113 else
4114 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004115 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004116" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004117 endif
4118
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004119 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004120 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004121 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004122" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004123 else
4124 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004125 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004126" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004127 endif
4128 else
4129 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004130 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004131" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4132" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4133" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004134 endif
4135
Bram Moolenaar85850f32019-07-19 22:05:51 +02004136" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004137 return ret
4138endfun
4139
4140" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004141" s:NetrwFileInfo: supports qf (query for file information) {{{2
4142fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004143" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004144 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004145 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004146 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004147 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004148 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004149 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004150 let lsopt= "-lsadh --si"
4151 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004152" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004153 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004154
4155 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004156 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004157" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004158
Bram Moolenaara6878372014-03-22 21:02:50 +01004159 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004160 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004161" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004162
4163 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004164 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004165" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004166
Bram Moolenaar446cb832008-06-24 21:56:24 +00004167 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004168" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004169 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004170" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004171 endif
4172 else
4173 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004174" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4175 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004176 let fname= substitute(a:fname,".$","","")
4177 else
4178 let fname= a:fname
4179 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004180 let t = getftime(s:NetrwFile(fname))
4181 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004182 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004183 let sz= s:NetrwHumanReadable(sz)
4184 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004185 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4186" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004187 endif
4188 else
4189 echo "sorry, \"qf\" not supported yet for remote files"
4190 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004191 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004192" call Dret("s:NetrwFileInfo")
4193endfun
4194
4195" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004196" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4197fun! s:NetrwFullPath(filename)
4198" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4199 let filename= a:filename
4200 if filename !~ '^/'
4201 let filename= resolve(getcwd().'/'.filename)
4202 endif
4203 if filename != "/" && filename =~ '/$'
4204 let filename= substitute(filename,'/$','','')
4205 endif
4206" " call Dret("s:NetrwFullPath <".filename.">")
4207 return filename
4208endfun
4209
4210" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004211" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004212" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004213" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004214" 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 +00004215fun! s:NetrwGetBuffer(islocal,dirname)
4216" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004217" 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 +02004218" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4219" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004220 let dirname= a:dirname
4221
4222 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004223" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004224 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004225" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004226 let s:netrwbuf= {}
4227 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004228" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4229" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4230
4231 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4232 let bufnum = -1
4233
4234 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4235 if has_key(s:netrwbuf,"NetrwTreeListing")
4236 let bufnum= s:netrwbuf["NetrwTreeListing"]
4237 else
4238 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4239 endif
4240" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4241 if !bufexists(bufnum)
4242 call remove(s:netrwbuf,"NetrwTreeListing"])
4243 let bufnum= -1
4244 endif
4245 elseif bufnr("NetrwTreeListing") != -1
4246 let bufnum= bufnr("NetrwTreeListing")
4247" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4248 else
4249" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4250 let bufnum= -1
4251 endif
4252
4253 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004254 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004255" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004256 if !bufexists(bufnum)
4257 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4258 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004259 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004260
Bram Moolenaar446cb832008-06-24 21:56:24 +00004261 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004262" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004263 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004264 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004265" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4266
Bram Moolenaar71badf92023-04-22 22:40:14 +01004267 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004268 " IF the buffer already has the desired name
4269 " AND it is empty
4270 let curbuf = bufname("%")
4271 if curbuf == '.'
4272 let curbuf = getcwd()
4273 endif
4274" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004275" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004276" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4277" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4278" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4279" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4280 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004281" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4282 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004283 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004284" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004285 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004286 " 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 +00004287
4288 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004289 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004290" 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 +00004291 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004292" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004293 " name the buffer
4294 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4295 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004296" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004297 let w:netrw_treebufnr = bufnr("%")
4298 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004299 if g:netrw_use_noswf
4300 setl nobl bt=nofile noswf
4301 else
4302 setl nobl bt=nofile
4303 endif
4304 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4305 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4306 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4307 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004308" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004309 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004310 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004311 " enter the new buffer into the s:netrwbuf dictionary
4312 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4313" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4314" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004315 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004316" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004317
4318 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004319" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004320 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004321 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004322 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004323
4324 if &ft == "netrw"
4325" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4326 exe "sil! NetrwKeepj noswapfile b ".bufnum
4327" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004328 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004329" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4330 call s:NetrwEditBuf(bufnum)
4331" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004332 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004333" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004334 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004335 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004336 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004337
4338 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004339 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004340
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004341 if line("$") <= 1 && getline(1) == ""
4342 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004343 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004344" 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>"))
4345" 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 +01004346" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4347 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004348
Bram Moolenaar97d62492012-11-15 21:28:22 +01004349 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004350" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004351 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004352 sil NetrwKeepj %d _
4353" 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>"))
4354" 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 +01004355" 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 +00004356 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004357
Bram Moolenaar446cb832008-06-24 21:56:24 +00004358 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004359" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4360" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004361 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004362 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004363 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004364" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4365" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004366" 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 +00004367 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004368
Bram Moolenaar446cb832008-06-24 21:56:24 +00004369 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004370" 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>"))
4371" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4372" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004373 return 1
4374 endif
4375 endif
4376
4377 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4378 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4379 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4380 " med 1 D H
4381 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004382" 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 +00004383 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004384 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004385 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004386
4387 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004388" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4389" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4390 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004391
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004392" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4393" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4394" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004395 return 0
4396endfun
4397
4398" ---------------------------------------------------------------------
4399" s:NetrwGetcwd: get the current directory. {{{2
4400" Change backslashes to forward slashes, if any.
4401" If doesc is true, escape certain troublesome characters
4402fun! s:NetrwGetcwd(doesc)
4403" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4404 let curdir= substitute(getcwd(),'\\','/','ge')
4405 if curdir !~ '[\/]$'
4406 let curdir= curdir.'/'
4407 endif
4408 if a:doesc
4409 let curdir= fnameescape(curdir)
4410 endif
4411" call Dret("NetrwGetcwd <".curdir.">")
4412 return curdir
4413endfun
4414
4415" ---------------------------------------------------------------------
4416" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4417fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004418" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4419" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4420 let keepsol= &l:sol
4421 setl nosol
4422
Bram Moolenaar446cb832008-06-24 21:56:24 +00004423 call s:UseBufWinVars()
4424
4425 " insure that w:netrw_liststyle is set up
4426 if !exists("w:netrw_liststyle")
4427 if exists("g:netrw_liststyle")
4428 let w:netrw_liststyle= g:netrw_liststyle
4429 else
4430 let w:netrw_liststyle= s:THINLIST
4431 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004432" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004433 endif
4434
4435 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4436 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004437" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004438 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004439 let dirname= "./"
4440 let curline= getline('.')
4441
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004442 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004443 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004444 let s:netrw_skipbrowse= 1
4445 echo 'Pressing "s" also works'
4446
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004447 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004448 let s:netrw_skipbrowse= 1
4449 echo 'Press "S" to edit sorting sequence'
4450
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004451 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004452 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004453 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004454
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004455 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004456 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004457 let s:netrw_skipbrowse= 1
4458 echo 'Pressing "a" also works'
4459
4460 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004461 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004462 endif
4463
4464 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004465" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004466 NetrwKeepj norm! 0
4467 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004468
4469 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004470" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004471 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004472 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4473
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004474 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004475" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004476 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004477 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004478
4479 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004480" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004481 let dirname= getline('.')
4482
4483 if !exists("b:netrw_cpf")
4484 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004485 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 +01004486 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004487" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004488 endif
4489
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004490" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004491 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004492" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4493" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004494 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004495 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004496 else
4497 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004498 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004499 endif
4500 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004501 let eofname= filestart + b:netrw_cpf + 1
4502 if eofname <= col("$")
4503 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004504 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004505 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004506 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004507 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508 let dirname = @a
4509 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004510" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004511 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004512" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004513 endif
4514
4515 " symlinks are indicated by a trailing "@". Remove it before further processing.
4516 let dirname= substitute(dirname,"@$","","")
4517
4518 " executables are indicated by a trailing "*". Remove it before further processing.
4519 let dirname= substitute(dirname,"\*$","","")
4520
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004521 let &l:sol= keepsol
4522
Bram Moolenaar446cb832008-06-24 21:56:24 +00004523" call Dret("s:NetrwGetWord <".dirname.">")
4524 return dirname
4525endfun
4526
4527" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004528" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4529" g:netrw_bufsettings will be used after the listing is produced.
4530" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004531fun! s:NetrwListSettings(islocal)
4532" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004533" 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 +00004534 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004535" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4536 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4537 setl bt=nofile nobl ma nonu nowrap noro nornu
4538 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004539 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004540 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004541 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004542" call Dredir("ls!","s:NetrwListSettings")
4543" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004544 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004545 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004546 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004547 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004548 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004549 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004550 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004551" 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 +00004552" call Dret("s:NetrwListSettings")
4553endfun
4554
4555" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004556" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004557" islocal=0: remote browsing
4558" =1: local browsing
4559fun! s:NetrwListStyle(islocal)
4560" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004561
Bram Moolenaar97d62492012-11-15 21:28:22 +01004562 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004563 let fname = s:NetrwGetWord()
4564 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004565 let svpos = winsaveview()
4566" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004567 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004568" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4569" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4570" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004571
Bram Moolenaar85850f32019-07-19 22:05:51 +02004572 " repoint t:netrw_lexbufnr if appropriate
4573 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4574" call Decho("set repointlexbufnr to true!")
4575 let repointlexbufnr= 1
4576 endif
4577
Bram Moolenaar446cb832008-06-24 21:56:24 +00004578 if w:netrw_liststyle == s:THINLIST
4579 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004580" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004581 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4582
4583 elseif w:netrw_liststyle == s:LONGLIST
4584 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004585" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004586 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4587
4588 elseif w:netrw_liststyle == s:WIDELIST
4589 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004590" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004591 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4592
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004593 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004594" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004595 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4596
4597 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004598 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004599 let g:netrw_liststyle = s:THINLIST
4600 let w:netrw_liststyle = g:netrw_liststyle
4601 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4602 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004603 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004604" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004605
4606 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004607" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4608 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004609 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004610" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004611 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004612" 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 +00004613
4614 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004615" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004616 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004617 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004618
Bram Moolenaar85850f32019-07-19 22:05:51 +02004619 " repoint t:netrw_lexbufnr if appropriate
4620 if exists("repointlexbufnr")
4621 let t:netrw_lexbufnr= bufnr("%")
4622" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4623 endif
4624
Bram Moolenaar13600302014-05-22 18:26:40 +02004625 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004626" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4627 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004628 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004629
4630" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4631endfun
4632
4633" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004634" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4635fun! s:NetrwBannerCtrl(islocal)
4636" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4637
Bram Moolenaar97d62492012-11-15 21:28:22 +01004638 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004639 " toggle the banner (enable/suppress)
4640 let g:netrw_banner= !g:netrw_banner
4641
4642 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004643 let svpos= winsaveview()
4644" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004645 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4646
4647 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004648 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4649 let fname= s:NetrwGetWord()
4650 sil NetrwKeepj $
4651 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4652" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4653 if result <= 0 && exists("w:netrw_bannercnt")
4654 exe "NetrwKeepj ".w:netrw_bannercnt
4655 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004656 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004657 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004658" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4659endfun
4660
4661" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004662" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4663"
4664" No bang: enters files/directories into Netrw's bookmark system
4665" No argument and in netrw buffer:
4666" if there are marked files: bookmark marked files
4667" otherwise : bookmark file/directory under cursor
4668" No argument and not in netrw buffer: bookmarks current open file
4669" Has arguments: globs them individually and bookmarks them
4670"
4671" With bang: deletes files/directories from Netrw's bookmark system
4672fun! s:NetrwBookmark(del,...)
4673" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4674 if a:0 == 0
4675 if &ft == "netrw"
4676 let curbufnr = bufnr("%")
4677
4678 if exists("s:netrwmarkfilelist_{curbufnr}")
4679 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004680" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004681 let svpos = winsaveview()
4682" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004683 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004684 for fname in s:netrwmarkfilelist_{curbufnr}
4685 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4686 endfor
4687 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4688 call s:NetrwUnmarkList(curbufnr,curdir)
4689 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004690" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4691 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004692 else
4693 let fname= s:NetrwGetWord()
4694 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4695 endif
4696
4697 else
4698 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004699" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004700 let fname= expand("%")
4701 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4702 endif
4703
4704 else
4705 " bookmark specified files
4706 " attempts to infer if working remote or local
4707 " by deciding if the current file begins with an url
4708 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004709 let islocal= expand("%") !~ '^\a\{3,}://'
4710" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004711 let i = 1
4712 while i <= a:0
4713 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004714 if v:version > 704 || (v:version == 704 && has("patch656"))
4715 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004716 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004717 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004718 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004719 else
4720 let mbfiles= [a:{i}]
4721 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004722" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004723 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004724" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004725 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4726 endfor
4727 let i= i + 1
4728 endwhile
4729 endif
4730
4731 " update the menu
4732 call s:NetrwBookmarkMenu()
4733
4734" call Dret("s:NetrwBookmark")
4735endfun
4736
4737" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004738" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4739" .2.[cnt] for bookmarks, and
4740" .3.[cnt] for history
4741" (see s:NetrwMenu())
4742fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004743 if !exists("s:netrw_menucnt")
4744 return
4745 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004746" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004747
4748 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004749 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004750 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004751" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004752 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4753 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004754 endif
4755 if !exists("s:netrw_initbookhist")
4756 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004757 endif
4758
4759 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004760 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004761 let cnt= 1
4762 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004763" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004764 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004765
4766 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004767 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004768
4769 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004770 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 +01004771 let cnt= cnt + 1
4772 endfor
4773
4774 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004775
4776 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004777 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004778 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004779 let first = 1
4780 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004781 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004782 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004783 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004784 if exists("g:netrw_dirhist_{cnt}")
4785 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004786" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004787 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4788 endif
4789 let first = 0
4790 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4791 if cnt < 0
4792 let cnt= cnt + g:netrw_dirhistmax
4793 endif
4794 endwhile
4795 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004796
Bram Moolenaar9964e462007-05-05 17:54:07 +00004797 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004798" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004799endfun
4800
4801" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004802" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4803" directory and a new directory name. Also, if the
4804" "new directory name" is actually a file,
4805" NetrwBrowseChgDir() edits the file.
4806fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004807" 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 +01004808" 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 +00004809
Bram Moolenaar97d62492012-11-15 21:28:22 +01004810 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004811 if !exists("b:netrw_curdir")
4812 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4813 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004814 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004815" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4816" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004817" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004818" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004819 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004820 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004821" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004822
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004823 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004824" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004825 call s:SavePosn(s:netrw_posn)
4826 NetrwKeepj call s:NetrwOptionsSave("s:")
4827 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004828 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004829 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004830 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004831 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004832 endif
4833 let newdir = a:newdir
4834 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004835 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004836" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004837" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004838" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004839
4840 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004841" 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 +01004842 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004843" 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 +01004844 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004845 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004846" 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 +01004847 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004848" 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 +02004849 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004850 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004851 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004852 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004853" 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 +01004854 endif
4855 endif
4856" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004857" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004858 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004859
Bram Moolenaar446cb832008-06-24 21:56:24 +00004860 " set up o/s-dependent directory recognition pattern
4861 if has("amiga")
4862 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004863 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004864 let dirpat= '[\/]$'
4865 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004866" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004867
4868 if dirname !~ dirpat
4869 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004870 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004871 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004872" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004873 endif
4874
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004875" 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 +01004876 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004877 " ------------------------------
4878 " NetrwBrowseChgDir: edit a file {{{3
4879 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004880" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004881
Bram Moolenaar97d62492012-11-15 21:28:22 +01004882 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004883 let s:rexposn_{bufnr("%")}= winsaveview()
4884" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004885" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4886" 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 +01004887
Bram Moolenaar446cb832008-06-24 21:56:24 +00004888 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004889" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4890" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004891" let newdir = s:NetrwTreePath(s:netrw_treetop)
4892" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004893 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004894 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4895" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4896 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004897 if dirname =~ '/$'
4898 let dirname= dirname.newdir
4899 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004900 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004902" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4903" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004904 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004905" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004907 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004908 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004909 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004910" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004911 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004912 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004913" 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 +02004914 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004915 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004916 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004917" " 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 +01004918 if type(g:netrw_browse_split) == 3
4919 " open file in server
4920 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004921" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004922 call s:NetrwServerEdit(a:islocal,dirname)
4923" call Dret("s:NetrwBrowseChgDir")
4924 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004925
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004926 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004927 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004928" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004929 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4930 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004931 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004932 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004933 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004934 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004935
Bram Moolenaar446cb832008-06-24 21:56:24 +00004936 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004937 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004938" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004939 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4940 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004941 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004942 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004943 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004944 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004945
Bram Moolenaar446cb832008-06-24 21:56:24 +00004946 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004947 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004948" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004949 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004950 if !exists("b:netrw_curdir")
4951 let b:netrw_curdir= getcwd()
4952 endif
4953 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004954
Bram Moolenaar446cb832008-06-24 21:56:24 +00004955 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004956 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004957" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004958 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004959 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004960" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004961 return
4962 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004963 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004964
Bram Moolenaar9964e462007-05-05 17:54:07 +00004965 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004966 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004967" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004968 call s:NetrwMenu(0)
4969 " optional change to window
4970 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004971" 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 +02004972 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004973 " if g:netrw_chgwin is set to one more than the last window, then
4974 " vertically split the last window to make that window available.
4975 let curwin= winnr()
4976 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4977 vs
4978 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004979 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004980 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004981 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004982 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004983 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004984
Bram Moolenaar9964e462007-05-05 17:54:07 +00004985 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004986
Bram Moolenaar446cb832008-06-24 21:56:24 +00004987 " the point where netrw actually edits the (local) file
4988 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004989 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004990 if !&mod
4991 " if e the new file would fail due to &mod, then don't change any of the flags
4992 let dolockout= 1
4993 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004994 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004995" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004996 " some like c-^ to return to the last edited file
4997 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004998 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4999 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005000 call s:NetrwEditFile("e","",dirname)
5001" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005002 " COMBAK -- cuc cul related
5003 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005004 if &hidden || &bufhidden == "hide"
5005 " file came from vim's hidden storage. Don't "restore" options with it.
5006 let dorestore= 0
5007 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005008 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005009" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005010 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005011
5012 " handle g:Netrw_funcref -- call external-to-netrw functions
5013 " This code will handle g:Netrw_funcref as an individual function reference
5014 " or as a list of function references. It will ignore anything that's not
5015 " a function reference. See :help Funcref for information about function references.
5016 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005017" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005018 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005019" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005020 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005021 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005022" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005023 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005024 if type(Fncref) == 2
5025 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005026 endif
5027 endfor
5028 endif
5029 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005030 endif
5031
5032 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005033 " ----------------------------------------------------
5034 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5035 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005036" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005037 let dirname = newdir
5038 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005039 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005040 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005041
5042 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005043 " ---------------------------------------------
5044 " NetrwBrowseChgDir: refresh the directory list {{{3
5045 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005046" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005047 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005048 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005049
5050 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005051 " --------------------------------------
5052 " NetrwBrowseChgDir: go up one directory {{{3
5053 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005054" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005055
5056 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5057 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005058" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5059" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005060 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005061 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005062 endif
5063
5064 if has("amiga")
5065 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005066" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005067 if a:islocal
5068 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5069 let dirname= substitute(dirname,'/$','','')
5070 else
5071 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5072 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005073" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005074
Nir Lichtman1e34b952024-05-08 19:19:34 +02005075 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005076 " windows
5077 if a:islocal
5078 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5079 if dirname == ""
5080 let dirname= '/'
5081 endif
5082 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005083 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005084 endif
5085 if dirname =~ '^\a:$'
5086 let dirname= dirname.'/'
5087 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005088" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005089
Bram Moolenaar446cb832008-06-24 21:56:24 +00005090 else
5091 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005092" 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 +00005093 if a:islocal
5094 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5095 if dirname == ""
5096 let dirname= '/'
5097 endif
5098 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005099 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005100 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005101" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005102 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005103 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005104 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005105
5106 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005107 " --------------------------------------
5108 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5109 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005110" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005111 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5112" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005113 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005114 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005115" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5116 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005117 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005118 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005119" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005120 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005121 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005122" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005123
5124 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005125" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005126 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005127" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005128 let haskey= 1
5129 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005130" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005131 endif
5132
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005133 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005134" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005135 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005136 if has_key(w:netrw_treedict,treedir."/")
5137 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005138" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005139 let haskey = 1
5140 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005141" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005142 endif
5143 endif
5144
5145 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005146" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005147 if !haskey && treedir =~ '/$'
5148 let treedir= substitute(treedir,'/$','','')
5149 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005150" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005151 let haskey = 1
5152 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005153" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005154 endif
5155 endif
5156
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005157" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005158 if haskey
5159 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005160" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005161 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005162" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5163" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005164 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005165 else
5166 " go down one directory
5167 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005168" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5169" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005170 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005171 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005172" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005173 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005174
5175 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005176 " ----------------------------------------
5177 " NetrwBrowseChgDir: Go down one directory {{{3
5178 " ----------------------------------------
5179 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005180" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005181 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005182 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005183 endif
5184
Bram Moolenaar97d62492012-11-15 21:28:22 +01005185 " --------------------------------------
5186 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5187 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005188 if dorestore
5189 " dorestore is zero'd when a local file was hidden or bufhidden;
5190 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005191" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005192 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005193" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005194" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005195 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005196 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005197" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005198 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005199" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5200" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005201 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005202" 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 +02005203 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005204" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5205" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005206 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005207" 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 +02005208 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005209 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005210 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005211 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005212
Bram Moolenaar446cb832008-06-24 21:56:24 +00005213" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5214 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005215endfun
5216
5217" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005218" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5219" for thin, long, and wide: cursor placed just after banner
5220" for tree, keeps cursor on current filename
5221fun! s:NetrwBrowseUpDir(islocal)
5222" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005223 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5224 " this test needed because occasionally this function seems to be incorrectly called
5225 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005226 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005227 " directories.
5228" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5229 return
5230 endif
5231
Bram Moolenaara6878372014-03-22 21:02:50 +01005232 norm! 0
5233 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005234" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005235 let curline= getline(".")
5236 let swwline= winline() - 1
5237 if exists("w:netrw_treetop")
5238 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005239 elseif exists("b:netrw_curdir")
5240 let w:netrw_treetop= b:netrw_curdir
5241 else
5242 let w:netrw_treetop= getcwd()
5243 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005244 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005245 let curfile = getline(".")
5246 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005247 if a:islocal
5248 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5249 else
5250 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5251 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005252" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5253" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5254 if w:netrw_treetop == '/'
5255 keepj call search('^\M'.curfile,"w")
5256 elseif curfile == '../'
5257 keepj call search('^\M'.curfile,"wb")
5258 else
5259" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5260 while 1
5261 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5262 let treepath= s:NetrwTreePath(w:netrw_treetop)
5263" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5264 if treepath == curpath
5265 break
5266 endif
5267 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005268 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005269
Bram Moolenaara6878372014-03-22 21:02:50 +01005270 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005271" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005272 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005273 if exists("b:netrw_curdir")
5274 let curdir= b:netrw_curdir
5275 else
5276 let curdir= expand(getcwd())
5277 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005278 if a:islocal
5279 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5280 else
5281 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5282 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005283 call s:RestorePosn(s:netrw_posn)
5284 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005285 let curdir= '\<'. escape(curdir, '~'). '/'
5286 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005287 endif
5288" call Dret("s:NetrwBrowseUpDir")
5289endfun
5290
5291" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005292" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005293" given filename; typically this means given their extension.
5294" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005295fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005296 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005297" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005298
Bram Moolenaar91359012019-11-30 17:57:03 +01005299 if a:remote == 0 && isdirectory(a:fname)
5300 " if its really just a local directory, then do a "gf" instead
5301" 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 +01005302" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5303 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005304" call Dret("netrw#BrowseX")
5305 return
5306 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5307 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5308" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5309" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5310" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5311" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5312 norm! gf
5313" call Dret("netrw#BrowseX")
5314 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005315 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005316" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005317
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005318 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5319 let remote = a:remote
5320 else
5321 let remote = 0
5322 endif
5323
Bram Moolenaar97d62492012-11-15 21:28:22 +01005324 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005325 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005326" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005327
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005328 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5329 let awkeep = &aw
5330 set noaw
5331
Bram Moolenaar5c736222010-01-06 20:54:52 +01005332 " special core dump handler
5333 if a:fname =~ '/core\(\.\d\+\)\=$'
5334 if exists("g:Netrw_corehandler")
5335 if type(g:Netrw_corehandler) == 2
5336 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005337" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005338 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005339 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005340 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005341" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005342 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005343 if type(Fncref) == 2
5344 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005345 endif
5346 endfor
5347 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005348" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005349 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005350 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005351 let &aw= awkeep
5352" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005353 return
5354 endif
5355 endif
5356
Bram Moolenaar446cb832008-06-24 21:56:24 +00005357 " set up the filename
5358 " (lower case the extension, make a local copy of a remote file)
5359 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005360 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005361 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005362 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005363 if exten =~ "[\\/]"
5364 let exten= ""
5365 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005366" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005367
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005368 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005369 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005370" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005371 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005372 call netrw#NetRead(3,a:fname)
5373 " attempt to rename tempfile
5374 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005375 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005376" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5377" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005378 if s:netrw_tmpfile != newname && newname != ""
5379 if rename(s:netrw_tmpfile,newname) == 0
5380 " renaming succeeded
5381" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5382 let fname= newname
5383 else
5384 " renaming failed
5385" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5386 let fname= s:netrw_tmpfile
5387 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005388 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005389 let fname= s:netrw_tmpfile
5390 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005391 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005392" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005393 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005394 " special ~ handler for local
5395 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005396" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5397 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005398 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005399 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005400" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5401" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005402
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005403 " set up redirection (avoids browser messages)
5404 " by default, g:netrw_suppress_gx_mesg is true
5405 if g:netrw_suppress_gx_mesg
5406 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005407 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005408 let redir= substitute(&srr,"%s","nul","")
5409 else
5410 let redir= substitute(&srr,"%s","/dev/null","")
5411 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005412 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005413 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005414 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005415 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005416 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005417 else
5418 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005419 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005420" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005421
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005422 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005423 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005424" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005425 if g:netrw_browsex_viewer =~ '\s'
5426 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5427 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5428 let oviewer = ''
5429 let cnt = 1
5430 while !executable(viewer) && viewer != oviewer
5431 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5432 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5433 let cnt = cnt + 1
5434 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005435" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005436 endwhile
5437 else
5438 let viewer = g:netrw_browsex_viewer
5439 let viewopt = ""
5440 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005441" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005442 endif
5443
5444 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005445" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005446 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005447" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005448 let ret= netrwFileHandlers#Invoke(exten,fname)
5449
5450 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005451" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005452 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005453 let ret= v:shell_error
5454
Nir Lichtman1e34b952024-05-08 19:19:34 +02005455 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005456" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005457 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005458 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005459 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005460 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005461 else
5462 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5463 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005464 let ret= v:shell_error
5465
Bram Moolenaar97d62492012-11-15 21:28:22 +01005466 elseif has("win32unix")
5467 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005468" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005469 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005470" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005471 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005472 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005473" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005474 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005475 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005476" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005477 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005478 else
5479 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5480 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005481 let ret= v:shell_error
5482
Bram Moolenaar85850f32019-07-19 22:05:51 +02005483 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005484" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5485 if a:fname =~ '^https\=://'
5486 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5487 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005488" call Decho("fname<".fname.">")
5489" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005490 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5491
5492 else
5493 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5494 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005495 let ret= v:shell_error
5496
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005497 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5498" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5499 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5500 let ret= v:shell_error
5501
5502 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5503" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5504 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5505 let ret= v:shell_error
5506
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005507 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005508" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005509 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005510 let ret= v:shell_error
5511
5512 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005513" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005514 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005515 let ret= v:shell_error
5516
5517 else
5518 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005519" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005520 let ret= netrwFileHandlers#Invoke(exten,fname)
5521 endif
5522
5523 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5524 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005525" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005526 let ret= netrwFileHandlers#Invoke(exten,fname)
5527 endif
5528
Bram Moolenaarc236c162008-07-13 17:41:49 +00005529 " restoring redraw! after external file handlers
5530 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005531
5532 " cleanup: remove temporary file,
5533 " delete current buffer if success with handler,
5534 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005535 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005536 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005537" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005538"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005539" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005540" endif
5541
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005542 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005543 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005544 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005545 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005546 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005547 if use_ctrlo
5548 exe "sil! NetrwKeepj norm! \<c-o>"
5549 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005550 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005551" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005552 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005553 let @@ = ykeep
5554 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005555
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005556" call Dret("netrw#BrowseX")
5557endfun
5558
5559" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005560" netrw#GX: gets word under cursor for gx support {{{2
5561" See also: netrw#BrowseXVis
5562" netrw#BrowseX
5563fun! netrw#GX()
5564" call Dfunc("netrw#GX()")
5565 if &ft == "netrw"
5566 let fname= s:NetrwGetWord()
5567 else
5568 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5569 endif
5570" call Dret("netrw#GX <".fname.">")
5571 return fname
5572endfun
5573
5574" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005575" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5576fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005577 let dict={}
5578 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005579 norm! gv"ay
5580 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005581 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005582 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005583endfun
5584
5585" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005586" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5587" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5588" to become an unlisted buffer, so in that case don't bwipe it.
5589fun! s:NetrwBufRename(newname)
5590" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5591" call Dredir("ls!","s:NetrwBufRename (before rename)")
5592 let oldbufname= bufname(bufnr("%"))
5593" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5594
5595 if oldbufname != a:newname
5596" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5597 let b:junk= 1
5598" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5599 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005600" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005601 let oldbufnr= bufnr(oldbufname)
5602" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5603" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5604 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5605" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5606 exe "bwipe! ".oldbufnr
5607" else " Decho
5608" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005609" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5610" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5611" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005612 endif
5613" call Dredir("ls!","s:NetrwBufRename (after rename)")
5614" else " Decho
5615" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5616 endif
5617
5618" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5619endfun
5620
5621" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005622" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005623fun! netrw#CheckIfRemote(...)
5624" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5625 if a:0 > 0
5626 let curfile= a:1
5627 else
5628 let curfile= expand("%")
5629 endif
5630" call Decho("curfile<".curfile.">")
5631 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005632" call Dret("netrw#CheckIfRemote 1")
5633 return 1
5634 else
5635" call Dret("netrw#CheckIfRemote 0")
5636 return 0
5637 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005638endfun
5639
5640" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005641" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5642fun! s:NetrwChgPerm(islocal,curdir)
5643" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005644 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005645 call inputsave()
5646 let newperm= input("Enter new permission: ")
5647 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005648 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5649 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5650" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005651 call system(chgperm)
5652 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005653 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005654 endif
5655 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005656 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005657 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005658 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005659" call Dret("s:NetrwChgPerm")
5660endfun
5661
5662" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005663" s:CheckIfKde: checks if kdeinit is running {{{2
5664" Returns 0: kdeinit not running
5665" 1: kdeinit is running
5666fun! s:CheckIfKde()
5667" call Dfunc("s:CheckIfKde()")
5668 " seems kde systems often have gnome-open due to dependencies, even though
5669 " gnome-open's subsidiary display tools are largely absent. Kde systems
5670 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5671 if !exists("s:haskdeinit")
5672 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005673 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005674 if v:shell_error
5675 let s:haskdeinit = 0
5676 endif
5677 else
5678 let s:haskdeinit= 0
5679 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005680" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005681 endif
5682
5683" call Dret("s:CheckIfKde ".s:haskdeinit)
5684 return s:haskdeinit
5685endfun
5686
5687" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005688" s:NetrwClearExplore: clear explore variables (if any) {{{2
5689fun! s:NetrwClearExplore()
5690" call Dfunc("s:NetrwClearExplore()")
5691 2match none
5692 if exists("s:explore_match") |unlet s:explore_match |endif
5693 if exists("s:explore_indx") |unlet s:explore_indx |endif
5694 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5695 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5696 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5697 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5698 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5699 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5700 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5701" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005702" call Dret("s:NetrwClearExplore")
5703endfun
5704
5705" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005706" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5707fun! s:NetrwEditBuf(bufnum)
5708" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5709 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5710" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5711 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5712 else
5713" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005714 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005715 endif
5716" call Dret("s:NetrwEditBuf")
5717endfun
5718
5719" ---------------------------------------------------------------------
5720" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5721" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5722fun! s:NetrwEditFile(cmd,opt,fname)
5723" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5724 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5725" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5726 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5727 else
5728" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005729 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5730 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5731 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005732 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5733 endif
5734" call Dret("s:NetrwEditFile")
5735endfun
5736
5737" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005738" s:NetrwExploreListUniq: {{{2
5739fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005740" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005741
5742 " this assumes that the list is already sorted
5743 let newexplist= []
5744 for member in a:explist
5745 if !exists("uniqmember") || member != uniqmember
5746 let uniqmember = member
5747 let newexplist = newexplist + [ member ]
5748 endif
5749 endfor
5750
Bram Moolenaar15146672011-10-20 22:22:38 +02005751" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005752 return newexplist
5753endfun
5754
5755" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005756" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5757fun! s:NetrwForceChgDir(islocal,newdir)
5758" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005759 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005760 if a:newdir !~ '/$'
5761 " ok, looks like force is needed to get directory-style treatment
5762 if a:newdir =~ '@$'
5763 let newdir= substitute(a:newdir,'@$','/','')
5764 elseif a:newdir =~ '[*=|\\]$'
5765 let newdir= substitute(a:newdir,'.$','/','')
5766 else
5767 let newdir= a:newdir.'/'
5768 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005769" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005770 else
5771 " should already be getting treatment as a directory
5772 let newdir= a:newdir
5773 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005774 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005775 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005776 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005777" call Dret("s:NetrwForceChgDir")
5778endfun
5779
5780" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005781" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005782" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5783" expr : this is the expression to follow the directory. Will use s:ComposePath()
5784" pare =1: remove the current directory from the resulting glob() filelist
5785" =0: leave the current directory in the resulting glob() filelist
5786fun! s:NetrwGlob(direntry,expr,pare)
5787" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005788 if netrw#CheckIfRemote()
5789 keepalt 1sp
5790 keepalt enew
5791 let keep_liststyle = w:netrw_liststyle
5792 let w:netrw_liststyle = s:THINLIST
5793 if s:NetrwRemoteListing() == 0
5794 keepj keepalt %s@/@@
5795 let filelist= getline(1,$)
5796 q!
5797 else
5798 " remote listing error -- leave treedict unchanged
5799 let filelist= w:netrw_treedict[a:direntry]
5800 endif
5801 let w:netrw_liststyle= keep_liststyle
5802 else
Christian Brabandt14879472024-06-13 21:25:35 +02005803 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005804 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005805 " escape [ so it is not detected as wildcard character, see :h wildcard
5806 let path= substitute(path, '[', '[[]', 'g')
5807 endif
5808 if v:version > 704 || (v:version == 704 && has("patch656"))
5809 let filelist= glob(path,0,1,1)
5810 else
5811 let filelist= glob(path,0,1)
5812 endif
5813 if a:pare
5814 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5815 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005816 endif
5817" call Dret("s:NetrwGlob ".string(filelist))
5818 return filelist
5819endfun
5820
5821" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005822" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5823fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005824" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005825 if a:newfile =~ '[/@*=|\\]$'
5826 let newfile= substitute(a:newfile,'.$','','')
5827 else
5828 let newfile= a:newfile
5829 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005830 if a:islocal
5831 call s:NetrwBrowseChgDir(a:islocal,newfile)
5832 else
5833 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5834 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005835" call Dret("s:NetrwForceFile")
5836endfun
5837
5838" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005839" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5840" and switches the hiding mode. The actual hiding is done by
5841" s:NetrwListHide().
5842" g:netrw_hide= 0: show all
5843" 1: show not-hidden files
5844" 2: show hidden files only
5845fun! s:NetrwHide(islocal)
5846" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005847 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005848 let svpos= winsaveview()
5849" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005850
5851 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005852" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5853" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005854
5855 " hide the files in the markfile list
5856 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005857" 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 +00005858 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5859 " remove fname from hiding list
5860 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5861 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5862 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005863" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005864 else
5865 " append fname to hiding list
5866 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5867 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5868 else
5869 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5870 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005871" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005872 endif
5873 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005874 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005875 let g:netrw_hide= 1
5876
5877 else
5878
5879 " switch between show-all/show-not-hidden/show-hidden
5880 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005881 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005882 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005883 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005884 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005885" call Dret("NetrwHide")
5886 return
5887 endif
5888 endif
5889
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005890 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005891" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5892 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005893 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005894" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005895endfun
5896
5897" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005898" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5899fun! s:NetrwHideEdit(islocal)
5900" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5901
5902 let ykeep= @@
5903 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005904 let svpos= winsaveview()
5905" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005906
5907 " get new hiding list from user
5908 call inputsave()
5909 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5910 call inputrestore()
5911 let g:netrw_list_hide= newhide
5912" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5913
5914 " refresh the listing
5915 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5916
5917 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005918" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5919 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005920 let @@= ykeep
5921
5922" call Dret("NetrwHideEdit")
5923endfun
5924
5925" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005926" s:NetrwHidden: invoked by "gh" {{{2
5927fun! s:NetrwHidden(islocal)
5928" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005929 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005930 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005931 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005932" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005933
5934 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005935 " remove .file pattern from hiding list
5936" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005937 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005938 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005939" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005940 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5941 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005942" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005943 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5944 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005945 if g:netrw_list_hide =~ '^,'
5946 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5947 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005948
5949 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005950 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005951" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5952 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005953 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005954" call Dret("s:NetrwHidden")
5955endfun
5956
5957" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005958" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5959fun! s:NetrwHome()
5960 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005961 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005962 else
5963 " go to vim plugin home
5964 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005965 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005966 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005967 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005968 let home= basehome."/.vim"
5969 break
5970 endif
5971 endfor
5972 if home == ""
5973 " just pick the first directory
5974 let home= substitute(&rtp,',.*$','','')
5975 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005976 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005977 let home= substitute(home,'/','\\','g')
5978 endif
5979 endif
5980 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005981 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005982" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005983 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005984" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005985 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005986 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005987" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005988 call mkdir(home)
5989 endif
5990 endif
5991 let g:netrw_home= home
5992 return home
5993endfun
5994
5995" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005996" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5997fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005998 if exists("s:netrwdrag")
5999 return
6000 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006001 if &ft != "netrw"
6002 return
6003 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006004" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006005
Bram Moolenaar97d62492012-11-15 21:28:22 +01006006 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006007 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006008 while getchar(0) != 0
6009 "clear the input stream
6010 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006011 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006012 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006013 let mouse_lnum = v:mouse_lnum
6014 let wlastline = line('w$')
6015 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006016" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6017" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006018 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6019 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006020 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006021" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6022 return
6023 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006024 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006025 " 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 +01006026 " without this test when its disabled.
6027 " 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 +01006028" 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 +01006029 if v:mouse_col > virtcol('.')
6030 let @@= ykeep
6031" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6032 return
6033 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006034
Bram Moolenaar446cb832008-06-24 21:56:24 +00006035 if a:islocal
6036 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006037 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006038 endif
6039 else
6040 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006041 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006042 endif
6043 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006044 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006045" call Dret("s:NetrwLeftmouse")
6046endfun
6047
6048" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006049" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6050fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006051 if &ft != "netrw"
6052 return
6053 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006054" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6055 call s:NetrwMarkFileTgt(a:islocal)
6056" call Dret("s:NetrwCLeftmouse")
6057endfun
6058
6059" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006060" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6061" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006062" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006063" a:islocal=2 : <c-r> used, remote
6064" a:islocal=3 : <c-r> used, local
6065fun! s:NetrwServerEdit(islocal,fname)
6066" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6067 let islocal = a:islocal%2 " =0: remote =1: local
6068 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006069" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006070
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006071 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006072 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006073 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006074" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006075 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006076 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006077 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6078 unlet s:netrw_browse_split_{winnr()}
6079 endif
6080 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6081" call Dret("s:NetrwServerEdit")
6082 return
6083 endif
6084
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006085" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006086 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006087" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006088
6089 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006090" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006091 let srvrname = g:netrw_browse_split[0]
6092 let tabnum = g:netrw_browse_split[1]
6093 let winnum = g:netrw_browse_split[2]
6094
6095 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006096" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006097
6098 if !ctrlr
6099 " user must have closed the server window and the user did not use <c-r>, but
6100 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006101" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006102 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006103 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006104 endif
6105 let g:netrw_browse_split= 0
6106 if exists("s:netrw_browse_split_".winnr())
6107 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6108 endif
6109 call s:NetrwBrowseChgDir(islocal,a:fname)
6110" call Dret("s:NetrwServerEdit")
6111 return
6112
6113 elseif has("win32") && executable("start")
6114 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006115" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006116 call system("start gvim --servername ".srvrname)
6117
6118 else
6119 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006120" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006121 call system("gvim --servername ".srvrname)
6122 endif
6123 endif
6124
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006125" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006126 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6127 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006128 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006129
6130 else
6131
6132 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6133
6134 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006135" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006136 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006137 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006138 endif
6139 let g:netrw_browse_split= 0
6140 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6141" call Dret("s:NetrwServerEdit")
6142 return
6143
6144 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006145" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006146 if has("win32") && executable("start")
6147 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006148" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006149 call system("start gvim --servername ".g:netrw_servername)
6150 else
6151 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006152" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006153 call system("gvim --servername ".g:netrw_servername)
6154 endif
6155 endif
6156 endif
6157
6158 while 1
6159 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006160" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6161 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006162 break
6163 catch /^Vim\%((\a\+)\)\=:E241/
6164 sleep 200m
6165 endtry
6166 endwhile
6167
6168 if exists("g:netrw_browse_split")
6169 if type(g:netrw_browse_split) != 3
6170 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6171 endif
6172 unlet g:netrw_browse_split
6173 endif
6174 let g:netrw_browse_split= [g:netrw_servername,1,1]
6175 endif
6176
6177 else
6178 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6179 endif
6180
6181" call Dret("s:NetrwServerEdit")
6182endfun
6183
6184" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006185" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6186fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006187 if &ft != "netrw"
6188 return
6189 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006190" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006191
Bram Moolenaar8d043172014-01-23 14:24:41 +01006192 let s:ngw= s:NetrwGetWord()
6193 call s:NetrwMarkFile(a:islocal,s:ngw)
6194
6195" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006196endfun
6197
6198" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006199" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6200" Used to mark multiple files.
6201fun! s:NetrwSLeftdrag(islocal)
6202" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6203 if !exists("s:netrwdrag")
6204 let s:netrwdrag = winnr()
6205 if a:islocal
6206 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006207 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006208 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006209 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006210 endif
6211 let ngw = s:NetrwGetWord()
6212 if !exists("s:ngw") || s:ngw != ngw
6213 call s:NetrwMarkFile(a:islocal,ngw)
6214 endif
6215 let s:ngw= ngw
6216" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6217endfun
6218
6219" ---------------------------------------------------------------------
6220" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6221fun! s:NetrwSLeftrelease(islocal)
6222" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6223 if exists("s:netrwdrag")
6224 nunmap <s-leftrelease>
6225 let ngw = s:NetrwGetWord()
6226 if !exists("s:ngw") || s:ngw != ngw
6227 call s:NetrwMarkFile(a:islocal,ngw)
6228 endif
6229 if exists("s:ngw")
6230 unlet s:ngw
6231 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006232 unlet s:netrwdrag
6233 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006234" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006235endfun
6236
6237" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006238" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6239" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006240fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006241" 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 +02006242" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006243 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006244
6245 " 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 +02006246 " How-it-works: take the hiding command, convert it into a range.
6247 " Duplicate characters don't matter.
6248 " Remove all such characters from the '/~@#...890' string.
6249 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006250" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006251 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006252 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006253" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006254
6255 while listhide != ""
6256 if listhide =~ ','
6257 let hide = substitute(listhide,',.*$','','e')
6258 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6259 else
6260 let hide = listhide
6261 let listhide = ""
6262 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006263" 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 +01006264 if g:netrw_sort_by =~ '^[ts]'
6265 if hide =~ '^\^'
6266" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6267 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6268 elseif hide =~ '^\\(\^'
6269 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6270 endif
6271" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6272 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006273
6274 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006275" 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 +00006276 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006277" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006278 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006279 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006280" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006281 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006282 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006283" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006284 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006285
Bram Moolenaar446cb832008-06-24 21:56:24 +00006286 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006287 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006288" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006289 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006290" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006291 endif
6292
Bram Moolenaaradc21822011-04-01 18:03:16 +02006293 " remove any blank lines that have somehow remained.
6294 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006295 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006296
Bram Moolenaar97d62492012-11-15 21:28:22 +01006297 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006298" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006299endfun
6300
6301" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006302" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006303" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006304fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006305" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306
Bram Moolenaar97d62492012-11-15 21:28:22 +01006307 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006308 " get name of new directory from user. A bare <CR> will skip.
6309 " if its currently a directory, also request will be skipped, but with
6310 " a message.
6311 call inputsave()
6312 let newdirname= input("Please give directory name: ")
6313 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006314" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006315
6316 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006317 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006318" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006319 return
6320 endif
6321
6322 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006323" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006324
6325 " Local mkdir:
6326 " sanity checks
6327 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006328" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6329 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006330 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006331 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006332 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006333 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006334" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006335 return
6336 endif
6337 if s:FileReadable(fullnewdir)
6338 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006339 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006340 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006341 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006342" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006343 return
6344 endif
6345
6346 " requested new local directory is neither a pre-existing file or
6347 " directory, so make it!
6348 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006349 if has("unix")
6350 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6351 else
6352 call mkdir(fullnewdir,"p")
6353 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006354 else
6355 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006356 if s:NetrwLcd(b:netrw_curdir)
6357" call Dret("s:NetrwMakeDir : lcd failure")
6358 return
6359 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006360" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006361 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006362 if v:shell_error != 0
6363 let @@= ykeep
6364 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 +01006365" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006366 return
6367 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006368 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006369" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006370 if s:NetrwLcd(netrw_origdir)
6371" call Dret("s:NetrwBrowse : lcd failure")
6372 return
6373 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006374 endif
6375 endif
6376
6377 if v:shell_error == 0
6378 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006379" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006380 let svpos= winsaveview()
6381" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006382 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006383" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6384 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006385 elseif !exists("g:netrw_quiet")
6386 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6387 endif
6388" redraw!
6389
6390 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006391 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006392" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006393 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6394 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006395 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006396 if v:shell_error == 0
6397 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006398 let svpos= winsaveview()
6399" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006400 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006401" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6402 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006403 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006404 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006405 endif
6406" redraw!
6407
6408 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006409 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006410 let svpos= winsaveview()
6411" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006412" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006413 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006414" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006415 let remotepath= b:netrw_fname
6416 else
6417 let remotepath= ""
6418 endif
6419 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006420 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006421" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6422 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006423
Bram Moolenaar446cb832008-06-24 21:56:24 +00006424 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006425 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006426 let svpos= winsaveview()
6427" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006428" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006429 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006430" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006431 let remotepath= b:netrw_fname
6432 else
6433 let remotepath= ""
6434 endif
6435 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006436 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006437" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6438 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006439 endif
6440
Bram Moolenaar97d62492012-11-15 21:28:22 +01006441 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006442" call Dret("s:NetrwMakeDir")
6443endfun
6444
6445" ---------------------------------------------------------------------
6446" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6447fun! s:TreeSqueezeDir(islocal)
6448" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6449 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6450 " its a tree-listing style
6451 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006452 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006453 let depth = strchars(substitute(curdepth,' ','','g'))
6454 let srch = -1
6455" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6456" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006457" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006458" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6459 if depth >= 2
6460 NetrwKeepj norm! 0
6461 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6462 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6463" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6464" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6465 elseif depth == 1
6466 NetrwKeepj norm! 0
6467 let treedepthchr= substitute(s:treedepthstring,' ','','')
6468 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6469" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6470 endif
6471 if srch > 0
6472" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6473 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6474 exe srch
6475 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006476 endif
6477" call Dret("s:TreeSqueezeDir")
6478endfun
6479
6480" ---------------------------------------------------------------------
6481" s:NetrwMaps: {{{2
6482fun! s:NetrwMaps(islocal)
6483" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6484
Bram Moolenaar85850f32019-07-19 22:05:51 +02006485 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006486 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006487" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006488 if !hasmapto("<Plug>NetrwReturn")
6489 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006490" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006491 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6492 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006493" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006494 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6495 endif
6496 endif
6497 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006498" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006499 endif
6500
Bram Moolenaar85850f32019-07-19 22:05:51 +02006501 " generate default <Plug> maps {{{3
6502 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006503 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006504 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6505 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6506 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6507 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6508 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6509 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6510 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6511 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6512 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6513 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6514" ---------------------------------------------------------------------
6515" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6516" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6517" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6518" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6519" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6520" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6521" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6522" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6523" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6524" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6525" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6526" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6527" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6528" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6529" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6530" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6531" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6532" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6533" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6534" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6535" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6536" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6537" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6538" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6539" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6540" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6541" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6542" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6543" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6544" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6545" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6546" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6547" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6548" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6549" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6550" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6551" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6552" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6553" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6554" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6555" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6556" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6557" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6558" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6559" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6560" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6561" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6562
Bram Moolenaara6878372014-03-22 21:02:50 +01006563 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006564" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006565 " local normal-mode maps {{{3
6566 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6567 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6568 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6569 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6570 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6571 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6572 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6573 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6574 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6575 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6576 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6577" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006578 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6579 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6580 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006581 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006582 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006583 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6584 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6585 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6586 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006587 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6588 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6589 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6590 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6591 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6592 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6593 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6594 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6595 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6596 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6597 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6598 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6599 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006600 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006601 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006602 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6603 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6604 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6605 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6606 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006607 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006608 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006609 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6610 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006611 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6612 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6613 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006614 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006615 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006616 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6617 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006618 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006619 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006620 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6621 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6622 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006623 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6624 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006625
6626 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 +01006627 if !hasmapto('<Plug>NetrwHideEdit')
6628 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006629 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006630 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006631 if !hasmapto('<Plug>NetrwRefresh')
6632 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006633 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006634 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 +01006635 if s:didstarstar || !mapcheck("<s-down>","n")
6636 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006637 endif
6638 if s:didstarstar || !mapcheck("<s-up>","n")
6639 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006640 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006641 if !hasmapto('<Plug>NetrwTreeSqueeze')
6642 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006643 endif
6644 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006645 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6646 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006647 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6648 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6649 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6650 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6651 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6652 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6653 imap <buffer> <leftmouse> <Plug>ILeftmouse
6654 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006655 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6656 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6657 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6658 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6659 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006660 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006661 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6662 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006663 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006664 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6665 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6666 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6667 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6668 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6669 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6670 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006671 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6672
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006673 " support user-specified maps
6674 call netrw#UserMaps(1)
6675
Bram Moolenaar85850f32019-07-19 22:05:51 +02006676 else
6677 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006678" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006679 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006680 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6681 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6682 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6683 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6684 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6685 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6686 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6687 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6688 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6689 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6690 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6691" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006692 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6693 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6694 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6695 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6696 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6697 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6698 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6699 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006700 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006701 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006702 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6703 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6704 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6705 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6706 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6707 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6708 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6709 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6710 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6711 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6712 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006713 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006714 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006715 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6716 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6717 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6718 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6719 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006720 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6721 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6722 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6723 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006724 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006725 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6726 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006727 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006728 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 +01006729 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6730 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6731 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6732 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6733 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6734 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6735 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6736 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6737 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006738 if !hasmapto('<Plug>NetrwHideEdit')
6739 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006740 endif
6741 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6742 if !hasmapto('<Plug>NetrwRefresh')
6743 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006744 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006745 if !hasmapto('<Plug>NetrwTreeSqueeze')
6746 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006747 endif
6748 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006749
6750 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006751 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006752
6753 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6754 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006755 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006756 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006757 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006758 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006759 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006760 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006761 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006762 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006763 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006764 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006765 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6766 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6767 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006768 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006769 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006770 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6771 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006772 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006773 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6774 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6775 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6776 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6777 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6778 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6779 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006780 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006781
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006782 " support user-specified maps
6783 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006784 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006785
6786" call Dret("s:NetrwMaps")
6787endfun
6788
6789" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006790" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006791" If -buffer, the command is only available from within netrw buffers
6792" Otherwise, the command is available from any window, so long as netrw
6793" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006794fun! s:NetrwCommands(islocal)
6795" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6796
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006797 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6798 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006799 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 +01006800 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006801 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006802 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006803 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006804 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006805 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006806
6807" call Dret("s:NetrwCommands")
6808endfun
6809
6810" ---------------------------------------------------------------------
6811" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6812" glob()ing only works with local files
6813fun! s:NetrwMarkFiles(islocal,...)
6814" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006815 let curdir = s:NetrwGetCurdir(a:islocal)
6816 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006817 while i <= a:0
6818 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006819 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006820 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006821 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006822 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006823 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006824 else
6825 let mffiles= [a:{i}]
6826 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006827" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006828 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006829" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006830 call s:NetrwMarkFile(a:islocal,mffile)
6831 endfor
6832 let i= i + 1
6833 endwhile
6834" call Dret("s:NetrwMarkFiles")
6835endfun
6836
6837" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006838" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006839fun! s:NetrwMarkTarget(...)
6840" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6841 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006842 let curdir = s:NetrwGetCurdir(1)
6843 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006844 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006845 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6846 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006847 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006848" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006849 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006850 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6851 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006852 let svpos = winsaveview()
6853" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006854 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006855" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6856 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006857" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006858endfun
6859
6860" ---------------------------------------------------------------------
6861" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6862" mark and unmark files. If a markfile list exists,
6863" then the rename and delete functions will use it instead
6864" of whatever may happen to be under the cursor at that
6865" moment. When the mouse and gui are available,
6866" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006867"
6868" Creates two lists
6869" s:netrwmarkfilelist -- holds complete paths to all marked files
6870" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6871"
6872" Creates a marked file match string
6873" s:netrwmarfilemtch_# -- used with 2match to display marked files
6874"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006875" Creates a buffer version of islocal
6876" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006877fun! s:NetrwMarkFile(islocal,fname)
6878" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006879" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006880
6881 " sanity check
6882 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006883" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006884 return
6885 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006886 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006887
Bram Moolenaar97d62492012-11-15 21:28:22 +01006888 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006889 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006890 if a:fname =~ '^\a'
6891 let leader= '\<'
6892 else
6893 let leader= ''
6894 endif
6895 if a:fname =~ '\a$'
6896 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6897 else
6898 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6899 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006900
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006901 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006902 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006903" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6904" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6905" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006906 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006907
6908 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006909 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006910" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006911 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006912 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006913
6914 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006915 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006916" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006917 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6918 if s:netrwmarkfilelist_{curbufnr} == []
6919 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006920" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006921 call s:NetrwUnmarkList(curbufnr,curdir)
6922 else
6923 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006924" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006925 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006926 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006927 for fname in s:netrwmarkfilelist_{curbufnr}
6928 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006929 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006930 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006931 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006932 endif
6933 let first= 0
6934 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006935" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006936 endif
6937 endif
6938
6939 else
6940 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006941" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006943" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006944 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006945 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6946" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006947
6948 " build initial markfile matching pattern
6949 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006950 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006951 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006952 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006953 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006954" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006955 endif
6956
6957 " handle global markfilelist
6958 if exists("s:netrwmarkfilelist")
6959 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6960 if index(s:netrwmarkfilelist,dname) == -1
6961 " append new filename to global markfilelist
6962 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006963" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006964 else
6965 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006966" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6967" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006968 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006969" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006970 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006971" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006972 unlet s:netrwmarkfilelist
6973 endif
6974 endif
6975 else
6976 " initialize new global-directory markfilelist
6977 let s:netrwmarkfilelist= []
6978 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006979" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006980 endif
6981
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006982 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006983 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6984 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6985" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6986 if exists("g:did_drchip_netrwlist_syntax")
6987 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6988 endif
6989 else
6990" " call Decho("2match none",'~'.expand("<slnum>"))
6991 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006992 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006993 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006994 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006995" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6996" 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 +00006997endfun
6998
6999" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007000" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7001" mA: move the argument list to marked file list (tomflist=1)
7002" Uses the global marked file list
7003fun! s:NetrwMarkFileArgList(islocal,tomflist)
7004" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7005
7006 let svpos = winsaveview()
7007" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7008 let curdir = s:NetrwGetCurdir(a:islocal)
7009 let curbufnr = bufnr("%")
7010
7011 if a:tomflist
7012 " mA: move argument list to marked file list
7013 while argc()
7014 let fname= argv(0)
7015" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7016 exe "argdel ".fnameescape(fname)
7017 call s:NetrwMarkFile(a:islocal,fname)
7018 endwhile
7019
7020 else
7021 " ma: move marked file list to argument list
7022 if exists("s:netrwmarkfilelist")
7023
7024 " for every filename in the marked list
7025 for fname in s:netrwmarkfilelist
7026" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7027 exe "argadd ".fnameescape(fname)
7028 endfor " for every file in the marked list
7029
7030 " unmark list and refresh
7031 call s:NetrwUnmarkList(curbufnr,curdir)
7032 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7033" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7034 NetrwKeepj call winrestview(svpos)
7035 endif
7036 endif
7037
7038" call Dret("s:NetrwMarkFileArgList")
7039endfun
7040
7041" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007042" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7043" compress/decompress files using the programs
7044" in g:netrw_compress and g:netrw_uncompress,
7045" using g:netrw_compress_suffix to know which to
7046" do. By default:
7047" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007048" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007049fun! s:NetrwMarkFileCompress(islocal)
7050" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007051 let svpos = winsaveview()
7052" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007053 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007054 let curbufnr = bufnr("%")
7055
Bram Moolenaarff034192013-04-24 18:51:19 +02007056 " sanity check
7057 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007058 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007059" call Dret("s:NetrwMarkFileCompress")
7060 return
7061 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007062" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007063
Bram Moolenaar446cb832008-06-24 21:56:24 +00007064 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007065
7066 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007067 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007068 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007069" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007070 if exists("g:netrw_decompress['".sfx."']")
7071 " fname has a suffix indicating that its compressed; apply associated decompression routine
7072 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007073" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007074 let exe= netrw#WinPath(exe)
7075 if a:islocal
7076 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007077 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007078 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007079 call system(exe." ".fname)
7080 if v:shell_error
7081 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007082 endif
7083 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007084 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7085 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007086 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007087
Bram Moolenaarff034192013-04-24 18:51:19 +02007088 endif
7089 unlet sfx
7090
Bram Moolenaar446cb832008-06-24 21:56:24 +00007091 if exists("exe")
7092 unlet exe
7093 elseif a:islocal
7094 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007095 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007096 if v:shell_error
7097 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7098 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007099 else
7100 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007101 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007102 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007103 endfor " for every file in the marked list
7104
Bram Moolenaar446cb832008-06-24 21:56:24 +00007105 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007106 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007107" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7108 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007109 endif
7110" call Dret("s:NetrwMarkFileCompress")
7111endfun
7112
7113" ---------------------------------------------------------------------
7114" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7115" If no marked files, then set up directory as the
7116" target. Currently does not support copying entire
7117" directories. Uses the local-buffer marked file list.
7118" Returns 1=success (used by NetrwMarkFileMove())
7119" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007120fun! s:NetrwMarkFileCopy(islocal,...)
7121" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7122
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007123 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007124 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007125 if b:netrw_curdir !~ '/$'
7126 if !exists("b:netrw_curdir")
7127 let b:netrw_curdir= curdir
7128 endif
7129 let b:netrw_curdir= b:netrw_curdir."/"
7130 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007131
Bram Moolenaarff034192013-04-24 18:51:19 +02007132 " sanity check
7133 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007134 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007135" call Dret("s:NetrwMarkFileCopy")
7136 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007137 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007138" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007139
Bram Moolenaar446cb832008-06-24 21:56:24 +00007140 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007141 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007142" call Dret("s:NetrwMarkFileCopy 0")
7143 return 0
7144 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007145" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007146
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007147 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007148 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007149" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007150 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007151 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7152" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7153 return
7154 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007155
7156 " copy marked files while within the same directory (ie. allow renaming)
7157 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7158 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7159 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007160" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007161 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007162 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7163 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007164" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007165 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007166 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007167 let oldname = a:1
7168 else
7169 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007170" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007171 let s:recursive= 1
7172 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7173 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7174 if ret == 0
7175 break
7176 endif
7177 endfor
7178 unlet s:recursive
7179 call s:NetrwUnmarkList(curbufnr,curdir)
7180" call Dret("s:NetrwMarkFileCopy ".ret)
7181 return ret
7182 endif
7183
7184 call inputsave()
7185 let newname= input("Copy ".oldname." to : ",oldname,"file")
7186 call inputrestore()
7187 if newname == ""
7188" call Dret("s:NetrwMarkFileCopy 0")
7189 return 0
7190 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007191 let args= s:ShellEscape(oldname)
7192 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007193 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007194 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7195 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007196 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007197 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007198 let args= substitute(args,'/','\\','g')
7199 let tgt = substitute(tgt, '/','\\','g')
7200 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007201 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7202 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7203 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7204 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7205" call Decho("args <".args.">",'~'.expand("<slnum>"))
7206" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007207 if isdirectory(s:NetrwFile(args))
7208" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007209 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007210" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007211 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007212 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7213 " contents to a target. One must append the source directory name to the target to get xcopy to
7214 " do the right thing.
7215 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007216" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007217 endif
7218 else
7219 let copycmd= g:netrw_localcopycmd
7220 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007221 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007222 let copycmd = substitute(copycmd,'\s.*$','','')
7223 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007224 let copycmd = netrw#WinPath(copycmd).copycmdargs
7225 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007226 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007227 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007228" call Decho("args <".args.">",'~'.expand("<slnum>"))
7229" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7230" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7231" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007232 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007233 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007234 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007235 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 +01007236 else
7237 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7238 endif
7239" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007240 return 0
7241 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007242
7243 elseif a:islocal && !s:netrwmftgt_islocal
7244 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007245" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007246 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007247
7248 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007249 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007250" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007251 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007252
7253 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007254 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007255" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007256 let curdir = getcwd()
7257 let tmpdir = s:GetTempfile("")
7258 if tmpdir !~ '/'
7259 let tmpdir= curdir."/".tmpdir
7260 endif
7261 if exists("*mkdir")
7262 call mkdir(tmpdir)
7263 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007264 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007265 if v:shell_error != 0
7266 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 +01007267" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007268 return
7269 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007270 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007271 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007272 if s:NetrwLcd(tmpdir)
7273" call Dret("s:NetrwMarkFileCopy : lcd failure")
7274 return
7275 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007276 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007277 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007278 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279 if getcwd() == tmpdir
7280 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007281 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007282 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007283 if s:NetrwLcd(curdir)
7284" call Dret("s:NetrwMarkFileCopy : lcd failure")
7285 return
7286 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007287 if delete(tmpdir,"d")
7288 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007289 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007290 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007291 if s:NetrwLcd(curdir)
7292" call Dret("s:NetrwMarkFileCopy : lcd failure")
7293 return
7294 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007295 endif
7296 endif
7297 endif
7298
7299 " -------
7300 " cleanup
7301 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007302" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007303 " remove markings from local buffer
7304 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007305" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7306" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7307" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7308" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7309" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7310" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7311 if exists("s:recursive")
7312" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7313 else
7314" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007315 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007316 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007317 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007318 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007319 else
7320 " refresh local and targets for fast browsing
7321 if !exists("s:recursive")
7322 " remove markings from local buffer
7323" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7324 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7325 endif
7326
7327 " refresh buffers
7328 if s:netrwmftgt_islocal
7329" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7330 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7331 endif
7332 if a:islocal && s:netrwmftgt != curdir
7333" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7334 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7335 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007336 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007337
Bram Moolenaar446cb832008-06-24 21:56:24 +00007338" call Dret("s:NetrwMarkFileCopy 1")
7339 return 1
7340endfun
7341
7342" ---------------------------------------------------------------------
7343" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7344" invoke vim's diff mode on the marked files.
7345" Either two or three files can be so handled.
7346" Uses the global marked file list.
7347fun! s:NetrwMarkFileDiff(islocal)
7348" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7349 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007350
Bram Moolenaarff034192013-04-24 18:51:19 +02007351 " sanity check
7352 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007353 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007354" call Dret("s:NetrwMarkFileDiff")
7355 return
7356 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007357 let curdir= s:NetrwGetCurdir(a:islocal)
7358" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007359
Bram Moolenaara6878372014-03-22 21:02:50 +01007360 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007362 for fname in s:netrwmarkfilelist
7363 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007364 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007365" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007366 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007367 diffthis
7368 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007369 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007370" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007371 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007372 diffthis
7373 else
7374 break
7375 endif
7376 endfor
7377 call s:NetrwUnmarkList(curbufnr,curdir)
7378 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007379
Bram Moolenaar446cb832008-06-24 21:56:24 +00007380" call Dret("s:NetrwMarkFileDiff")
7381endfun
7382
7383" ---------------------------------------------------------------------
7384" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7385" Uses global markfilelist
7386fun! s:NetrwMarkFileEdit(islocal)
7387" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7388
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007389 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007390 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007391
7392 " sanity check
7393 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007394 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007395" call Dret("s:NetrwMarkFileEdit")
7396 return
7397 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007398" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007399
Bram Moolenaar446cb832008-06-24 21:56:24 +00007400 if exists("s:netrwmarkfilelist_{curbufnr}")
7401 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007402 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007403 " unmark markedfile list
7404" call s:NetrwUnmarkList(curbufnr,curdir)
7405 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007406" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007407 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007408 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007409 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007410
Bram Moolenaar446cb832008-06-24 21:56:24 +00007411" call Dret("s:NetrwMarkFileEdit")
7412endfun
7413
7414" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007415" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007416fun! s:NetrwMarkFileQFEL(islocal,qfel)
7417" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7418 call s:NetrwUnmarkAll()
7419 let curbufnr= bufnr("%")
7420
7421 if !empty(a:qfel)
7422 for entry in a:qfel
7423 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007424" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007425 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007426" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007427 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7428 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7429 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7430 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007431" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007432 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7433 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007434" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007435 endif
7436 endfor
7437 echo "(use me to edit marked files)"
7438 else
7439 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7440 endif
7441
7442" call Dret("s:NetrwMarkFileQFEL")
7443endfun
7444
7445" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007446" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7447" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7448" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7449fun! s:NetrwMarkFileExe(islocal,enbloc)
7450" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007451 let svpos = winsaveview()
7452" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007453 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007454 let curbufnr = bufnr("%")
7455
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007456 if a:enbloc == 0
7457 " individually apply command to files, one at a time
7458 " sanity check
7459 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7460 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7461" call Dret("s:NetrwMarkFileExe")
7462 return
7463 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007464" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007465
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007466 if exists("s:netrwmarkfilelist_{curbufnr}")
7467 " get the command
7468 call inputsave()
7469 let cmd= input("Enter command: ","","file")
7470 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007471" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007472 if cmd == ""
7473" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7474 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007475 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007476
7477 " apply command to marked files, individually. Substitute: filename -> %
7478 " If no %, then append a space and the filename to the command
7479 for fname in s:netrwmarkfilelist_{curbufnr}
7480 if a:islocal
7481 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007482 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483 endif
7484 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007485 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007486 endif
7487 if cmd =~ '%'
7488 let xcmd= substitute(cmd,'%',fname,'g')
7489 else
7490 let xcmd= cmd.' '.fname
7491 endif
7492 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007493" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007494 let ret= system(xcmd)
7495 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007496" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007497 let ret= s:RemoteSystem(xcmd)
7498 endif
7499 if v:shell_error < 0
7500 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7501 break
7502 else
7503 echo ret
7504 endif
7505 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007506
7507 " unmark marked file list
7508 call s:NetrwUnmarkList(curbufnr,curdir)
7509
7510 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007511 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007512" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7513 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007514 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007515 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007516 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007517
7518 else " apply command to global list of files, en bloc
7519
7520 call inputsave()
7521 let cmd= input("Enter command: ","","file")
7522 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007523" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007524 if cmd == ""
7525" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7526 return
7527 endif
7528 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007529 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007530 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007531 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007532 endif
7533 if a:islocal
7534 call system(cmd)
7535 if v:shell_error < 0
7536 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7537 endif
7538 else
7539 let ret= s:RemoteSystem(cmd)
7540 endif
7541 call s:NetrwUnmarkAll()
7542
7543 " refresh the listing
7544 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007545" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7546 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007547
7548 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007549
Bram Moolenaar446cb832008-06-24 21:56:24 +00007550" call Dret("s:NetrwMarkFileExe")
7551endfun
7552
7553" ---------------------------------------------------------------------
7554" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7555" as the marked file(s) (toggles suffix presence)
7556" Uses the local marked file list.
7557fun! s:NetrwMarkHideSfx(islocal)
7558" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007559 let svpos = winsaveview()
7560" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007561 let curbufnr = bufnr("%")
7562
7563 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7564 if exists("s:netrwmarkfilelist_{curbufnr}")
7565
7566 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007567" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007568 " construct suffix pattern
7569 if fname =~ '\.'
7570 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7571 else
7572 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7573 endif
7574 " determine if its in the hiding list or not
7575 let inhidelist= 0
7576 if g:netrw_list_hide != ""
7577 let itemnum = 0
7578 let hidelist= split(g:netrw_list_hide,',')
7579 for hidepat in hidelist
7580 if sfxpat == hidepat
7581 let inhidelist= 1
7582 break
7583 endif
7584 let itemnum= itemnum + 1
7585 endfor
7586 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007587" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007588 if inhidelist
7589 " remove sfxpat from list
7590 call remove(hidelist,itemnum)
7591 let g:netrw_list_hide= join(hidelist,",")
7592 elseif g:netrw_list_hide != ""
7593 " append sfxpat to non-empty list
7594 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7595 else
7596 " set hiding list to sfxpat
7597 let g:netrw_list_hide= sfxpat
7598 endif
7599 endfor
7600
7601 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007602 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007603" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7604 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007605 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007606 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007607 endif
7608
7609" call Dret("s:NetrwMarkHideSfx")
7610endfun
7611
7612" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007613" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007614" Uses the local marked-file list.
7615fun! s:NetrwMarkFileVimCmd(islocal)
7616" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007617 let svpos = winsaveview()
7618" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007619 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007620 let curbufnr = bufnr("%")
7621
Bram Moolenaarff034192013-04-24 18:51:19 +02007622 " sanity check
7623 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007624 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007625" call Dret("s:NetrwMarkFileVimCmd")
7626 return
7627 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007628" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007629
Bram Moolenaar15146672011-10-20 22:22:38 +02007630 if exists("s:netrwmarkfilelist_{curbufnr}")
7631 " get the command
7632 call inputsave()
7633 let cmd= input("Enter vim command: ","","file")
7634 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007635" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007636 if cmd == ""
7637" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7638 return
7639 endif
7640
7641 " apply command to marked files. Substitute: filename -> %
7642 " If no %, then append a space and the filename to the command
7643 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007644" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007645 if a:islocal
7646 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007647 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007648" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007649 exe cmd
7650 exe "sil! keepalt wq!"
7651 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007652" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007653 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007654 endif
7655 endfor
7656
7657 " unmark marked file list
7658 call s:NetrwUnmarkList(curbufnr,curdir)
7659
7660 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007661 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007662" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7663 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007664 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007665 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007666 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007667
Bram Moolenaar15146672011-10-20 22:22:38 +02007668" call Dret("s:NetrwMarkFileVimCmd")
7669endfun
7670
7671" ---------------------------------------------------------------------
7672" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7673" as the marked file(s) (toggles suffix presence)
7674" Uses the local marked file list.
7675fun! s:NetrwMarkHideSfx(islocal)
7676" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007677 let svpos = winsaveview()
7678" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007679 let curbufnr = bufnr("%")
7680
7681 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7682 if exists("s:netrwmarkfilelist_{curbufnr}")
7683
7684 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007685" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007686 " construct suffix pattern
7687 if fname =~ '\.'
7688 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7689 else
7690 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7691 endif
7692 " determine if its in the hiding list or not
7693 let inhidelist= 0
7694 if g:netrw_list_hide != ""
7695 let itemnum = 0
7696 let hidelist= split(g:netrw_list_hide,',')
7697 for hidepat in hidelist
7698 if sfxpat == hidepat
7699 let inhidelist= 1
7700 break
7701 endif
7702 let itemnum= itemnum + 1
7703 endfor
7704 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007705" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007706 if inhidelist
7707 " remove sfxpat from list
7708 call remove(hidelist,itemnum)
7709 let g:netrw_list_hide= join(hidelist,",")
7710 elseif g:netrw_list_hide != ""
7711 " append sfxpat to non-empty list
7712 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7713 else
7714 " set hiding list to sfxpat
7715 let g:netrw_list_hide= sfxpat
7716 endif
7717 endfor
7718
7719 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007720 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007721" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7722 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007723 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007724 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007725 endif
7726
7727" call Dret("s:NetrwMarkHideSfx")
7728endfun
7729
7730" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007731" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7732" Uses the global markfilelist
7733fun! s:NetrwMarkFileGrep(islocal)
7734" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007735 let svpos = winsaveview()
7736" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007737 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007738 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007739
7740 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007741" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007742 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007743" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007744 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007745 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007746" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007747 let netrwmarkfilelist= "*"
7748 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007749
Bram Moolenaarff034192013-04-24 18:51:19 +02007750 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007751" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007752 call inputsave()
7753 let pat= input("Enter pattern: ","")
7754 call inputrestore()
7755 let patbang = ""
7756 if pat =~ '^!'
7757 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007758 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007759 endif
7760 if pat =~ '^\i'
7761 let pat = escape(pat,'/')
7762 let pat = '/'.pat.'/'
7763 else
7764 let nonisi = pat[0]
7765 endif
7766
7767 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007768" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007769 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007770 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007771 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007772 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007773" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7774 return
7775 endtry
7776 echo "(use :cn, :cp to navigate, :Rex to return)"
7777
7778 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007779" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7780 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007781
7782 if exists("nonisi")
7783 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007784" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007785 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007786 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007787 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007788 endif
7789
7790" call Dret("s:NetrwMarkFileGrep")
7791endfun
7792
7793" ---------------------------------------------------------------------
7794" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7795" uses the global marked file list
7796" s:netrwmfloc= 0: target directory is remote
7797" = 1: target directory is local
7798fun! s:NetrwMarkFileMove(islocal)
7799" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007800 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007801 let curbufnr = bufnr("%")
7802
7803 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007804 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007805 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007806" call Dret("s:NetrwMarkFileMove")
7807 return
7808 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007809" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007810
Bram Moolenaar446cb832008-06-24 21:56:24 +00007811 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007812 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007813" call Dret("s:NetrwMarkFileCopy 0")
7814 return 0
7815 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007816" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817
7818 if a:islocal && s:netrwmftgt_islocal
7819 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007820" call Decho("move from local to local",'~'.expand("<slnum>"))
7821" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007822 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007823 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7824" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7825 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007826 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007827 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007828" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007829 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007830 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007831" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007832 if g:netrw_localmovecmd =~ '\s'
7833 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7834 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7835 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007836" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007837 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007838 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007839" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007840 endif
7841 else
7842 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007843" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007844 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007845 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007846 if g:netrw_keepdir
7847 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7848 let fname= b:netrw_curdir."/".fname
7849 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007850 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007851 let fname= substitute(fname,'/','\\','g')
7852 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007854 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007855 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007856 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007857 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 +01007858 else
7859 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7860 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007861 break
7862 endif
7863 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007864
7865 elseif a:islocal && !s:netrwmftgt_islocal
7866 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007867" call Decho("move from local to remote",'~'.expand("<slnum>"))
7868" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007869 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007870 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007871" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007872 for fname in mflist
7873 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7874 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7875 endfor
7876 unlet mflist
7877
7878 elseif !a:islocal && s:netrwmftgt_islocal
7879 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007880" call Decho("move from remote to local",'~'.expand("<slnum>"))
7881" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007882 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007883 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007884" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007885 for fname in mflist
7886 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7887 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7888 endfor
7889 unlet mflist
7890
7891 elseif !a:islocal && !s:netrwmftgt_islocal
7892 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007893" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7894" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007895 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007896 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007897" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007898 for fname in mflist
7899 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7900 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7901 endfor
7902 unlet mflist
7903 endif
7904
7905 " -------
7906 " cleanup
7907 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007908" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007909
7910 " remove markings from local buffer
7911 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7912
7913 " refresh buffers
7914 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007915" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007916 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007917 endif
7918 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007919" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007920 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007921 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007922 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007923" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007924 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007925 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007926
Bram Moolenaar446cb832008-06-24 21:56:24 +00007927" call Dret("s:NetrwMarkFileMove")
7928endfun
7929
7930" ---------------------------------------------------------------------
7931" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7932" using the hardcopy command. Local marked-file list only.
7933fun! s:NetrwMarkFilePrint(islocal)
7934" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7935 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007936
7937 " sanity check
7938 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007939 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007940" call Dret("s:NetrwMarkFilePrint")
7941 return
7942 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007943" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7944 let curdir= s:NetrwGetCurdir(a:islocal)
7945
Bram Moolenaar446cb832008-06-24 21:56:24 +00007946 if exists("s:netrwmarkfilelist_{curbufnr}")
7947 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007948 call s:NetrwUnmarkList(curbufnr,curdir)
7949 for fname in netrwmarkfilelist
7950 if a:islocal
7951 if g:netrw_keepdir
7952 let fname= s:ComposePath(curdir,fname)
7953 endif
7954 else
7955 let fname= curdir.fname
7956 endif
7957 1split
7958 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007959" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007960 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007961" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007962 hardcopy
7963 q
7964 endfor
7965 2match none
7966 endif
7967" call Dret("s:NetrwMarkFilePrint")
7968endfun
7969
7970" ---------------------------------------------------------------------
7971" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7972" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007973" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007974fun! s:NetrwMarkFileRegexp(islocal)
7975" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7976
7977 " get the regular expression
7978 call inputsave()
7979 let regexp= input("Enter regexp: ","","file")
7980 call inputrestore()
7981
7982 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007983 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007984" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007985 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007986" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007987 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007988 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007989 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007990 else
7991 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007992 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007993 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007994" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007995
7996 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007997 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007998 if fname =~ '^'.fnameescape(curdir)
7999" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8000 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8001 else
8002" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8003 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8004 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008005 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006
8007 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008008" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008009
8010 " convert displayed listing into a filelist
8011 let eikeep = &ei
8012 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008013 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008014 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008015" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008016 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008017 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008018 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008019 sil NetrwKeepj norm! "ap
8020 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008022 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008023 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008025 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008026 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008028 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008029 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008030 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008031 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8032 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008033 call histdel("/",-1)
8034 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008035 endif
8036 " convert regexp into the more usual glob-style format
8037 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008038" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008039 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008040 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008041 let filelist= getline(1,line("$"))
8042 q!
8043 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008044 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008045 endfor
8046 unlet filelist
8047 let @a = areg
8048 let &ei = eikeep
8049 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008050 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008051
8052" call Dret("s:NetrwMarkFileRegexp")
8053endfun
8054
8055" ---------------------------------------------------------------------
8056" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8057" Uses the local marked file list.
8058fun! s:NetrwMarkFileSource(islocal)
8059" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8060 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008061
8062 " sanity check
8063 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008064 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008065" call Dret("s:NetrwMarkFileSource")
8066 return
8067 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008068" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8069 let curdir= s:NetrwGetCurdir(a:islocal)
8070
Bram Moolenaar446cb832008-06-24 21:56:24 +00008071 if exists("s:netrwmarkfilelist_{curbufnr}")
8072 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008073 call s:NetrwUnmarkList(curbufnr,curdir)
8074 for fname in netrwmarkfilelist
8075 if a:islocal
8076 if g:netrw_keepdir
8077 let fname= s:ComposePath(curdir,fname)
8078 endif
8079 else
8080 let fname= curdir.fname
8081 endif
8082 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008083" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008084 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008085 endfor
8086 2match none
8087 endif
8088" call Dret("s:NetrwMarkFileSource")
8089endfun
8090
8091" ---------------------------------------------------------------------
8092" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8093" Uses the global markfilelist
8094fun! s:NetrwMarkFileTag(islocal)
8095" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008096 let svpos = winsaveview()
8097" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008098 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008099 let curbufnr = bufnr("%")
8100
Bram Moolenaarff034192013-04-24 18:51:19 +02008101 " sanity check
8102 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008103 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008104" call Dret("s:NetrwMarkFileTag")
8105 return
8106 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008107" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008108
Bram Moolenaar446cb832008-06-24 21:56:24 +00008109 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008110" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8111 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008112 call s:NetrwUnmarkAll()
8113
8114 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008115
8116" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8117 call system(g:netrw_ctags." ".netrwmarkfilelist)
8118 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8120 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008121
Bram Moolenaar446cb832008-06-24 21:56:24 +00008122 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008123 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008124 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008125 let curdir= b:netrw_curdir
8126 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008127 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008128 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008129" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008130 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008131 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008132 wq!
8133 endif
8134 2match none
8135 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008136" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8137 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008138 endif
8139
8140" call Dret("s:NetrwMarkFileTag")
8141endfun
8142
8143" ---------------------------------------------------------------------
8144" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008145" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008146" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008147" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008148" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008150" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8151 let svpos = winsaveview()
8152" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008153 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008154 let hadtgt = exists("s:netrwmftgt")
8155 if !exists("w:netrw_bannercnt")
8156 let w:netrw_bannercnt= b:netrw_bannercnt
8157 endif
8158
8159 " set up target
8160 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008161" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008162 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8163 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008164" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008165 unlet s:netrwmftgt s:netrwmftgt_islocal
8166 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008167 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008168 endif
8169 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008170" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8171 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008172" call Dret("s:NetrwMarkFileTgt : removed target")
8173 return
8174 else
8175 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008176" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008177 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008178
8179 else
8180 " get word under cursor.
8181 " * If directory, use it for the target.
8182 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184 let curword= s:NetrwGetWord()
8185 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008186 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008187 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008189 elseif !a:islocal && tgtdir =~ '/$'
8190 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008192 else
8193 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008194" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008195 endif
8196 endif
8197 if a:islocal
8198 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8199 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008200" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008201 endif
8202 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008203 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008204 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8205 endif
8206 let s:netrwmftgt_islocal= a:islocal
8207
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008208 " need to do refresh so that the banner will be updated
8209 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008210 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008211" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008212 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008213 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008214" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008215 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008216 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8217 else
8218 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8219 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008220" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8221 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008222 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008223 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008224 endif
8225
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008226" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8227" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008228" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8229endfun
8230
8231" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008232" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8233fun! s:NetrwGetCurdir(islocal)
8234" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8235
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008236 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008237 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8238" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8239 elseif !exists("b:netrw_curdir")
8240 let b:netrw_curdir= getcwd()
8241" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8242 endif
8243
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008244" 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 +01008245 if b:netrw_curdir !~ '\<\a\{3,}://'
8246 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008247" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008248 if g:netrw_keepdir == 0
8249 call s:NetrwLcd(curdir)
8250 endif
8251 endif
8252
8253" call Dret("s:NetrwGetCurdir <".curdir.">")
8254 return b:netrw_curdir
8255endfun
8256
8257" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008258" s:NetrwOpenFile: query user for a filename and open it {{{2
8259fun! s:NetrwOpenFile(islocal)
8260" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008261 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008262 call inputsave()
8263 let fname= input("Enter filename: ")
8264 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008265" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8266
8267 " determine if Lexplore is in use
8268 if exists("t:netrw_lexbufnr")
8269 " check if t:netrw_lexbufnr refers to a netrw window
8270" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8271 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8272 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8273" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8274 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8275 exe "NetrwKeepj e ".fnameescape(fname)
8276 let @@= ykeep
8277" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8278 endif
8279 endif
8280
8281 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008282 if fname !~ '[/\\]'
8283 if exists("b:netrw_curdir")
8284 if exists("g:netrw_quiet")
8285 let netrw_quiet_keep = g:netrw_quiet
8286 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008287 let g:netrw_quiet = 1
8288 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008289 let s:rexposn_{bufnr("%")}= winsaveview()
8290" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008291 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008292 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008293 else
8294 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8295 endif
8296 if exists("netrw_quiet_keep")
8297 let g:netrw_quiet= netrw_quiet_keep
8298 else
8299 unlet g:netrw_quiet
8300 endif
8301 endif
8302 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008303 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008304 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008305 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008306" call Dret("s:NetrwOpenFile")
8307endfun
8308
8309" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008310" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8311" For the mapping to this function be made via
8312" netrwPlugin, you'll need to have had
8313" g:netrw_usetab set to non-zero.
8314fun! netrw#Shrink()
8315" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8316 let curwin = winnr()
8317 let wiwkeep = &wiw
8318 set wiw=1
8319
8320 if &ft == "netrw"
8321 if winwidth(0) > g:netrw_wiw
8322 let t:netrw_winwidth= winwidth(0)
8323 exe "vert resize ".g:netrw_wiw
8324 wincmd l
8325 if winnr() == curwin
8326 wincmd h
8327 endif
8328" call Decho("vert resize 0",'~'.expand("<slnum>"))
8329 else
8330 exe "vert resize ".t:netrw_winwidth
8331" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8332 endif
8333
8334 elseif exists("t:netrw_lexbufnr")
8335 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8336 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8337 let t:netrw_winwidth= winwidth(0)
8338 exe "vert resize ".g:netrw_wiw
8339 wincmd l
8340 if winnr() == curwin
8341 wincmd h
8342 endif
8343" call Decho("vert resize 0",'~'.expand("<slnum>"))
8344 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8345 exe "vert resize ".t:netrw_winwidth
8346" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8347 else
8348 call netrw#Lexplore(0,0)
8349 endif
8350
8351 else
8352 call netrw#Lexplore(0,0)
8353 endif
8354 let wiw= wiwkeep
8355
8356" call Dret("netrw#Shrink")
8357endfun
8358
8359" ---------------------------------------------------------------------
8360" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8361fun! s:NetSortSequence(islocal)
8362" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8363
8364 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008365 let svpos= winsaveview()
8366" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008367 call inputsave()
8368 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8369 call inputrestore()
8370
8371 " refresh the listing
8372 let g:netrw_sort_sequence= newsortseq
8373 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008374" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8375 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008376 let @@= ykeep
8377
8378" call Dret("NetSortSequence")
8379endfun
8380
8381" ---------------------------------------------------------------------
8382" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8383" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008384" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008385fun! s:NetrwUnmarkList(curbufnr,curdir)
8386" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8387
8388 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008389 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008390 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8391 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8392 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8393 call remove(s:netrwmarkfilelist,idx) " remove from global list
8394 endfor
8395 if s:netrwmarkfilelist == []
8396 unlet s:netrwmarkfilelist
8397 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008398
Bram Moolenaar446cb832008-06-24 21:56:24 +00008399 " getting rid of the local marked-file lists is easy
8400 unlet s:netrwmarkfilelist_{a:curbufnr}
8401 endif
8402 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8403 unlet s:netrwmarkfilemtch_{a:curbufnr}
8404 endif
8405 2match none
8406" call Dret("s:NetrwUnmarkList")
8407endfun
8408
8409" ---------------------------------------------------------------------
8410" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8411fun! s:NetrwUnmarkAll()
8412" call Dfunc("s:NetrwUnmarkAll()")
8413 if exists("s:netrwmarkfilelist")
8414 unlet s:netrwmarkfilelist
8415 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008416 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008417 2match none
8418" call Dret("s:NetrwUnmarkAll")
8419endfun
8420
8421" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008422" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008423fun! s:NetrwUnmarkAll2()
8424" call Dfunc("s:NetrwUnmarkAll2()")
8425 redir => netrwmarkfilelist_let
8426 let
8427 redir END
8428 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008429 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008430 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8431 for flist in netrwmarkfilelist_list
8432 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8433 unlet s:netrwmarkfilelist_{curbufnr}
8434 unlet s:netrwmarkfilemtch_{curbufnr}
8435 endfor
8436" call Dret("s:NetrwUnmarkAll2")
8437endfun
8438
8439" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008440" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8441"
8442" Marked files are in two types of lists:
8443" s:netrwmarkfilelist -- holds complete paths to all marked files
8444" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8445"
8446" Marked files suitable for use with 2match are in:
8447" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008448fun! s:NetrwUnMarkFile(islocal)
8449" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008450 let svpos = winsaveview()
8451" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008452 let curbufnr = bufnr("%")
8453
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008454 " unmark marked file list
8455 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8456 if exists("s:netrwmarkfilelist")
8457" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008458 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008459 endif
8460
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008461 let ibuf= 1
8462 while ibuf < bufnr("$")
8463 if exists("s:netrwmarkfilelist_".ibuf)
8464 unlet s:netrwmarkfilelist_{ibuf}
8465 unlet s:netrwmarkfilemtch_{ibuf}
8466 endif
8467 let ibuf = ibuf + 1
8468 endwhile
8469 2match none
8470
Bram Moolenaar446cb832008-06-24 21:56:24 +00008471" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008472"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8473call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008474" call Dret("s:NetrwUnMarkFile")
8475endfun
8476
8477" ---------------------------------------------------------------------
8478" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8479fun! s:NetrwMenu(domenu)
8480
8481 if !exists("g:NetrwMenuPriority")
8482 let g:NetrwMenuPriority= 80
8483 endif
8484
Bram Moolenaaradc21822011-04-01 18:03:16 +02008485 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008486" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8487
8488 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008489" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008490 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008491 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8492 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8495 if g:netrw_dirhistmax > 0
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8497 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8500 else
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8502 endif
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8517 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 +01008518 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 +02008519 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8548 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>'
8549 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>'
8550 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>'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8552 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>'
8553 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>'
8554 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 +01008555 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 +02008556 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008558 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008559 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8560 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008561
8562 elseif !a:domenu
8563 let s:netrwcnt = 0
8564 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008565 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008566 exe curwin."wincmd w"
8567
8568 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008569" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008570 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008571" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008572 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008573 endif
8574 endif
8575" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008576 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008577 endif
8578
8579endfun
8580
8581" ---------------------------------------------------------------------
8582" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8583" Used by the O maps (as <SID>NetrwObtain())
8584fun! s:NetrwObtain(islocal)
8585" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8586
Bram Moolenaar97d62492012-11-15 21:28:22 +01008587 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008588 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008589 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008590 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008591 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8592 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008593 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008594 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008595 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008596
8597" call Dret("NetrwObtain")
8598endfun
8599
8600" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8602" If there's only one window, then the window will first be split.
8603" Returns:
8604" choice = 0 : didn't have to choose
8605" choice = 1 : saved modified file in window first
8606" choice = 2 : didn't save modified file, opened window
8607" choice = 3 : cancel open
8608fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008609" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008610
Bram Moolenaar97d62492012-11-15 21:28:22 +01008611 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008613 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008614" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615
8616 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008617 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008618 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008619" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8620" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8621 let curword = s:NetrwGetWord()
8622 let choice = 0
8623 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8624" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008625 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008626" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008627 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008628" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008629" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008630" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008631
Bram Moolenaar8d043172014-01-23 14:24:41 +01008632 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008633 if lastwinnr == 1
8634 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008635" 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 +02008636 " g:netrw_preview=0: preview window shown in a horizontally split window
8637 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008638 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008639 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008640 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008641" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008642 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008644 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008645 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008646" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008647 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008648 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008649 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008650" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008651
8652 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008653" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008654 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008655" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008656 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008657" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008658 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008659" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008660 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008661" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008662" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008663" call Decho("COMBAK#12: mod=".&mod)
8664
8665 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8666 " whoops -- user trying to open file in the Lexplore window.
8667 " Use Lexplore's opening-file window instead.
8668" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8669" exe g:netrw_chgwin."wincmd w"
8670 wincmd p
8671 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8672 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008673
8674 " prevwinnr: the window number of the "prev" window
8675 " prevbufnr: the buffer number of the buffer in the "prev" window
8676 " bnrcnt : the qty of windows open on the "prev" buffer
8677 let prevwinnr = winnr()
8678 let prevbufnr = bufnr("%")
8679 let prevbufname = bufname("%")
8680 let prevmod = &mod
8681 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008682" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008683 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008684" 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 +01008685" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008686
8687 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008688 " and it doesn't appear in any other extant window, then ask the
8689 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008690 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008691" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008692 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008693" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008694 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008695" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008696
8697 if bnrcnt == 1 && &hidden == 0
8698 " only one copy of the modified buffer in a window, and
8699 " hidden not set, so overwriting will lose the modified file. Ask first...
8700 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008701" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008702 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008703" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008704
8705 if choice == 1
8706 " Yes -- write file & then browse
8707 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008708 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008709 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008710 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008711 exe origwin."wincmd w"
8712 let &ei = eikeep
8713 let @@ = ykeep
8714" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008715 return choice
8716 endif
8717
8718 elseif choice == 2
8719 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008720" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008721 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008722
8723 else
8724 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008725" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008726 exe origwin."wincmd w"
8727 let &ei= eikeep
8728 let @@ = ykeep
8729" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008730 return choice
8731 endif
8732 endif
8733 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008734 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008735 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008736" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008737
8738 " restore b:netrw_curdir (window split/enew may have lost it)
8739 let b:netrw_curdir= curdir
8740 if a:islocal < 2
8741 if a:islocal
8742 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8743 else
8744 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8745 endif
8746 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008747 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008748" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008749 return choice
8750endfun
8751
8752" ---------------------------------------------------------------------
8753" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8754" Always assumed to be local -> remote
8755" call s:NetrwUpload(filename, target)
8756" call s:NetrwUpload(filename, target, fromdirectory)
8757fun! s:NetrwUpload(fname,tgt,...)
8758" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8759
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008760 if a:tgt =~ '^\a\{3,}://'
8761 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008762 else
8763 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8764 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008765" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008766
8767 if a:0 > 0
8768 let fromdir= a:1
8769 else
8770 let fromdir= getcwd()
8771 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008772" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008773
8774 if type(a:fname) == 1
8775 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008776" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008777 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008778" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8779 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8780" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008781 if a:tgt =~ '/$'
8782 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008784 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008785 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008786" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008787 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008788" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008789 endif
8790 q!
8791
8792 elseif type(a:fname) == 3
8793 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008794" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008795 let curdir= getcwd()
8796 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008797 if s:NetrwLcd(fromdir)
8798" call Dret("s:NetrwUpload : lcd failure")
8799 return
8800 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008801 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008802 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008803 if exists("g:netrw_port") && g:netrw_port != ""
8804 let useport= " ".g:netrw_scpport." ".g:netrw_port
8805 else
8806 let useport= ""
8807 endif
8808 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8809 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008810 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 +02008811 if s:NetrwLcd(curdir)
8812" call Dret("s:NetrwUpload : lcd failure")
8813 return
8814 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008815
8816 elseif a:tgt =~ '^ftp:'
8817 call s:NetrwMethod(a:tgt)
8818
8819 if b:netrw_method == 2
8820 " handle uploading a list of files via ftp+.netrc
8821 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008822 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008823" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008825 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008826" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008827
8828 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008829 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008830" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008831 endif
8832
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008833 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008834" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008835
Bram Moolenaaradc21822011-04-01 18:03:16 +02008836 if tgtdir == ""
8837 let tgtdir= '/'
8838 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008839 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008840" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008841
8842 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008843 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8844" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008845 endfor
8846
8847 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008848 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 +00008849 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008850" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8851 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008852 endif
8853 " 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 +01008854 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008855 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8857 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8858 else
8859 bw!|q
8860 endif
8861
8862 elseif b:netrw_method == 3
8863 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8864 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008865 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008866 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008867 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008868
8869 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008870 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008871" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008872 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008873 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008874" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008875 endif
8876
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008877 if exists("g:netrw_uid") && g:netrw_uid != ""
8878 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008879 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008880" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008881 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008882 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008883 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008884" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008885 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008886 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008887" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008888 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008889 endif
8890
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008891 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008892" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008893
8894 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008895 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008896" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008897 endif
8898
8899 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008900 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008901" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008902 endif
8903
8904 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008905 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008906" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008907 endfor
8908
8909 " perform ftp:
8910 " -i : turns off interactive prompting from ftp
8911 " -n unix : DON'T use <.netrc>, even though it exists
8912 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008913 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008914 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008915 " 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 +01008916 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008917 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008918 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8919 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008920 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008921 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8922 let &debug = debugkeep
8923 let mod = 1
8924 else
8925 bw!|q
8926 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008927 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008928" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008929 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008930 endif
8931 else
8932 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8933 endif
8934 endif
8935
8936" call Dret("s:NetrwUpload")
8937endfun
8938
8939" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008940" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008941fun! s:NetrwPreview(path) range
8942" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008943" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8944" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008945 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008946 NetrwKeepj call s:NetrwOptionsSave("s:")
8947 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8948 NetrwKeepj call s:NetrwOptionsSafe(1)
8949 else
8950 NetrwKeepj call s:NetrwOptionsSafe(0)
8951 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008952 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008953" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008954 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008955" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8956 if g:netrw_preview
8957 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008958 let pvhkeep = &pvh
8959 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8960 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008961" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8962 else
8963 " horizontal split
8964 let pvhkeep = &pvh
8965 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8966 let &pvh = winheight(0) - winsz
8967" 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 +02008968 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008969 " g:netrw_preview g:netrw_alto
8970 " 1 : vert 1: top -- preview window is vertically split off and on the left
8971 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8972 " 0 : 1: top -- preview window is horizontally split off and on the top
8973 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8974 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008975 " 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 +02008976 " the BufEnter event set up in netrwPlugin.vim
8977" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8978 let eikeep = &ei
8979 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008980 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008981 let &ei= eikeep
8982" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008983 if exists("pvhkeep")
8984 let &pvh= pvhkeep
8985 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008986 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008987 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008988 endif
8989 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008990 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 +00008991 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008992 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008993 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008994" call Dret("NetrwPreview")
8995endfun
8996
8997" ---------------------------------------------------------------------
8998" s:NetrwRefresh: {{{2
8999fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009000" 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 +00009001 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009002 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009003" call Decho("setl ma noro",'~'.expand("<slnum>"))
9004" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009005 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009006 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9007 if !exists("w:netrw_treetop")
9008 if exists("b:netrw_curdir")
9009 let w:netrw_treetop= b:netrw_curdir
9010 else
9011 let w:netrw_treetop= getcwd()
9012 endif
9013 endif
9014 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9015 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009016
9017 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009018 let screenposn = winsaveview()
9019" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009020
9021" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9022" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9023 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009024 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009025 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009026 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009027 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009028 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009029
9030 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009031" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9032 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009033
9034 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009035 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9036 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9037" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9038 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9039 else
9040" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9041 2match none
9042 endif
9043 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009044
Bram Moolenaar97d62492012-11-15 21:28:22 +01009045" restore
9046 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009047" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009048endfun
9049
9050" ---------------------------------------------------------------------
9051" s:NetrwRefreshDir: refreshes a directory by name {{{2
9052" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009053" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009055" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009056 if g:netrw_fastbrowse == 0
9057 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009058" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009059 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009060" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009061
9062 if tgtwin > 0
9063 " tgtwin is being displayed, so refresh it
9064 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009065" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009066 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009067 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009068 exe curwin."wincmd w"
9069
9070 elseif bufnr(a:dirname) > 0
9071 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009072" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9073 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074 endif
9075
9076 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009077" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009078 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079 endif
9080" call Dret("s:NetrwRefreshDir")
9081endfun
9082
9083" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009084" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9085" window number to do its editing in.
9086" Supports [count]C where the count, if present, is used to specify
9087" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009088fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009089" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009090 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009091" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009092 if a:1 == "" " :NetrwC win#
9093 let g:netrw_chgwin= winnr()
9094 else " :NetrwC
9095 let g:netrw_chgwin= a:1
9096 endif
9097 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009098 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009099 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009100 let g:netrw_chgwin= winnr()
9101 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009102 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009103" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009104endfun
9105
9106" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009107" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9108" What this function does is to compute a priority for the patterns
9109" in the g:netrw_sort_sequence. It applies a substitute to any
9110" "files" that satisfy each pattern, putting the priority / in
9111" front. An "*" pattern handles the default priority.
9112fun! s:NetrwSetSort()
9113" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009114 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009115 if w:netrw_liststyle == s:LONGLIST
9116 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9117 else
9118 let seqlist = g:netrw_sort_sequence
9119 endif
9120 " sanity check -- insure that * appears somewhere
9121 if seqlist == ""
9122 let seqlist= '*'
9123 elseif seqlist !~ '\*'
9124 let seqlist= seqlist.',*'
9125 endif
9126 let priority = 1
9127 while seqlist != ""
9128 if seqlist =~ ','
9129 let seq = substitute(seqlist,',.*$','','e')
9130 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9131 else
9132 let seq = seqlist
9133 let seqlist = ""
9134 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009135 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009136 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009137 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009138 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009139 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009140 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009141 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009142" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009143
9144 " sanity check
9145 if w:netrw_bannercnt > line("$")
9146 " apparently no files were left after a Hiding pattern was used
9147" call Dret("SetSort : no files left after hiding")
9148 return
9149 endif
9150 if seq == '*'
9151 let starpriority= spriority
9152 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009153 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009154 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009155 " sometimes multiple sorting patterns will match the same file or directory.
9156 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009157 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9158 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009159 endif
9160 let priority = priority + 1
9161 endwhile
9162 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009163 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9164 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165 endif
9166
9167 " Following line associated with priority -- items that satisfy a priority
9168 " pattern get prefixed by ###/ which permits easy sorting by priority.
9169 " Sometimes files can satisfy multiple priority patterns -- only the latest
9170 " priority pattern needs to be retained. So, at this point, these excess
9171 " priority prefixes need to be removed, but not directories that happen to
9172 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009173 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9174 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009175 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009176
9177" call Dret("SetSort")
9178endfun
9179
Bram Moolenaarff034192013-04-24 18:51:19 +02009180" ---------------------------------------------------------------------
9181" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9182" Implements [count]Tb (bookhist<b>)
9183" [count]Th (bookhist<h>)
9184" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009185fun! s:NetrwSetTgt(islocal,bookhist,choice)
9186" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009187
9188 if a:bookhist == 'b'
9189 " supports choosing a bookmark as a target using a qb-generated list
9190 let choice= a:choice - 1
9191 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009192 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009193 else
9194 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9195 endif
9196
9197 elseif a:bookhist == 'h'
9198 " supports choosing a history stack entry as a target using a qb-generated list
9199 let choice= (a:choice % g:netrw_dirhistmax) + 1
9200 if exists("g:netrw_dirhist_".choice)
9201 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009202 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009203 else
9204 echomsg "Sorry, history#".a:choice." not available!"
9205 endif
9206 endif
9207
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009208 " refresh the display
9209 if !exists("b:netrw_curdir")
9210 let b:netrw_curdir= getcwd()
9211 endif
9212 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9213
Bram Moolenaarff034192013-04-24 18:51:19 +02009214" call Dret("s:NetrwSetTgt")
9215endfun
9216
Bram Moolenaar446cb832008-06-24 21:56:24 +00009217" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009218" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009219fun! s:NetrwSortStyle(islocal)
9220" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009221 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009222 let svpos= winsaveview()
9223" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009224
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009225 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 +01009226 NetrwKeepj norm! 0
9227 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009228" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9229 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009230
9231" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9232endfun
9233
9234" ---------------------------------------------------------------------
9235" s:NetrwSplit: mode {{{2
9236" =0 : net and o
9237" =1 : net and t
9238" =2 : net and v
9239" =3 : local and o
9240" =4 : local and t
9241" =5 : local and v
9242fun! s:NetrwSplit(mode)
9243" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9244
Bram Moolenaar97d62492012-11-15 21:28:22 +01009245 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009246 call s:SaveWinVars()
9247
9248 if a:mode == 0
9249 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009250 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009251 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009252" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009253 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009254 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009255 NetrwKeepj call s:RestoreWinVars()
9256 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009257 unlet s:didsplit
9258
9259 elseif a:mode == 1
9260 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009261 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009262" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009263 tabnew
9264 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009265 NetrwKeepj call s:RestoreWinVars()
9266 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 unlet s:didsplit
9268
9269 elseif a:mode == 2
9270 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009271 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009272 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009273" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009274 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009275 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009276 NetrwKeepj call s:RestoreWinVars()
9277 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278 unlet s:didsplit
9279
9280 elseif a:mode == 3
9281 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009282 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009283 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009284" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009285 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009287 NetrwKeepj call s:RestoreWinVars()
9288 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009289 unlet s:didsplit
9290
9291 elseif a:mode == 4
9292 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009293 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009294 let eikeep = &ei
9295 let netrw_winnr = winnr()
9296 let netrw_line = line(".")
9297 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009298 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009299 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009300 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009301 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9302 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009303 let &ei = eikeep
9304 let netrw_curdir = s:NetrwTreeDir(0)
9305" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009306 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009307 let b:netrw_curdir = netrw_curdir
9308 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009309 NetrwKeepj call s:RestoreWinVars()
9310 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009311 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009312 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009313 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9314 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009315 let &ei= eikeep
9316 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009317 unlet s:didsplit
9318
9319 elseif a:mode == 5
9320 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009321 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009322 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009323" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009324 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009325 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009326 NetrwKeepj call s:RestoreWinVars()
9327 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009328 unlet s:didsplit
9329
9330 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009331 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009332 endif
9333
Bram Moolenaar97d62492012-11-15 21:28:22 +01009334 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009335" call Dret("s:NetrwSplit")
9336endfun
9337
9338" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009339" s:NetrwTgtMenu: {{{2
9340fun! s:NetrwTgtMenu()
9341 if !exists("s:netrw_menucnt")
9342 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009343 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009344" call Dfunc("s:NetrwTgtMenu()")
9345
9346 " the following test assures that gvim is running, has menus available, and has menus enabled.
9347 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9348 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009349" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009350 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9351 endif
9352 if !exists("s:netrw_initbookhist")
9353 call s:NetrwBookHistRead()
9354 endif
9355
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009356 " try to cull duplicate entries
9357 let tgtdict={}
9358
Bram Moolenaarff034192013-04-24 18:51:19 +02009359 " target bookmarked places
9360 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009361" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009362 let cnt= 1
9363 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009364 if has_key(tgtdict,bmd)
9365 let cnt= cnt + 1
9366 continue
9367 endif
9368 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009369 let ebmd= escape(bmd,g:netrw_menu_escape)
9370 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009371" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009372 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 +02009373 let cnt= cnt + 1
9374 endfor
9375 endif
9376
9377 " target directory browsing history
9378 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009379" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009380 let histcnt = 1
9381 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009382 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009383 if exists("g:netrw_dirhist_{histcnt}")
9384 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385 if has_key(tgtdict,histentry)
9386 let histcnt = histcnt + 1
9387 continue
9388 endif
9389 let tgtdict[histentry] = histcnt
9390 let ehistentry = escape(histentry,g:netrw_menu_escape)
9391" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009392 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 +02009393 endif
9394 let histcnt = histcnt + 1
9395 endwhile
9396 endif
9397 endif
9398" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009399endfun
9400
9401" ---------------------------------------------------------------------
9402" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9403" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009404fun! s:NetrwTreeDir(islocal)
9405" 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 +02009406" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009407" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9408" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9409" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009410" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009411
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009412 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009413 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009414" 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 +01009415 let treedir= s:treedir
9416 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009417 unlet s:prevwinopen
9418" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009419 return treedir
9420 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009421 if exists("s:prevwinopen")
9422 unlet s:prevwinopen
9423 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009424" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009425
Bram Moolenaar8d043172014-01-23 14:24:41 +01009426 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9427 let b:netrw_curdir= getcwd()
9428 endif
9429 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009430" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009431" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009432
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009433 let s:treecurpos= winsaveview()
9434" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009435" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009436
9437 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009438" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9439" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009440" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009441
9442 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009443 let curline= substitute(getline('.'),"\t -->.*$",'','')
9444 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009445" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009446 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009447" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9448 elseif curline =~ '@$'
9449" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009450 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009451" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009452 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009453" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009454 let treedir= ""
9455 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009456" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009457
9458 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009459" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9460" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009461" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009462 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009463" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009464 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009465" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9466 sil! NetrwKeepj %d _
9467" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009468 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009469" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009470" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009471 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009472" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009473
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009474" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009475" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009476" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009477
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009478 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9479" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9480" let newdir = w:netrw_treetop.'/'.potentialdir
9481" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9482" let treedir = s:NetrwTreePath(newdir)
9483" let w:netrw_treetop = newdir
9484" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9485" else
9486" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009487 if a:islocal && curline =~ '@$'
9488 if isdirectory(s:NetrwFile(potentialdir))
9489 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9490 let w:netrw_treetop = treedir
9491 endif
9492 else
9493 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9494 let treedir = s:NetrwTreePath(w:netrw_treetop)
9495 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009496 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009497" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009498
9499 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009501" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009502" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009503
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009504" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009505 return treedir
9506endfun
9507
9508" ---------------------------------------------------------------------
9509" s:NetrwTreeDisplay: recursive tree display {{{2
9510fun! s:NetrwTreeDisplay(dir,depth)
9511" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9512
9513 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009514 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009515
9516 " install ../ and shortdir
9517 if a:depth == ""
9518 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009519" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009520 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009521 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009522 if a:dir == w:netrw_treetop
9523 let shortdir= a:dir
9524 else
9525 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9526 endif
9527 call setline(line("$")+1,a:depth.shortdir)
9528 else
9529 let shortdir= substitute(a:dir,'^.*/','','e')
9530 call setline(line("$")+1,a:depth.shortdir.'/')
9531 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009532" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009533 " append a / to dir if its missing one
9534 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009535
9536 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009537 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009538" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009539
Bram Moolenaar85850f32019-07-19 22:05:51 +02009540 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9541 if g:netrw_hide == 1
9542 " hide given patterns
9543 let listhide= split(g:netrw_list_hide,',')
9544" call Decho("listhide=".string(listhide))
9545 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009546 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009547 endfor
9548
9549 elseif g:netrw_hide == 2
9550 " show given patterns (only)
9551 let listhide= split(g:netrw_list_hide,',')
9552" call Decho("listhide=".string(listhide))
9553 let entries=[]
9554 for entry in w:netrw_treedict[dir]
9555 for pat in listhide
9556 if entry =~ pat
9557 call add(entries,entry)
9558 break
9559 endif
9560 endfor
9561 endfor
9562 let w:netrw_treedict[dir]= entries
9563 endif
9564 if depth != ""
9565 " always remove "." and ".." entries when there's depth
9566 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9567 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9568 endif
9569
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009570" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009571 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009572 if dir =~ '/$'
9573 let direntry= substitute(dir.entry,'[@/]$','','e')
9574 else
9575 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9576 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009577" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009579" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009580 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009581 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009582" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9583 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9584 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9585" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009586 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009587 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009588" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009589 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009590 endif
9591 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009592" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009593
Bram Moolenaar446cb832008-06-24 21:56:24 +00009594" call Dret("NetrwTreeDisplay")
9595endfun
9596
9597" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009598" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9599fun! s:NetrwRefreshTreeDict(dir)
9600" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009601 if !exists("w:netrw_treedict")
9602" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9603 return
9604 endif
9605
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009606 for entry in w:netrw_treedict[a:dir]
9607 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9608" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9609
9610 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9611" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9612 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009613 let liststar = s:NetrwGlob(direntry,'*',1)
9614 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009615 let w:netrw_treedict[direntry] = liststar + listdotstar
9616" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9617
9618 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9619" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9620 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009621 let liststar = s:NetrwGlob(direntry.'/','*',1)
9622 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009623 let w:netrw_treedict[direntry]= liststar + listdotstar
9624" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9625
9626 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9627" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9628 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009629 let liststar = s:NetrwGlob(direntry.'/','*',1)
9630 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009631" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9632
9633 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009634" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009635 endif
9636 endfor
9637" call Dret("s:NetrwRefreshTreeDict")
9638endfun
9639
9640" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009641" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009642" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009643fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009644 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009645" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009646" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9647" 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>"))
9648" 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 +00009649
9650 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009651 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009652" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009653 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009654 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009655" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009656 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 +02009657" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009659 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009660" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009661 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009662 if exists("w:netrw_treetop")
9663 let s:netrw_treetop= w:netrw_treetop
9664 else
9665 let w:netrw_treetop= getcwd()
9666 let s:netrw_treetop= w:netrw_treetop
9667 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009668
Bram Moolenaar446cb832008-06-24 21:56:24 +00009669 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009670 " insure that we have a treedict, albeit empty
9671" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009672 let w:netrw_treedict= {}
9673 endif
9674
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009675 " update the dictionary for the current directory
9676" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009677" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009678 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009680" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009681 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009682
9683 " if past banner, record word
9684 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9685 let fname= expand("<cword>")
9686 else
9687 let fname= ""
9688 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009689" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9690" 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 +00009691
9692 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009693" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009694 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009695" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009696
9697 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9698 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009699" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009700 1d
9701 endwhile
9702
Bram Moolenaar13600302014-05-22 18:26:40 +02009703 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009704
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009705" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009706 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009707 endif
9708endfun
9709
9710" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009711" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009712" Normally, treetop is w:netrw_treetop, but a
9713" user of the function ( netrw#SetTreetop() )
9714" wipes that out prior to calling this function
9715fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009716" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9717 if line(".") < w:netrw_bannercnt + 2
9718 let treedir= a:treetop
9719 if treedir !~ '/$'
9720 let treedir= treedir.'/'
9721 endif
9722" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9723 return treedir
9724 endif
9725
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009726 let svpos = winsaveview()
9727" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009728 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009729" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009730 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009731" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9732 let curline= getline('.')
9733" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9734 if curline =~ '/$'
9735" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9736 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9737" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9738 elseif curline =~ '@\s\+-->'
9739" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9740 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9741 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9742" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009743 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009744" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009745 let treedir= ""
9746 endif
9747 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009748" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9749" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009750 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9751 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9752 let treedir= dirname.treedir
9753 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009754" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009755 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009756" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009757 if a:treetop =~ '/$'
9758 let treedir= a:treetop.treedir
9759 else
9760 let treedir= a:treetop.'/'.treedir
9761 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009762" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009763 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009764" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009765" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9766 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009767" call Dret("s:NetrwTreePath <".treedir.">")
9768 return treedir
9769endfun
9770
9771" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009772" s:NetrwWideListing: {{{2
9773fun! s:NetrwWideListing()
9774
9775 if w:netrw_liststyle == s:WIDELIST
9776" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9777 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009778 " cpf: characters per filename
9779 " fpl: filenames per line
9780 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009781 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009782 let dict={}
9783 " save the unnamed register and register 0-9 and a
9784 let dict.a=[getreg('a'), getregtype('a')]
9785 for i in range(0, 9)
9786 let dict[i] = [getreg(i), getregtype(i)]
9787 endfor
9788 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009789" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009790 let b:netrw_cpf= 0
9791 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009792 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009793 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9794 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009796 " restore stored registers
9797 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009798" call Dret("NetrwWideListing")
9799 return
9800 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009801 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009802 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009803" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009804
9805 " determine qty files per line (fpl)
9806 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9807 if w:netrw_fpl <= 0
9808 let w:netrw_fpl= 1
9809 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009810" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009811
9812 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009813 " fpc: files per column of wide listing
9814 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009815 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009816 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9817 let newcolstart = w:netrw_bannercnt + fpc
9818 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009819" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009820 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009821" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009822 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009823 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009824 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009825 while line("$") >= newcolstart
9826 if newcolend > line("$") | let newcolend= line("$") | endif
9827 let newcolqty= newcolend - newcolstart
9828 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009829 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009830 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009831 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009832 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009833 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009834 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009835 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009836 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009837 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009838 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009839" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009840 if @* != keepregstar | sil! let @* = keepregstar | endif
9841 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009842 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009843 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9844 NetrwKeepj call histdel("/",-1)
9845 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9846 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009847" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009848 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009849 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009850" 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 +00009851" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009852 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009853 else
9854 if hasmapto("w","n")
9855 sil! nunmap <buffer> w
9856 endif
9857 if hasmapto("b","n")
9858 sil! nunmap <buffer> b
9859 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009860 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009861endfun
9862
9863" ---------------------------------------------------------------------
9864" s:PerformListing: {{{2
9865fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009866" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9867" 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 +02009868" 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>"))
9869 sil! NetrwKeepj %d _
9870" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009871
Bram Moolenaar15146672011-10-20 22:22:38 +02009872 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009873" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009874 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009875
Bram Moolenaar85850f32019-07-19 22:05:51 +02009876 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009877 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009878" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009879
9880" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009881" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009882" endif " Decho
9883
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009884" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009885 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9886 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009887" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9888 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009889 endif
9890
9891 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009892 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009893
9894 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009895 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009896" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009897 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009898 if exists("g:netrw_pchk")
9899 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9900 " failure detections.
9901 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009902 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009903 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9904 endif
9905 if exists("g:netrw_pchk")
9906 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9907 else
9908 let curdir= b:netrw_curdir
9909 endif
9910 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9911 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9912 else
9913 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009914 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009915 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009916 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009917 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009918" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009919 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009920 let w:netrw_bannercnt= 1
9921 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009922" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9923" 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 +00009924
Bram Moolenaar85850f32019-07-19 22:05:51 +02009925 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009926 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009927 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009928 let sortby= sortby." reversed"
9929 endif
9930
9931 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009932 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009933" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009934 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009935" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009936 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009937 NetrwKeepj put ='\" Sorted by '.sortby
9938 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009939 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9940 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009941" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009942 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009943 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009944 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9945 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009946 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009947" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009948" 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 +00009949 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009950
Bram Moolenaar85850f32019-07-19 22:05:51 +02009951 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009952 if g:netrw_banner
9953 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009954" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009955 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009956 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009957 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009958 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009959 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009960 endif
9961 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009962 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009963" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009964 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009965 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009966 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009967
9968 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009969 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009970" 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 +01009971 if g:netrw_list_hide != "" && g:netrw_hide
9972 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009973 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009974 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009975 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009976 endif
9977 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009978 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009979 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009980
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009981" 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 +01009982 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009983" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009984 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009985" 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 +01009986 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009987 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009988" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009989" 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 +00009990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009991
9992 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009993 if g:netrw_banner
9994 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009995 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" 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 +01009997" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" 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 +01009999 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010000
Bram Moolenaar446cb832008-06-24 21:56:24 +000010001 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010002" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010003 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010004 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010005 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010006 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010007 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010008" 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 +010010009" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10010 return
10011 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010012 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010013
10014 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010015 if !exists("w:netrw_bannercnt")
10016 let w:netrw_bannercnt= 0
10017 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010018" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10019" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10020" 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 +010010021
Bram Moolenaar5c736222010-01-06 20:54:52 +010010022 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010023" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010024" 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 +000010025 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010026 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010027 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010028 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010029" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010030
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010031 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010033" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010034 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010035
Bram Moolenaar5c736222010-01-06 20:54:52 +010010036 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010037" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010038 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010039 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010040 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010041 else
10042 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010043 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010044 endif
10045 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010046
Bram Moolenaar446cb832008-06-24 21:56:24 +000010047 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010048" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010049 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10050 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010051
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010052 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010053 " exten: sort by extension
10054 " The histdel(...,-1) calls remove the last search from the search history
10055" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010056 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10057 NetrwKeepj call histdel("/",-1)
10058 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10059 NetrwKeepj call histdel("/",-1)
10060 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10061 NetrwKeepj call histdel("/",-1)
10062 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10063" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010064 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010065 " normal direction sorting
10066 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10067 else
10068 " reverse direction sorting
10069 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10070 endif
10071 endif
10072 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10073 NetrwKeepj call histdel("/",-1)
10074
Bram Moolenaar446cb832008-06-24 21:56:24 +000010075 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010076 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010077" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010078 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010079" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010080 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010081 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010082" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010083 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010084 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010085" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010086 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10087 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010088 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010089 endif
10090
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010091 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010092" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010093 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010094 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010095 call histdel("/",-1)
10096 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010097 endif
10098 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010099" 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 +000010100
10101 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010102" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10103" 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 +010010104 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010105" 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 +010010106 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010107" 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 +000010108
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010109 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010110 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010111" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010112 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010113 endif
10114
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010115 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010116 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010117" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10118 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010119 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10121 else
10122" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10123" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10124" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10125" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010126 endif
10127
10128 " record previous current directory
10129 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010130" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010131
10132 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010133" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10134" 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 +010010135 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010136" 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 +020010137 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010138" 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 +000010139
10140 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010141" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010142 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010143" 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 +010010144 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010145" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010146 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10147 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010148" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010149" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010150
Bram Moolenaar8d043172014-01-23 14:24:41 +010010151 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010152" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10153" 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 +010010154" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10155 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010156 unlet s:treecurpos
10157 endif
10158
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010159" 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>"))
10160" 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 +000010161" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10162endfun
10163
10164" ---------------------------------------------------------------------
10165" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010166fun! s:SetupNetrwStatusLine(statline)
10167" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10168
10169 if !exists("s:netrw_setup_statline")
10170 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010171" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010172
10173 if !exists("s:netrw_users_stl")
10174 let s:netrw_users_stl= &stl
10175 endif
10176 if !exists("s:netrw_users_ls")
10177 let s:netrw_users_ls= &laststatus
10178 endif
10179
10180 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010181 let dict={}
10182 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010183 redir @a
10184 try
10185 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010186 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010187 if &bg == "dark"
10188 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10189 else
10190 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10191 endif
10192 endtry
10193 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010194 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010195 endif
10196
10197 " set up status line (may use User9 highlighting)
10198 " insure that windows have a statusline
10199 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010200 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010201 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010202" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010203 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010204
10205" call Dret("SetupNetrwStatusLine : stl=".&stl)
10206endfun
10207
Bram Moolenaar85850f32019-07-19 22:05:51 +020010208" =========================================
10209" Remote Directory Browsing Support: {{{1
10210" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010211
10212" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010213" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10214" This function assumes that a long listing will be received. Size, time,
10215" and reverse sorts will be requested of the server but not otherwise
10216" enforced here.
10217fun! s:NetrwRemoteFtpCmd(path,listcmd)
10218" 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 +010010219" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010220 " sanity check: {{{3
10221 if !exists("w:netrw_method")
10222 if exists("b:netrw_method")
10223 let w:netrw_method= b:netrw_method
10224 else
10225 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10226" call Dret("NetrwRemoteFtpCmd")
10227 return
10228 endif
10229 endif
10230
10231 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10232 let ffkeep= &ff
10233 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010234" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010235
10236 " clear off any older non-banner lines " {{{3
10237 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010238" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10239 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010240
10241 ".........................................
10242 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10243 " ftp + <.netrc>: Method #2
10244 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010245 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010246 endif
10247 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010248 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010249" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010250 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010251 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010252" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010253 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010254" 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>"))
10255 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 +010010256 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010257" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10258 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 +010010259 endif
10260
10261 ".........................................
10262 elseif w:netrw_method == 3 " {{{3
10263 " ftp + machine,id,passwd,filename: Method #3
10264 setl ff=unix
10265 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010266 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010267 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010268 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010269 endif
10270
10271 " handle userid and password
10272 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010273" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010274 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10275 call NetUserPass("ftp:".host)
10276 endif
10277 if exists("g:netrw_uid") && g:netrw_uid != ""
10278 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010279 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010280 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010281 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010282 endif
10283 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010284 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010285 endif
10286 endif
10287
10288 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010289 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010290 endif
10291 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010292 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010293" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010294 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010295 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010296
10297 " perform ftp:
10298 " -i : turns off interactive prompting from ftp
10299 " -n unix : DON'T use <.netrc>, even though it exists
10300 " -n win32: quit being obnoxious about password
10301 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010302" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010303 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010304" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010305" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10306" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010307 endif
10308
10309 ".........................................
10310 elseif w:netrw_method == 9 " {{{3
10311 " sftp username@machine: Method #9
10312 " s:netrw_sftp_cmd
10313 setl ff=unix
10314
10315 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010316 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010317" call Dret("NetrwRemoteFtpCmd")
10318 return
10319
10320 ".........................................
10321 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010322 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010323 endif
10324
10325 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010326 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010327 sil! NetrwKeepj %s/\r$//e
10328 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010329 endif
10330 if a:listcmd == "dir"
10331 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010332 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10333 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10334 NetrwKeepj call histdel("/",-1)
10335 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010336 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 +010010337 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10338 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010339 endif
10340 endif
10341
10342 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10343 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010344 exe 'NetrwKeepj '.w:netrw_bannercnt
10345 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010346 endif
10347 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010348 exe 'NetrwKeepj '.w:netrw_bannercnt
10349 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010350 endif
10351
10352 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010353 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010354" call Dret("NetrwRemoteFtpCmd")
10355endfun
10356
10357" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010358" s:NetrwRemoteListing: {{{2
10359fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010360" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010361
Bram Moolenaara6878372014-03-22 21:02:50 +010010362 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10363 let w:netrw_bannercnt= s:bannercnt
10364 endif
10365 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010366 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010367 endif
10368
Bram Moolenaar446cb832008-06-24 21:56:24 +000010369 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010370
Bram Moolenaar446cb832008-06-24 21:56:24 +000010371 " sanity check:
10372 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010373" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010374 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010375" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010376 if !exists("g:netrw_quiet")
10377 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10378 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010379 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010380" call Dret("s:NetrwRemoteListing -1")
10381 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010382 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010383
Bram Moolenaar8d043172014-01-23 14:24:41 +010010384 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010385" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010386 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010387 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010388 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 +000010389 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010390 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 +000010391 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010392 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010393
Bram Moolenaar85850f32019-07-19 22:05:51 +020010394 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010395" call Dret("s:NetrwRemoteListing -1")
10396 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010398" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010399
Bram Moolenaar446cb832008-06-24 21:56:24 +000010400 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010401" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010402 let w:netrw_method= b:netrw_method
10403 endif
10404
Bram Moolenaar13600302014-05-22 18:26:40 +020010405 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010406 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010407" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010408 let s:method = "ftp"
10409 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010410 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010411 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010412 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010413 let listcmd= g:netrw_ftp_sizelist_cmd
10414 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010415" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010416 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010417" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010418
Bram Moolenaara6878372014-03-22 21:02:50 +010010419 " report on missing file or directory messages
10420 if search('[Nn]o such file or directory\|Failed to change directory')
10421 let mesg= getline(".")
10422 if exists("w:netrw_bannercnt")
10423 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010424 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010425 setl noma
10426 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010427 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010428 call netrw#ErrorMsg(s:WARNING,mesg,96)
10429" call Dret("s:NetrwRemoteListing : -1")
10430 return -1
10431 endif
10432
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010433 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 +000010434 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010435" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010436 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010437
10438 " cleanup
10439 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010440 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10441 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010442 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010443 sil! NetrwKeepj %s/\r$//e
10444 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010445
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010446 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010448 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010449 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010450" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010451 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010452" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010453 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010454 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010455 exe "sil! NetrwKeepj ".line1
10456 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010457
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010458" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010459 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010460" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010461 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10462 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010463 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010464" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010465 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10466 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10467 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10468 NetrwKeepj call histdel("/",-1)
10469 NetrwKeepj call histdel("/",-1)
10470 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010471 endif
10472 endif
10473
Bram Moolenaar13600302014-05-22 18:26:40 +020010474 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010475 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010476" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010477 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010478" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010480" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10481 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010482 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010483 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10484 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10485 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10486 NetrwKeepj call histdel("/",-1)
10487 NetrwKeepj call histdel("/",-1)
10488 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010490 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10491 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010492 endif
10493 else
10494 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010495" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010496 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010498" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10499 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10500" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010501 endif
10502 endif
10503
10504 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010505 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010506" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010507 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10508 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010509 endif
10510 endif
10511
10512 if w:netrw_liststyle == s:LONGLIST
10513 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010514" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010515
10516 if s:method == "ftp"
10517 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010518 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010519 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010520 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010521 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010522 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010524 sil! NetrwKeepj 1
10525 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010526 let line2= line(".")
10527 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010528 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010529 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010530 endif
10531 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010532 exe "sil! NetrwKeepj ".line1
10533 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010534 endif
10535
10536 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010537" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010538 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 +000010539 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010540" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010541 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010542 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010543 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10544 NetrwKeepj call histdel("/",-1)
10545 NetrwKeepj call histdel("/",-1)
10546 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010547 endif
10548 endif
10549
10550" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010551" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010552" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010553
10554" call Dret("s:NetrwRemoteListing 0")
10555 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010556endfun
10557
Bram Moolenaar446cb832008-06-24 21:56:24 +000010558" ---------------------------------------------------------------------
10559" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10560fun! s:NetrwRemoteRm(usrhost,path) range
10561" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010562" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010563 let svpos= winsaveview()
10564" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010565
10566 let all= 0
10567 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10568 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010569" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570 for fname in s:netrwmarkfilelist_{bufnr("%")}
10571 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010572 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010574 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575 let all= 1
10576 endif
10577 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010578 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010579
10580 else
10581 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010582" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010583
10584 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010585 let keepsol = &l:sol
10586 setl nosol
10587 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010588
10589 " remove multiple files and directories
10590 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010591 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010592 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010593 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010594 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010595 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596 let all= 1
10597 endif
10598 let ctr= ctr + 1
10599 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010600 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601 endif
10602
10603 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010604" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010605 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010606" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10607 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010608
10609" call Dret("s:NetrwRemoteRm")
10610endfun
10611
10612" ---------------------------------------------------------------------
10613" s:NetrwRemoteRmFile: {{{2
10614fun! s:NetrwRemoteRmFile(path,rmfile,all)
10615" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10616
10617 let all= a:all
10618 let ok = ""
10619
10620 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10621 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010622" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010623 if !all
10624 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010625" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010626 call inputsave()
10627 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10628 call inputrestore()
10629 echohl NONE
10630 if ok == ""
10631 let ok="no"
10632 endif
10633 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010634 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010635 let all= 1
10636 endif
10637 endif
10638
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010639 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010640" 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 +000010641 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010642" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010643 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010644 if path =~ '^\a\{3,}://'
10645 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010646 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010647 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010648 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10649 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010650" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010651 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010652" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010653 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010654 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010655 let ok="q"
10656 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010657 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010658" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10659" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10660" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010661 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010662 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010663 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010664 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010665 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010666" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010667 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668 if v:shell_error != 0
10669 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010670 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 +010010671 else
10672 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10673 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010674 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010675 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010676 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010677" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010678 endif
10679 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010680 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010681" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010682 endif
10683
10684 else
10685 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010686" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010687 if !all
10688 call inputsave()
10689 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10690 call inputrestore()
10691 if ok == ""
10692 let ok="no"
10693 endif
10694 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010695 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010696 let all= 1
10697 endif
10698 endif
10699
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010700 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010701 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010702 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010703 else
10704 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010705 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10706" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010707 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010708" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010709
10710 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010711" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10712 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10713" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010714 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010715" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010716
10717 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010718 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010719 endif
10720 endif
10721 endif
10722
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010723 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010724" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010725 endif
10726 endif
10727
10728" call Dret("s:NetrwRemoteRmFile ".ok)
10729 return ok
10730endfun
10731
10732" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010733" s:NetrwRemoteRename: rename a remote file or directory {{{2
10734fun! s:NetrwRemoteRename(usrhost,path) range
10735" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10736
10737 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010738 let svpos = winsaveview()
10739" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010740 let ctr = a:firstline
10741 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10742
10743 " rename files given by the markfilelist
10744 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10745 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010746" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010747 if exists("subfrom")
10748 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010749" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010750 else
10751 call inputsave()
10752 let newname= input("Moving ".oldname." to : ",oldname)
10753 call inputrestore()
10754 if newname =~ '^s/'
10755 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10756 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10757 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010758" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010759 endif
10760 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010761
Bram Moolenaar446cb832008-06-24 21:56:24 +000010762 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010763 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010764 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765 let oldname= s:ShellEscape(a:path.oldname)
10766 let newname= s:ShellEscape(a:path.newname)
10767" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010768 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010769 endif
10770
10771 endfor
10772 call s:NetrwUnMarkFile(1)
10773
10774 else
10775
10776 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010777 let keepsol= &l:sol
10778 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010779 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010780 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010781
10782 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010783" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010784
10785 call inputsave()
10786 let newname= input("Moving ".oldname." to : ",oldname)
10787 call inputrestore()
10788
10789 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10790 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10791 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010792 let oldname= s:ShellEscape(a:path.oldname)
10793 let newname= s:ShellEscape(a:path.newname)
10794" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010795 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010796 endif
10797
10798 let ctr= ctr + 1
10799 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010800 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010801 endif
10802
10803 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010804 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010805" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10806 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010807
10808" call Dret("NetrwRemoteRename")
10809endfun
10810
Bram Moolenaar85850f32019-07-19 22:05:51 +020010811" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010812" Local Directory Browsing Support: {{{1
10813" ==========================================
10814
10815" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010816" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010817" Should accept: file://localhost/etc/fstab
10818" file:///etc/fstab
10819" file:///c:/WINDOWS/clock.avi
10820" file:///c|/WINDOWS/clock.avi
10821" file://localhost/c:/WINDOWS/clock.avi
10822" file://localhost/c|/WINDOWS/clock.avi
10823" file://c:/foo.txt
10824" file:///c:/foo.txt
10825" 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 +020010826fun! netrw#FileUrlEdit(fname)
10827" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010828 let fname = a:fname
10829 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010830" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010831 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010832" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010833 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010834 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010835 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010836" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010837 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010838" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010839 endif
10840 endif
10841 let fname2396 = netrw#RFC2396(fname)
10842 let fname2396e= fnameescape(fname2396)
10843 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010844 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010845" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010846 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010847" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010848 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10849 endif
10850 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010851
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010852" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10853" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010854 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010855 exe 'NetrwKeepj keepalt edit '.plainfname
10856 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10857
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010858" 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 +020010859" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010860 exe "sil doau BufReadPost ".fname2396e
10861endfun
10862
10863" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010864" netrw#LocalBrowseCheck: {{{2
10865fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010866 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010867 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10868 "
10869 " unfortunate interaction -- split window debugging can't be used here, must use
10870 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10871 " another call to LocalBrowseCheck() when attempts to write
10872 " to the DBG buffer are made.
10873 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010874 " The &ft == "netrw" test was installed because the BufEnter event
10875 " would hit when re-entering netrw windows, creating unexpected
10876 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010877" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010878" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010879" 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 +010010880 " getting E930: Cannot use :redir inside execute
10881"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010882" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10883" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010884
Bram Moolenaar97d62492012-11-15 21:28:22 +010010885 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010886 if isdirectory(s:NetrwFile(a:dirname))
10887" 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 +010010888
Bram Moolenaar97d62492012-11-15 21:28:22 +010010889 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010890" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10891" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010892 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010893
Bram Moolenaar446cb832008-06-24 21:56:24 +000010894 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010895" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010896 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010897
Bram Moolenaar5c736222010-01-06 20:54:52 +010010898 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010899" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010900 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010901 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010902 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010903" 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 +010010904" call Dret("netrw#LocalBrowseCheck")
10905 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010906 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010907
Bram Moolenaar85850f32019-07-19 22:05:51 +020010908 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010909 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10910 " AND IF the listing style is not a tree listing
10911 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010912" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010913 let ibuf = 1
10914 let buflast = bufnr("$")
10915 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010916 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10917 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010918 endif
10919 let ibuf= ibuf + 1
10920 endwhile
10921 endif
10922 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010923" 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>"))
10924" 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 +000010925 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010926" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010927endfun
10928
10929" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010930" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010931" performed any shell command. The idea is to cause all local-browsing
10932" buffers to be refreshed after a user has executed some shell command,
10933" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010934fun! s:LocalBrowseRefresh()
10935" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010936" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10937" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010938
Bram Moolenaar446cb832008-06-24 21:56:24 +000010939 " determine which buffers currently reside in a tab
10940 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010941" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010942 return
10943 endif
10944 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010945" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010946 return
10947 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010948 if !empty(getcmdwintype())
10949 " cannot move away from cmdline window, see :h E11
10950 return
10951 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010952 if exists("s:netrw_events") && s:netrw_events == 1
10953 " s:LocalFastBrowser gets called (indirectly) from a
10954 let s:netrw_events= 2
10955" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10956 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010957 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010958 let itab = 1
10959 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010960 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010961 while itab <= tabpagenr("$")
10962 let buftablist = buftablist + tabpagebuflist()
10963 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010964 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010966" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10967" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010968 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10969 " | refresh any netrw window
10970 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010971 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010972 let ibl = 0
10973 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010974" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010975 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10976 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010977 " (ibuf not shown in a current window AND
10978 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010979" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10980 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010981 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010982" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010983 continue
10984 elseif index(tabpagebuflist(),ibuf) != -1
10985 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010986" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010987 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010988 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010989 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10990 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10991 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10992 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010993" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010994 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10995 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10996 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010997 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010998 endif
10999 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011000" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011001 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011002" call Decho("restore window: win_gotoid(".curwinid.")")
11003 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011004 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011005
Bram Moolenaara6878372014-03-22 21:02:50 +010011006" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011007endfun
11008
11009" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011010" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11011"
11012" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011013" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011014" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11015" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011016" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011017"
11018" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11019" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011020" (re-using a buffer may not be as accurate)
11021"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011022" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011023" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11024" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11025" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11026" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011027fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011028" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11029" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11030" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11031" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011032
11033 " initialize browselist, a list of buffer numbers that the local browser has used
11034 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011035" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011036 let s:netrw_browselist= []
11037 endif
11038
11039 " append current buffer to fastbrowse list
11040 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011041" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011042 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011043" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011044 endif
11045
11046 " enable autocmd events to handle refreshing/removing local browser buffers
11047 " If local browse buffer is currently showing: refresh it
11048 " If local browse buffer is currently hidden : wipe it
11049 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11050 " =1 : medium speed, re-use directory listing for remote only
11051 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011052 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11053 let s:netrw_events= 1
11054 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011055 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011056 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011057" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011058 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011059 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011060" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011061 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011062 endif
11063 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011064
11065 " user must have changed fastbrowse to its fast setting, so remove
11066 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011067 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011068" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011069 unlet s:netrw_events
11070 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011071 au!
11072 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011073 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011074 endif
11075
Bram Moolenaar85850f32019-07-19 22:05:51 +020011076" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011077endfun
11078
11079" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011080" s:LocalListing: does the job of "ls" for local directories {{{2
11081fun! s:LocalListing()
11082" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011083" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11084" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11085" 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 +010011086
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011087" 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
11088" 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
11089" 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 +010011090
11091 " get the list of files contained in the current directory
11092 let dirname = b:netrw_curdir
11093 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011094 let filelist = s:NetrwGlob(dirname,"*",0)
11095 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011096" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011097
Nir Lichtman1e34b952024-05-08 19:19:34 +020011098 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011099" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011100 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11101 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011102" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011103 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011104" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011105 endif
11106
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011107" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011108" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011109" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011110
11111 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11112 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11113 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011114" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11115" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011116 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011117" 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 +010011118
11119 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011120" call Decho(" ",'~'.expand("<slnum>"))
11121" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011122
11123 if getftype(filename) == "link"
11124 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011125" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011126 let pfile= filename."@"
11127
11128 elseif getftype(filename) == "socket"
11129 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011130" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011131 let pfile= filename."="
11132
11133 elseif getftype(filename) == "fifo"
11134 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011135" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011136 let pfile= filename."|"
11137
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011138 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011139 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011141 let pfile= filename."/"
11142
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011143 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011144 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011145 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11146 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011147" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011148 let pfile= filename."*"
11149 else
11150 " normal file
11151 let pfile= filename
11152 endif
11153 elseif executable(filename)
11154 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011155" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011156 let pfile= filename."*"
11157 else
11158 " normal file
11159 let pfile= filename
11160 endif
11161
11162 else
11163 " normal file
11164 let pfile= filename
11165 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011166" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011167
11168 if pfile =~ '//$'
11169 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011170" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011171 endif
11172 let pfile= strpart(pfile,dirnamelen)
11173 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011174" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11175" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011176
11177 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011178 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11179 let sz = getfsize(filename)
11180 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11181 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011182
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011183 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011184 let sz= s:NetrwHumanReadable(sz)
11185 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011186 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011187 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011188" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011189 endif
11190
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011191 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011192 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011193 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011194" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011195" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011196 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011197 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011198" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011199 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011200 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011201
11202 elseif g:netrw_sort_by =~ "^s"
11203 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011204" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011205" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011206 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011207 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011208" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011209 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011210 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011211
11212 else
11213 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011214" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011215" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011216 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011217 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011218" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011219 endfor
11220
11221 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011222 sil! NetrwKeepj g/^$/d
11223 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011224 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011225" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011226 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11227
11228" call Dret("s:LocalListing")
11229endfun
11230
11231" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011232" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11233fun! s:NetrwLocalExecute(cmd)
11234" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11235 let ykeep= @@
11236 " sanity check
11237 if !executable(a:cmd)
11238 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11239 let @@= ykeep
11240" call Dret("s:NetrwLocalExecute")
11241 return
11242 endif
11243
11244 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011245" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011246 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011247" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011248
11249 " strip any ansi escape sequences off
11250 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11251
11252 " show user the result(s)
11253 echomsg result
11254 let @@= ykeep
11255
11256" call Dret("s:NetrwLocalExecute")
11257endfun
11258
11259" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011260" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011261fun! s:NetrwLocalRename(path) range
11262" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11263
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011264 if !exists("w:netrw_bannercnt")
11265 let w:netrw_bannercnt= b:netrw_bannercnt
11266 endif
11267
Bram Moolenaar97d62492012-11-15 21:28:22 +010011268 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011269 let ykeep = @@
11270 let ctr = a:firstline
11271 let svpos = winsaveview()
11272 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011273" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011274
11275 " rename files given by the markfilelist
11276 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11277 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011278" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011279 if exists("subfrom")
11280 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011281" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011282 else
11283 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011284 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011285 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011286 if newname =~ ''
11287 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11288 let newname = substitute(newname,'^.*','','')
11289 elseif newname =~ ''
11290 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11291 let newname = substitute(newname,'[^/]*','','')
11292 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011293 if newname =~ '^s/'
11294 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11295 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011296" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011297 let newname = substitute(oldname,subfrom,subto,'')
11298 endif
11299 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011300 if !all && filereadable(newname)
11301 call inputsave()
11302 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11303 call inputrestore()
11304 if response == "all"
11305 let all= 1
11306 elseif response != "y" && response != "yes"
11307 " refresh the directory
11308" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11309 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11310" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11311 NetrwKeepj call winrestview(svpos)
11312 let @@= ykeep
11313" call Dret("NetrwLocalRename")
11314 return
11315 endif
11316 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011317 call rename(oldname,newname)
11318 endfor
11319 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011320
Bram Moolenaar97d62492012-11-15 21:28:22 +010011321 else
11322
11323 " attempt to rename files/directories
11324 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011325 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011326
11327 " sanity checks
11328 if line(".") < w:netrw_bannercnt
11329 let ctr= ctr + 1
11330 continue
11331 endif
11332 let curword= s:NetrwGetWord()
11333 if curword == "./" || curword == "../"
11334 let ctr= ctr + 1
11335 continue
11336 endif
11337
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011338 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011339 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011340" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011341
11342 call inputsave()
11343 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11344 call inputrestore()
11345
11346 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011347" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011348
11349 let ctr= ctr + 1
11350 endwhile
11351 endif
11352
11353 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011354" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011355 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011356" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11357 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011358 let @@= ykeep
11359
11360" call Dret("NetrwLocalRename")
11361endfun
11362
11363" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011364" s:NetrwLocalRm: {{{2
11365fun! s:NetrwLocalRm(path) range
11366" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011367" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011368
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011369 if !exists("w:netrw_bannercnt")
11370 let w:netrw_bannercnt= b:netrw_bannercnt
11371 endif
11372
Bram Moolenaar446cb832008-06-24 21:56:24 +000011373 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011374 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011375 let ret = 0
11376 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011377 let svpos = winsaveview()
11378" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011379
11380 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11381 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011382" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011383 for fname in s:netrwmarkfilelist_{bufnr("%")}
11384 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011385 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011386 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011387 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011388 let all= 1
11389 endif
11390 endfor
11391 call s:NetrwUnMarkFile(1)
11392
11393 else
11394 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011395" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011396
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011397 let keepsol= &l:sol
11398 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011399 let ctr = a:firstline
11400 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011401 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011402
11403 " sanity checks
11404 if line(".") < w:netrw_bannercnt
11405 let ctr= ctr + 1
11406 continue
11407 endif
11408 let curword= s:NetrwGetWord()
11409 if curword == "./" || curword == "../"
11410 let ctr= ctr + 1
11411 continue
11412 endif
11413 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011414 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011415 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011416 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011417 let all= 1
11418 endif
11419 let ctr= ctr + 1
11420 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011421 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011422 endif
11423
11424 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011425" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011426 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011427 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011428" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11429 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011430 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011431 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011432
11433" call Dret("s:NetrwLocalRm")
11434endfun
11435
11436" ---------------------------------------------------------------------
11437" s:NetrwLocalRmFile: remove file fname given the path {{{2
11438" Give confirmation prompt unless all==1
11439fun! s:NetrwLocalRmFile(path,fname,all)
11440" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011441
Bram Moolenaar446cb832008-06-24 21:56:24 +000011442 let all= a:all
11443 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011444 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011445 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11446" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011447
11448 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11449 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011450" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011451 if !all
11452 echohl Statement
11453 call inputsave()
11454 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11455 call inputrestore()
11456 echohl NONE
11457 if ok == ""
11458 let ok="no"
11459 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011460" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011461 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011462" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011463 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011464 let all= 1
11465 endif
11466 endif
11467
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011468 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011469 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011470" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011471 endif
11472
11473 else
11474 " attempt to remove directory
11475 if !all
11476 echohl Statement
11477 call inputsave()
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011478 let ok= input("Confirm *recursive* deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011479 call inputrestore()
11480 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11481 if ok == ""
11482 let ok="no"
11483 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011484 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011485 let all= 1
11486 endif
11487 endif
11488 let rmfile= substitute(rmfile,'[\/]$','','e')
11489
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011490 if all || ok =~# 'y\%[es]' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011491 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011492 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011493 endif
11494 endif
11495 endif
11496
11497" call Dret("s:NetrwLocalRmFile ".ok)
11498 return ok
11499endfun
11500
Bram Moolenaar85850f32019-07-19 22:05:51 +020011501" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011502" Support Functions: {{{1
11503
Bram Moolenaar488c6512005-08-11 20:09:58 +000011504" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011505" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11506" 0: marked file list of current buffer
11507" 1: marked file target
11508fun! netrw#Access(ilist)
11509 if a:ilist == 0
11510 if exists("s:netrwmarkfilelist_".bufnr('%'))
11511 return s:netrwmarkfilelist_{bufnr('%')}
11512 else
11513 return "no-list-buf#".bufnr('%')
11514 endif
11515 elseif a:ilist == 1
11516 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011517 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011518endfun
11519
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011520" ---------------------------------------------------------------------
11521" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11522fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011523 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011524endfun
11525
Bram Moolenaara6878372014-03-22 21:02:50 +010011526" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011527" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11528" I expect this function to be used in
11529" :PChkAssert netrw#Expose("netrwmarkfilelist")
11530" for example.
11531fun! netrw#Expose(varname)
11532" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011533 if exists("s:".a:varname)
11534 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011535" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011536 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011537" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011538 if type(retval) == 3
11539 let retval = copy(retval)
11540 let i = 0
11541 while i < len(retval)
11542 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11543 let i = i + 1
11544 endwhile
11545 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011546" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011547 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011548 else
11549" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011550 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011551 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011552" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011553 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011554 endif
11555
11556" call Dret("netrw#Expose ".string(retval))
11557 return retval
11558endfun
11559
11560" ---------------------------------------------------------------------
11561" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11562fun! netrw#Modify(varname,newvalue)
11563" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11564 exe "let s:".a:varname."= ".string(a:newvalue)
11565" call Dret("netrw#Modify")
11566endfun
11567
11568" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011569" netrw#RFC2396: converts %xx into characters {{{2
11570fun! netrw#RFC2396(fname)
11571" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011572 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011573" call Dret("netrw#RFC2396 ".fname)
11574 return fname
11575endfun
11576
11577" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011578" netrw#UserMaps: supports user-specified maps {{{2
11579" see :help function()
11580"
11581" g:Netrw_UserMaps is a List with members such as:
11582" [[keymap sequence, function reference],...]
11583"
11584" The referenced function may return a string,
11585" refresh : refresh the display
11586" -other- : this string will be executed
11587" or it may return a List of strings.
11588"
11589" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011590" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011591" Related functions:
11592" netrw#Expose(varname) -- see s:varname variables
11593" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11594" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11595fun! netrw#UserMaps(islocal)
11596" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11597" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11598
11599 " set up usermaplist
11600 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11601" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11602 for umap in g:Netrw_UserMaps
11603" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11604" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11605 " if umap[0] is a string and umap[1] is a string holding a function name
11606 if type(umap[0]) == 1 && type(umap[1]) == 1
11607" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11608 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11609 else
11610 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11611 endif
11612 endfor
11613 endif
11614" call Dret("netrw#UserMaps")
11615endfun
11616
11617" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011618" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11619fun! netrw#WinPath(path)
11620" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011621 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011622 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011623 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011624 " remove trailing slash (Win95)
11625 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11626 " remove escaped spaces
11627 let path = substitute(path, '\ ', ' ', 'g')
11628 " convert slashes to backslashes
11629 let path = substitute(path, '/', '\', 'g')
11630 else
11631 let path= a:path
11632 endif
11633" call Dret("netrw#WinPath <".path.">")
11634 return path
11635endfun
11636
11637" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011638" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11639" cb : bl2mf=0 add marked files to buffer list
11640" cB : bl2mf=1 use bufferlist to mark files
11641" (mnemonic: cb = copy (marked files) to buffer list)
11642fun! s:NetrwBadd(islocal,bl2mf)
11643" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11644 if a:bl2mf
11645 " cB: add buffer list to marked files
11646 redir => bufl
11647 ls
11648 redir END
11649 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11650 for fname in bufl
11651 call s:NetrwMarkFile(a:islocal,fname)
11652 endfor
11653 else
11654 " cb: add marked files to buffer list
11655 for fname in s:netrwmarkfilelist_{bufnr("%")}
11656" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11657 exe "badd ".fnameescape(fname)
11658 endfor
11659 let curbufnr = bufnr("%")
11660 let curdir = s:NetrwGetCurdir(a:islocal)
11661 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11662 endif
11663" call Dret("s:NetrwBadd")
11664endfun
11665
11666" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011667" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11668fun! s:ComposePath(base,subdir)
11669" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11670
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011671 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011672" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011673 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011674 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011675 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011676 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011677 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011678 endif
11679
Bram Moolenaar85850f32019-07-19 22:05:51 +020011680 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011681 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011682" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011683 let ret= a:subdir
11684
Nir Lichtman1e34b952024-05-08 19:19:34 +020011685 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011686" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011687 if a:base =~ '[/\\]$'
11688 let ret= a:base.a:subdir
11689 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011690 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011691 endif
11692
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011693 elseif a:base =~ '^\a\{3,}://'
11694" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011695 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11696 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11697 if a:subdir == '../'
11698 if curpath =~ '[^/]/[^/]\+/$'
11699 let curpath= substitute(curpath,'[^/]\+/$','','')
11700 else
11701 let curpath=""
11702 endif
11703 let ret= urlbase.curpath
11704 else
11705 let ret= urlbase.curpath.a:subdir
11706 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011707" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11708" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11709" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011710
11711 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011712" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011713 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11714 if a:base =~ '^//'
11715 " keeping initial '//' for the benefit of network share listing support
11716 let ret= '/'.ret
11717 endif
11718 let ret= simplify(ret)
11719 endif
11720
11721" call Dret("s:ComposePath ".ret)
11722 return ret
11723endfun
11724
11725" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011726" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11727" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11728fun! s:DeleteBookmark(fname)
11729" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11730 call s:MergeBookmarks()
11731
11732 if exists("g:netrw_bookmarklist")
11733 let indx= index(g:netrw_bookmarklist,a:fname)
11734 if indx == -1
11735 let indx= 0
11736 while indx < len(g:netrw_bookmarklist)
11737 if g:netrw_bookmarklist[indx] =~ a:fname
11738 call remove(g:netrw_bookmarklist,indx)
11739 let indx= indx - 1
11740 endif
11741 let indx= indx + 1
11742 endwhile
11743 else
11744 " remove exact match
11745 call remove(g:netrw_bookmarklist,indx)
11746 endif
11747 endif
11748
11749" call Dret("s:DeleteBookmark")
11750endfun
11751
11752" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011753" s:FileReadable: o/s independent filereadable {{{2
11754fun! s:FileReadable(fname)
11755" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11756
11757 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011758 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011759 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011760 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011761 endif
11762
11763" call Dret("s:FileReadable ".ret)
11764 return ret
11765endfun
11766
11767" ---------------------------------------------------------------------
11768" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11769" Places correct suffix on end of temporary filename,
11770" using the suffix provided with fname
11771fun! s:GetTempfile(fname)
11772" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11773
11774 if !exists("b:netrw_tmpfile")
11775 " get a brand new temporary filename
11776 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011777" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011778
Bram Moolenaarc236c162008-07-13 17:41:49 +000011779 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011780" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011781
Bram Moolenaar9964e462007-05-05 17:54:07 +000011782 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011783 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11784" 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 +010011785 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011786" call Dret("s:GetTempfile getcwd<".getcwd().">")
11787 return ""
11788 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011789
Bram Moolenaar9964e462007-05-05 17:54:07 +000011790 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011791 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011792" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011793
Bram Moolenaar9964e462007-05-05 17:54:07 +000011794 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011795 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011796 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011797 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011798 if !exists("+shellslash") || !&ssl
11799 let tmpfile = substitute(tmpfile,'/','\','g')
11800 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011801 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011802 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011803 endif
11804 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011805" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011806 else
11807 " re-use temporary filename
11808 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011809" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011810 endif
11811
11812 " use fname's suffix for the temporary file
11813 if a:fname != ""
11814 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011815" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011816 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011817 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011818 elseif a:fname =~ '.txz$'
11819 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011820 else
11821 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11822 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011823" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011824 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011825" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011826 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011827" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011828 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11829 endif
11830 endif
11831
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011832" 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 +000011833" call Dret("s:GetTempfile <".tmpfile.">")
11834 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011835endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011836
11837" ---------------------------------------------------------------------
11838" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011839" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011840fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011841" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011842 if s:user == ""
11843 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11844 else
11845 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11846 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011847 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011848 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011849 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011850 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011851 else
11852 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11853 endif
11854" call Dret("s:MakeSshCmd <".sshcmd.">")
11855 return sshcmd
11856endfun
11857
11858" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011859" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11860fun! s:MakeBookmark(fname)
11861" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11862
11863 if !exists("g:netrw_bookmarklist")
11864 let g:netrw_bookmarklist= []
11865 endif
11866
11867 if index(g:netrw_bookmarklist,a:fname) == -1
11868 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011869 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011870 call add(g:netrw_bookmarklist,a:fname.'/')
11871 elseif a:fname !~ '/'
11872 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11873 else
11874 call add(g:netrw_bookmarklist,a:fname)
11875 endif
11876 call sort(g:netrw_bookmarklist)
11877 endif
11878
11879" call Dret("s:MakeBookmark")
11880endfun
11881
11882" ---------------------------------------------------------------------
11883" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11884fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011885" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011886 " get bookmarks from .netrwbook file
11887 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011888 if filereadable(s:NetrwFile(savefile))
11889" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011890 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011891" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011892 NetrwKeepj call delete(savefile)
11893 endif
11894" call Dret("s:MergeBookmarks")
11895endfun
11896
11897" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011898" s:NetrwBMShow: {{{2
11899fun! s:NetrwBMShow()
11900" call Dfunc("s:NetrwBMShow()")
11901 redir => bmshowraw
11902 menu
11903 redir END
11904 let bmshowlist = split(bmshowraw,'\n')
11905 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011906 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011907 if bmshowfuncs != []
11908 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011909 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011910 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011911 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011912 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011913 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011914" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11915endfun
11916
11917" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011918" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011919fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011920 if !exists("w:netrw_liststyle")
11921 let w:netrw_liststyle= g:netrw_liststyle
11922 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011923" 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 +020011924
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011925" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11926
Bram Moolenaaradc21822011-04-01 18:03:16 +020011927 if &ft != "netrw"
11928 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11929 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011930" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011931
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011932 elseif g:netrw_cursor == 8
11933 if w:netrw_liststyle == s:WIDELIST
11934 setl cursorline
11935 setl cursorcolumn
11936 else
11937 setl cursorline
11938 endif
11939 elseif g:netrw_cursor == 7
11940 setl cursorline
11941 elseif g:netrw_cursor == 6
11942 if w:netrw_liststyle == s:WIDELIST
11943 setl cursorline
11944 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011945 elseif g:netrw_cursor == 4
11946 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011947" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011948 setl cursorline
11949 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011950
11951 elseif g:netrw_cursor == 3
11952 " thin-long-tree: cursorline, user's cursorcolumn
11953 " wide : cursorline, cursorcolumn
11954 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011955" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011956 setl cursorline
11957 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011958 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011959" 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 +020011960 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011961 endif
11962
11963 elseif g:netrw_cursor == 2
11964 " thin-long-tree: cursorline, user's cursorcolumn
11965 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011966" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011967 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011968
11969 elseif g:netrw_cursor == 1
11970 " thin-long-tree: user's cursorline, user's cursorcolumn
11971 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011972 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011973" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011974 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011975 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011976" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011977 endif
11978
11979 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011980 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011981" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011982 let &l:cursorline = s:netrw_usercul
11983 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011984 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011985
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011986" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011987" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011988endfun
11989
11990" ---------------------------------------------------------------------
11991" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11992fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011993" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011994 if exists("s:netrw_usercul")
11995 let &l:cursorline = s:netrw_usercul
11996 endif
11997 if exists("s:netrw_usercuc")
11998 let &l:cursorcolumn = s:netrw_usercuc
11999 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012000" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012001" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12002endfun
12003
Christian Brabandt62f7b552024-06-23 20:23:40 +020012004" s:RestoreRegister: restores all registers given in the dict {{{2
12005fun! s:RestoreRegister(dict)
12006 for [key, val] in items(a:dict)
12007 if key == 'unnamed'
12008 let key = ''
12009 endif
12010 call setreg(key, val[0], val[1])
12011 endfor
12012endfun
12013
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012014" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012015" s:NetrwDelete: Deletes a file. {{{2
12016" Uses Steve Hall's idea to insure that Windows paths stay
12017" acceptable. No effect on Unix paths.
12018" Examples of use: let result= s:NetrwDelete(path)
12019fun! s:NetrwDelete(path)
12020" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12021
Bram Moolenaar5c736222010-01-06 20:54:52 +010012022 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012023 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012024 if exists("+shellslash")
12025 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012026 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012027 let result = delete(path)
12028 let &shellslash = sskeep
12029 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012030" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012031 let result= delete(path)
12032 endif
12033 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012034" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012035 let result= delete(path)
12036 endif
12037 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012038 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012039 endif
12040
12041" call Dret("s:NetrwDelete ".result)
12042 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012043endfun
12044
12045" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012046" s:NetrwBufRemover: removes a buffer that: {{{2s
12047" has buffer-id > 1
12048" is unlisted
12049" is unnamed
12050" does not appear in any window
12051fun! s:NetrwBufRemover(bufid)
12052" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12053" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12054" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12055" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12056" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12057
yasuda4dbb2662023-10-04 20:50:35 +020012058 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012059" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012060 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012061 endif
12062
12063" call Dret("s:NetrwBufRemover")
12064endfun
12065
12066" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012067" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012068fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012069" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012070" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012071
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012072 " Clean out the last buffer:
12073 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12074 " If so, delete it.
12075 call s:NetrwBufRemover(bufnr("$"))
12076
Bram Moolenaar446cb832008-06-24 21:56:24 +000012077 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012078" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012079 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12080 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12081 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12082 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12083 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12084 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12085 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12086 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12087 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12088 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12089 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12090 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12091 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12092 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12093 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12094 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12095
Bram Moolenaar85850f32019-07-19 22:05:51 +020012096 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012097" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012098 " when tree listing uses file TreeListing... a new buffer is made.
12099 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012100 " COMBAK: this causes a problem, see P43
12101" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012102 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012103 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012104 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012105" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012106 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012107
Bram Moolenaar446cb832008-06-24 21:56:24 +000012108 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012109" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012110 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12111 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12112 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12113 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12114 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12115 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12116 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12117 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12118 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12119 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12120 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12121 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12122 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12123 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12124 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12125 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12126
Bram Moolenaar5c736222010-01-06 20:54:52 +010012127 if a:0 > 0
12128 let b:netrw_curdir= a:1
12129 if b:netrw_curdir =~ '/$'
12130 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012131 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012132 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012133 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012134 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12135 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012136 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012137 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012138 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012139 endif
12140 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012141 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12142 let &l:bexpr = "netrw#BalloonHelp()"
12143 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012144
Bram Moolenaar8d043172014-01-23 14:24:41 +010012145" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012146endfun
12147
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012148" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012149" s:NetrwExe: executes a string using "!" {{{2
12150fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012151" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012152 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012153" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012154 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12155 set shell& shellcmdflag& shellxquote& shellxescape&
12156 set shellquote& shellpipe& shellredir& shellslash&
12157 exe a:cmd
12158 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12159 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012160" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012161 exe a:cmd
12162 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012163 if v:shell_error
12164 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12165 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012166" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012167endfun
12168
12169" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012170" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12171fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012172 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012173" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012174 let curbuf = bufnr("%")
12175 let curwin = winnr()
12176 let iwin = 1
12177 while iwin <= winnr("$")
12178 exe iwin."wincmd w"
12179 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12180 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12181 let winvars= w:
12182 break
12183 endif
12184 let iwin= iwin + 1
12185 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012186 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012187 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012188" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012189 for k in keys(winvars)
12190 let w:{k}= winvars[k]
12191 endfor
12192 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012193" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012194 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012195endfun
12196
Bram Moolenaara6878372014-03-22 21:02:50 +010012197" ---------------------------------------------------------------------
12198" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012199" Returns: 0=success
12200" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012201fun! s:NetrwLcd(newdir)
12202" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012203" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012204
Bram Moolenaar85850f32019-07-19 22:05:51 +020012205 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012206 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012207 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012208 catch /^Vim\%((\a\+)\)\=:E344/
12209 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12210 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012211 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012212 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12213 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012214 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012215 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12216 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012217 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012218 endif
12219 endif
12220 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012221 let err472= 1
12222 endtry
12223
12224 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012225 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12226 if exists("w:netrw_prvdir")
12227 let a:newdir= w:netrw_prvdir
12228 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012229 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012230" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012231 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012232" 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 +010012233 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012234 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012235" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12236 return -1
12237 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012238
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012239" call Decho("getcwd <".getcwd().">")
12240" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012241" call Dret("s:NetrwLcd 0")
12242 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012243endfun
12244
Bram Moolenaar9964e462007-05-05 17:54:07 +000012245" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012246" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12247" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12248fun! s:NetrwSaveWordPosn()
12249" call Dfunc("NetrwSaveWordPosn()")
12250 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12251" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12252endfun
12253
12254" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012255" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12256" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12257fun! s:NetrwHumanReadable(sz)
12258" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12259
12260 if g:netrw_sizestyle == 'h'
12261 if a:sz >= 1000000000
12262 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12263 elseif a:sz >= 10000000
12264 let sz = printf("%d",a:sz/1000000)."m"
12265 elseif a:sz >= 1000000
12266 let sz = printf("%.1f",a:sz/1000000.0)."m"
12267 elseif a:sz >= 10000
12268 let sz = printf("%d",a:sz/1000)."k"
12269 elseif a:sz >= 1000
12270 let sz = printf("%.1f",a:sz/1000.0)."k"
12271 else
12272 let sz= a:sz
12273 endif
12274
12275 elseif g:netrw_sizestyle == 'H'
12276 if a:sz >= 1073741824
12277 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12278 elseif a:sz >= 10485760
12279 let sz = printf("%d",a:sz/1048576)."M"
12280 elseif a:sz >= 1048576
12281 let sz = printf("%.1f",a:sz/1048576.0)."M"
12282 elseif a:sz >= 10240
12283 let sz = printf("%d",a:sz/1024)."K"
12284 elseif a:sz >= 1024
12285 let sz = printf("%.1f",a:sz/1024.0)."K"
12286 else
12287 let sz= a:sz
12288 endif
12289
12290 else
12291 let sz= a:sz
12292 endif
12293
12294" call Dret("s:NetrwHumanReadable ".sz)
12295 return sz
12296endfun
12297
12298" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012299" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12300" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12301fun! s:NetrwRestoreWordPosn()
12302" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012303 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012304" call Dret("NetrwRestoreWordPosn")
12305endfun
12306
12307" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012308" s:RestoreBufVars: {{{2
12309fun! s:RestoreBufVars()
12310" call Dfunc("s:RestoreBufVars()")
12311
12312 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12313 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12314 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12315 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12316 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12317 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12318
12319" call Dret("s:RestoreBufVars")
12320endfun
12321
12322" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012323" s:RemotePathAnalysis: {{{2
12324fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012325" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012326
Bram Moolenaara6878372014-03-22 21:02:50 +010012327 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012328 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012329 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012330 let s:user = substitute(a:dirname,dirpat,'\3','')
12331 let s:machine = substitute(a:dirname,dirpat,'\4','')
12332 let s:port = substitute(a:dirname,dirpat,'\5','')
12333 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012334 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012335 if s:machine =~ '@'
12336 let dirpat = '^\(.*\)@\(.\{-}\)$'
12337 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12338 let s:machine = substitute(s:machine,dirpat,'\2','')
12339 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012340
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012341" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12342" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12343" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12344" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12345" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12346" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012347
12348" call Dret("s:RemotePathAnalysis")
12349endfun
12350
12351" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012352" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12353" Returns status
12354" Runs system() on
12355" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012356" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012357fun! s:RemoteSystem(cmd)
12358" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12359 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012360 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 +000012361 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012362 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012363 else
12364 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12365 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12366 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012367 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012368 else
12369 let cmd= cmd.' '
12370 endif
12371 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012372" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012373 let ret= system(cmd)
12374 endif
12375" call Dret("s:RemoteSystem ".ret)
12376 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012377endfun
12378
12379" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012380" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012381fun! s:RestoreWinVars()
12382" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012383 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012384 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12385 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12386 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12387 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12388 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12389 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12390 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12391 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12392 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12393 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12394 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12395 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012396 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12397 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012398 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12399 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12400 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12401" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012402endfun
12403
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012404" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012405" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12406"
12407" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12408" is true) and a command, :Rexplore, which call this function.
12409"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012410" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012411"
12412" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012413fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012414 if exists("s:netrwdrag")
12415 return
12416 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012417" 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 +010012418" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12419" 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 +010012420
12421 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012422 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012423" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012424 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012425 unlet w:netrw_rexfile
12426" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012427 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012428" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012429" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12430" 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 +020012431 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012432
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012433 " ---------------------------
12434 " :Rex issued while in a file
12435 " ---------------------------
12436
Bram Moolenaara6878372014-03-22 21:02:50 +010012437 " record current file so :Rex can return to it from netrw
12438 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012439" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012440
12441 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012442" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012443 return
12444 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012445" 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 +020012446 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012447 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012448 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012449 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012450 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012451 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012452 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012453 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012454 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012455" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12456 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012457" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12458 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012459 if exists("s:rexposn_".bufnr('%'))
12460 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012461 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012462 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012463" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012464 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012465
Bram Moolenaar85850f32019-07-19 22:05:51 +020012466 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12467 if exists("s:explore_match")
12468 exe "2match netrwMarkFile /".s:explore_match."/"
12469 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012470 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012471
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012472" 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 +010012473" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012474endfun
12475
12476" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012477" s:SaveBufVars: save selected b: variables to s: variables {{{2
12478" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012479fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012480" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012481
12482 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12483 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12484 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12485 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12486 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12487 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12488
12489" call Dret("s:SaveBufVars")
12490endfun
12491
12492" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012493" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12494fun! s:SavePosn(posndict)
12495" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12496
Bram Moolenaar85850f32019-07-19 22:05:51 +020012497 if !exists("a:posndict[bufnr('%')]")
12498 let a:posndict[bufnr("%")]= []
12499 endif
12500" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12501 call add(a:posndict[bufnr("%")],winsaveview())
12502" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012503
12504" call Dret("s:SavePosn posndict")
12505 return a:posndict
12506endfun
12507
12508" ---------------------------------------------------------------------
12509" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12510fun! s:RestorePosn(posndict)
12511" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012512 if exists("a:posndict")
12513 if has_key(a:posndict,bufnr("%"))
12514" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12515 let posnlen= len(a:posndict[bufnr("%")])
12516 if posnlen > 0
12517 let posnlen= posnlen - 1
12518" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12519 call winrestview(a:posndict[bufnr("%")][posnlen])
12520 call remove(a:posndict[bufnr("%")],posnlen)
12521" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12522 endif
12523 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012524 endif
12525" call Dret("s:RestorePosn")
12526endfun
12527
12528" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012529" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012530fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012531" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012532 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12533 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12534 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12535 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12536 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12537 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12538 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12539 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12540 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12541 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12542 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12543 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12544 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12545 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12546 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12547 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12548 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12549 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12550" call Dret("s:SaveWinVars")
12551endfun
12552
12553" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012554" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012555" To allow separate windows to have their own activities, such as
12556" Explore **/pattern, several variables have been made window-oriented.
12557" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012558" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012559" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012560fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012561" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012562 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12563 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12564 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12565 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12566 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12567 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12568 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12569 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12570 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12571 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12572" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012573endfun
12574
12575" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012576" s:SetRexDir: set directory for :Rexplore {{{2
12577fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012578" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012579 let w:netrw_rexdir = a:dirname
12580 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012581 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012582" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12583" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012584" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012585" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012586" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012587endfun
12588
12589" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012590" s:ShowLink: used to modify thin and tree listings to show links {{{2
12591fun! s:ShowLink()
12592" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012593" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12594" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012595 if exists("b:netrw_curdir")
12596 norm! $?\a
12597 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12598 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012599" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12600" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12601" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12602 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012603 let dirlen = strlen(b:netrw_curdir)
12604 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012605" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012606 endif
12607 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012608" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12609" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012610 setl noro ma
12611 call setline(".",modline)
12612 setl ro noma nomod
12613 endif
12614" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12615endfun
12616
12617" ---------------------------------------------------------------------
12618" s:ShowStyle: {{{2
12619fun! s:ShowStyle()
12620 if !exists("w:netrw_liststyle")
12621 let liststyle= g:netrw_liststyle
12622 else
12623 let liststyle= w:netrw_liststyle
12624 endif
12625 if liststyle == s:THINLIST
12626 return s:THINLIST.":thin"
12627 elseif liststyle == s:LONGLIST
12628 return s:LONGLIST.":long"
12629 elseif liststyle == s:WIDELIST
12630 return s:WIDELIST.":wide"
12631 elseif liststyle == s:TREELIST
12632 return s:TREELIST.":tree"
12633 else
12634 return 'n/a'
12635 endif
12636endfun
12637
12638" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012639" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12640" Solution from Nicolai Weibull, vim docs (:help strlen()),
12641" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012642fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012643" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12644
12645 if v:version >= 703 && exists("*strdisplaywidth")
12646 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012647
Bram Moolenaar8d043172014-01-23 14:24:41 +010012648 elseif type(g:Align_xstrlen) == 1
12649 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12650 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012651
Bram Moolenaar8d043172014-01-23 14:24:41 +010012652 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012653 " number of codepoints (Latin a + combining circumflex is two codepoints)
12654 " (comment from TM, solution from NW)
12655 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012656
Bram Moolenaar8d043172014-01-23 14:24:41 +010012657 elseif g:Align_xstrlen == 2
12658 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012659 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12660 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012661 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012662
Bram Moolenaar8d043172014-01-23 14:24:41 +010012663 elseif g:Align_xstrlen == 3
12664 " virtual length (counting, for instance, tabs as anything between 1 and
12665 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012666 " preceded by lam, one otherwise, etc.)
12667 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012668 let modkeep= &l:mod
12669 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012670 call setline(line("."),a:x)
12671 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012672 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012673 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012674 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012675
Bram Moolenaar446cb832008-06-24 21:56:24 +000012676 else
12677 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012678 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012679 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012680" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012681 return ret
12682endfun
12683
12684" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012685" s:ShellEscape: shellescape(), or special windows handling {{{2
12686fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012687 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012688 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12689 endif
12690 let f = a:0 > 0 ? a:1 : 0
12691 return shellescape(a:s, f)
12692endfun
12693
12694" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012695" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012696fun! s:TreeListMove(dir)
12697" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012698 let curline = getline('.')
12699 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12700 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12701 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12702 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12703 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12704 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12705" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12706" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12707" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12708" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12709" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12710 " COMBAK : need to handle when on a directory
12711 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012712 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012713 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012714 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012715 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012716" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012717 elseif a:dir == '[]' && nxtline != ''
12718 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012719" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012720 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12721 if nl != 0
12722 NetrwKeepj norm! k
12723 else
12724 NetrwKeepj norm! G
12725 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012726" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012727 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012728 endif
12729
12730" call Dret("s:TreeListMove")
12731endfun
12732
12733" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012734" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12735" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12736" can't be called except via emenu. But due to locale, that menu line may not be called
12737" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12738fun! s:UpdateBuffersMenu()
12739" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012740 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012741 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012742 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012743 catch /^Vim\%((\a\+)\)\=:E/
12744 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012745 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012746 endtry
12747 endif
12748" call Dret("s:UpdateBuffersMenu")
12749endfun
12750
12751" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012752" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012753" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012754fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012755" call Dfunc("s:UseBufWinVars()")
12756 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012757 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12758 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12759 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12760 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12761 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12762 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12763 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12764 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12765 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 +000012766" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012767endfun
12768
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012769" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012770" s:UserMaps: supports user-defined UserMaps {{{2
12771" * calls a user-supplied funcref(islocal,curdir)
12772" * interprets result
12773" See netrw#UserMaps()
12774fun! s:UserMaps(islocal,funcname)
12775" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12776
12777 if !exists("b:netrw_curdir")
12778 let b:netrw_curdir= getcwd()
12779 endif
12780 let Funcref = function(a:funcname)
12781 let result = Funcref(a:islocal)
12782
12783 if type(result) == 1
12784 " if result from user's funcref is a string...
12785" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12786 if result == "refresh"
12787" call Decho("refreshing display",'~'.expand("<slnum>"))
12788 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12789 elseif result != ""
12790" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12791 exe result
12792 endif
12793
12794 elseif type(result) == 3
12795 " if result from user's funcref is a List...
12796" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12797 for action in result
12798 if action == "refresh"
12799" call Decho("refreshing display",'~'.expand("<slnum>"))
12800 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12801 elseif action != ""
12802" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12803 exe action
12804 endif
12805 endfor
12806 endif
12807
12808" call Dret("s:UserMaps")
12809endfun
12810
Bram Moolenaar85850f32019-07-19 22:05:51 +020012811" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012812" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012813" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012814let &cpo= s:keepcpo
12815unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012816
Bram Moolenaar85850f32019-07-19 22:05:51 +020012817" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012818" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012819" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012820" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012821" doing autoload/netrw.vim version v172g ~57
12822" varname<g:netrw_dirhistcnt> value=0 ~1
12823" varname<s:THINLIST> value=0 ~1
12824" varname<s:LONGLIST> value=1 ~1
12825" varname<s:WIDELIST> value=2 ~1
12826" varname<s:TREELIST> value=3 ~1
12827" varname<s:MAXLIST> value=4 ~1
12828" varname<g:netrw_use_errorwindow> value=2 ~1
12829" varname<g:netrw_http_xcmd> value=-q -O ~1
12830" varname<g:netrw_http_put_cmd> value=curl -T ~1
12831" varname<g:netrw_keepj> value=keepj ~1
12832" varname<g:netrw_rcp_cmd> value=rcp ~1
12833" varname<g:netrw_rsync_cmd> value=rsync ~1
12834" varname<g:netrw_rsync_sep> value=/ ~1
12835" varname<g:netrw_scp_cmd> value=scp -q ~1
12836" varname<g:netrw_sftp_cmd> value=sftp ~1
12837" varname<g:netrw_ssh_cmd> value=ssh ~1
12838" varname<g:netrw_alto> value=0 ~1
12839" varname<g:netrw_altv> value=1 ~1
12840" varname<g:netrw_banner> value=1 ~1
12841" varname<g:netrw_browse_split> value=0 ~1
12842" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12843" varname<g:netrw_chgwin> value=-1 ~1
12844" varname<g:netrw_clipboard> value=1 ~1
12845" varname<g:netrw_compress> value=gzip ~1
12846" varname<g:netrw_ctags> value=ctags ~1
12847" varname<g:netrw_cursor> value=2 ~1
12848" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12849" varname<g:netrw_cygdrive> value=/cygdrive ~1
12850" varname<s:didstarstar> value=0 ~1
12851" varname<g:netrw_dirhistcnt> value=0 ~1
12852" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12853" varname<g:netrw_dirhistmax> value=10 ~1
12854" varname<g:netrw_errorlvl> value=0 ~1
12855" varname<g:netrw_fastbrowse> value=1 ~1
12856" 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
12857" varname<g:netrw_ftpmode> value=binary ~1
12858" varname<g:netrw_hide> value=1 ~1
12859" varname<g:netrw_keepdir> value=1 ~1
12860" varname<g:netrw_list_hide> value= ~1
12861" varname<g:netrw_localmkdir> value=mkdir ~1
12862" varname<g:netrw_remote_mkdir> value=mkdir ~1
12863" varname<g:netrw_liststyle> value=0 ~1
12864" varname<g:netrw_markfileesc> value=*./[\~ ~1
12865" varname<g:netrw_maxfilenamelen> value=32 ~1
12866" varname<g:netrw_menu> value=1 ~1
12867" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12868" varname<g:netrw_mousemaps> value=1 ~1
12869" varname<g:netrw_retmap> value=0 ~1
12870" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12871" varname<g:netrw_preview> value=0 ~1