blob: 9f7afd5b29d55ec94f3f8054278c740ca0417df8 [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)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Christian Brabandtf9ca1392024-02-19 20:37:11 +010021" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000022" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010023" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000024" Permission is hereby granted to use and distribute this code,
25" with or without modifications, provided that this copyright
26" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000027" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000028" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000029" expressed or implied. By using this plugin, you agree that
30" in no event will the copyright holder be liable for any damages
31" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010032"
33" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
34" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
35"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020036"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000037"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000038" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000039" (James 1:22 RSV)
40" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000041" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000042if &cp || exists("g:loaded_netrw")
43 finish
44endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020045
46" Check that vim has patches that netrw requires.
47" Patches needed for v7.4: 1557, and 213.
48" (netrw will benefit from vim's having patch#656, too)
49let s:needspatches=[1557,213]
50if exists("s:needspatches")
51 for ptch in s:needspatches
52 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
53 if !exists("s:needpatch{ptch}")
54 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
55 endif
56 let s:needpatch{ptch}= 1
57 finish
58 endif
59 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020060endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020061
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010062let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000063if !exists("s:NOTE")
64 let s:NOTE = 0
65 let s:WARNING = 1
66 let s:ERROR = 2
67endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000068
Bram Moolenaar1afcace2005-11-25 19:54:28 +000069let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010070setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020071"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010072"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010073"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000074
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000075" ======================
76" Netrw Variables: {{{1
77" ======================
78
Bram Moolenaar071d4272004-06-13 20:20:40 +000079" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020080" netrw#ErrorMsg: {{{2
81" 0=note = s:NOTE
82" 1=warning = s:WARNING
83" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010084" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
85" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
86" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010087" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020088fun! netrw#ErrorMsg(level,msg,errnum)
89" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
90
91 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020092" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020093 return
94 endif
95
96 if a:level == 1
97 let level= "**warning** (netrw) "
98 elseif a:level == 2
99 let level= "**error** (netrw) "
100 else
101 let level= "**note** (netrw) "
102 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100103" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200104
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200105 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
106 " use popup window
107 if type(a:msg) == 3
108 let msg = [level]+a:msg
109 else
110 let msg= level.a:msg
111 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200112 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200113 let s:popuperr_text= ""
114 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200115 " (default) netrw creates a one-line window to show error/warning
116 " messages (reliably displayed)
117
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100118 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200119 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100120" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200121
122 " getting messages out reliably is just plain difficult!
123 " This attempt splits the current window, creating a one line window.
124 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100125" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200126 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100127" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200128 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100129 if type(a:msg) == 3
130 for msg in a:msg
131 NetrwKeepj call setline(line("$")+1,level.msg)
132 endfor
133 else
134 NetrwKeepj call setline(line("$")+1,level.a:msg)
135 endif
136 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200137 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100138" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200139 bo 1split
140 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200141 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200142 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100143 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100144" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200145 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100146 if type(a:msg) == 3
147 for msg in a:msg
148 NetrwKeepj call setline(line("$")+1,level.msg)
149 endfor
150 else
151 NetrwKeepj call setline(line("$"),level.a:msg)
152 endif
153 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200154 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100155" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200156 if &fo !~ '[ta]'
157 syn clear
158 syn match netrwMesgNote "^\*\*note\*\*"
159 syn match netrwMesgWarning "^\*\*warning\*\*"
160 syn match netrwMesgError "^\*\*error\*\*"
161 hi link netrwMesgWarning WarningMsg
162 hi link netrwMesgError Error
163 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100164" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200165 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200166
167 else
168 " (optional) netrw will show messages using echomsg. Even if the
169 " message doesn't appear, at least it'll be recallable via :messages
170" redraw!
171 if a:level == s:WARNING
172 echohl WarningMsg
173 elseif a:level == s:ERROR
174 echohl Error
175 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100176
177 if type(a:msg) == 3
178 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100179 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100180 endfor
181 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100182 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100183 endif
184
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100185" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200186 echohl None
187 endif
188
189" call Dret("netrw#ErrorMsg")
190endfun
191
192" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100193" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100194" Loosely, varname = value.
195fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100196" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100197 if !exists(a:varname)
198 if type(a:value) == 0
199 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200200 elseif type(a:value) == 1 && a:value =~ '^[{[]'
201 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100202 elseif type(a:value) == 1
203 exe "let ".a:varname."="."'".a:value."'"
204 else
205 exe "let ".a:varname."=".a:value
206 endif
207 endif
208endfun
209
210" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000211" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200212call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000213if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100214 call s:NetrwInit("s:THINLIST",0)
215 call s:NetrwInit("s:LONGLIST",1)
216 call s:NetrwInit("s:WIDELIST",2)
217 call s:NetrwInit("s:TREELIST",3)
218 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000219endif
220
221" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200222" Default option values: {{{2
223let g:netrw_localcopycmdopt = ""
224let g:netrw_localcopydircmdopt = ""
225let g:netrw_localmkdiropt = ""
226let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200227
228" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000229" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200230if (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")
231 call s:NetrwInit("g:netrw_use_errorwindow",2)
232else
233 call s:NetrwInit("g:netrw_use_errorwindow",1)
234endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200235
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000236if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100237 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000238 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100239 elseif executable("curl")
240 let g:netrw_dav_cmd = "curl"
241 else
242 let g:netrw_dav_cmd = ""
243 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000244endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000245if !exists("g:netrw_fetch_cmd")
246 if executable("fetch")
247 let g:netrw_fetch_cmd = "fetch -o"
248 else
249 let g:netrw_fetch_cmd = ""
250 endif
251endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100252if !exists("g:netrw_file_cmd")
253 if executable("elinks")
254 call s:NetrwInit("g:netrw_file_cmd","elinks")
255 elseif executable("links")
256 call s:NetrwInit("g:netrw_file_cmd","links")
257 endif
258endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000259if !exists("g:netrw_ftp_cmd")
260 let g:netrw_ftp_cmd = "ftp"
261endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200262let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200263if !exists("g:netrw_ftp_options")
264 let g:netrw_ftp_options= "-i -n"
265endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000266if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100267 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100268 let g:netrw_http_cmd = "wget"
269 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100270 elseif executable("curl")
271 let g:netrw_http_cmd = "curl"
272 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200273 elseif executable("elinks")
274 let g:netrw_http_cmd = "elinks"
275 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000276 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100277 let g:netrw_http_cmd = "fetch"
278 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200279 elseif executable("links")
280 let g:netrw_http_cmd = "links"
281 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000282 else
283 let g:netrw_http_cmd = ""
284 endif
285endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100286call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100287call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100288call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
289call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200290call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200291if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200292 if executable("scp")
293 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
294 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200295 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200296 else
297 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
298 endif
299endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100300call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
301call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000302
Nir Lichtman1e34b952024-05-08 19:19:34 +0200303if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000304 \ && exists("g:netrw_use_nt_rcp")
305 \ && g:netrw_use_nt_rcp
306 \ && executable( $SystemRoot .'/system32/rcp.exe')
307 let s:netrw_has_nt_rcp = 1
308 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000309else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000310 let s:netrw_has_nt_rcp = 0
311 let s:netrw_rcpmode = ''
312endif
313
314" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000315" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000316" Cygwin Detection ------- {{{3
317if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200318 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
319 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000320 else
321 let g:netrw_cygwin= 0
322 endif
323endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000324" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100325call s:NetrwInit("g:netrw_alto" , &sb)
326call s:NetrwInit("g:netrw_altv" , &spr)
327call s:NetrwInit("g:netrw_banner" , 1)
328call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200329call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100330call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200331call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100332call s:NetrwInit("g:netrw_compress" , "gzip")
333call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200334if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
335 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
336 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000337endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200338call s:NetrwInit("g:netrw_cursor" , 2)
339let s:netrw_usercul = &cursorline
340let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200341"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100342call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000343" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200344call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200345call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200346call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100347call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200348call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100349call s:NetrwInit("g:netrw_fastbrowse" , 1)
350call s:NetrwInit("g:netrw_ftp_browse_reject", '^total\s\+\d\+$\|^Trying\s\+\d\+.*$\|^KERBEROS_V\d rejected\|^Security extensions not\|No such file\|: connect to address [0-9a-fA-F:]*: No route to host$')
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000351if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000352 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
353 let g:netrw_ftp_list_cmd = "ls -lF"
354 let g:netrw_ftp_timelist_cmd = "ls -tlF"
355 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000356 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000357 let g:netrw_ftp_list_cmd = "dir"
358 let g:netrw_ftp_timelist_cmd = "dir"
359 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000360 endif
361endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100362call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000363" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100364call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000365if !exists("g:netrw_ignorenetrc")
366 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
367 let g:netrw_ignorenetrc= 1
368 else
369 let g:netrw_ignorenetrc= 0
370 endif
371endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100372call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000373if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000374 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100375 if exists("g:netrw_list_cmd_options")
376 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
377 else
378 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
379 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000380 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200381 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100382 if exists("g:netrw_list_cmd_options")
383 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
384 else
385 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
386 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000387 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100388" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000389 let g:netrw_list_cmd= ""
390 endif
391endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100392call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000393" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200394if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200395 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200396 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
397endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100398if !exists("g:netrw_localcmdshell")
399 let g:netrw_localcmdshell= ""
400endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000401if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200402 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000403 if g:netrw_cygwin
404 let g:netrw_localcopycmd= "cp"
405 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000406 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200407 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000408 endif
409 elseif has("unix") || has("macunix")
410 let g:netrw_localcopycmd= "cp"
411 else
412 let g:netrw_localcopycmd= ""
413 endif
414endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100415if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200416 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100417 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200418 let g:netrw_localcopydircmd = "cp"
419 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100420 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000421 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200422 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100423 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200424 elseif has("unix")
425 let g:netrw_localcopydircmd = "cp"
426 let g:netrw_localcopydircmdopt= " -R"
427 elseif has("macunix")
428 let g:netrw_localcopydircmd = "cp"
429 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100430 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200431 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100432 endif
433endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200434if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100435 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200436 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
437endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200438if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200439 if g:netrw_cygwin
440 call s:NetrwInit("g:netrw_localmkdir","mkdir")
441 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000442 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200443 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200444 endif
445else
446 call s:NetrwInit("g:netrw_localmkdir","mkdir")
447endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200448call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200449if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200450 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200451 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
452endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000453if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200454 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000455 if g:netrw_cygwin
456 let g:netrw_localmovecmd= "mv"
457 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000458 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200459 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000460 endif
461 elseif has("unix") || has("macunix")
462 let g:netrw_localmovecmd= "mv"
463 else
464 let g:netrw_localmovecmd= ""
465 endif
466endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100467" following serves as an example for how to insert a version&patch specific test
468"if v:version < 704 || (v:version == 704 && !has("patch1107"))
469"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100470call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
471" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000472if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000473 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000474endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000475if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000476 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
477endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000478" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100479call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
480call s:NetrwInit("g:netrw_maxfilenamelen", 32)
481call s:NetrwInit("g:netrw_menu" , 1)
482call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200483call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100484call s:NetrwInit("g:netrw_retmap" , 0)
485if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
486 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200487elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100488 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
489else
490 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000491endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100492call s:NetrwInit("g:netrw_preview" , 0)
493call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100494call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100495call s:NetrwInit("g:netrw_sshport" , "-p")
496call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
497call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
498call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100499call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
500" Default values - q-s ---------- {{{3
501call s:NetrwInit("g:netrw_quickhelp",0)
502let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100503 \ "(create new) %:file d:directory",
504 \ "(windows split&open) o:horz v:vert p:preview",
505 \ "i:style qf:file info O:obtain r:reverse",
506 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
507 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
508 \ "(history) qb:list u:go up U:go down",
509 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100510" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
511call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100512if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
513 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
514else
515 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
516endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100517call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
518call s:NetrwInit("g:netrw_sort_options" , "")
519call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000520if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100521 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200522 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100523 else
524 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000525 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000526endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100527call s:NetrwInit("g:netrw_special_syntax" , 0)
528call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200529call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100530call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100531call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000532" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100533call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200534if !exists("g:netrw_xstrlen")
535 if exists("g:Align_xstrlen")
536 let g:netrw_xstrlen= g:Align_xstrlen
537 elseif exists("g:drawit_xstrlen")
538 let g:netrw_xstrlen= g:drawit_xstrlen
539 elseif &enc == "latin1" || !has("multi_byte")
540 let g:netrw_xstrlen= 0
541 else
542 let g:netrw_xstrlen= 1
543 endif
544endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100545call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200546call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100547call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200548if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000549" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000550" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100551call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200552if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200553 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200554else
Bram Moolenaarff034192013-04-24 18:51:19 +0200555 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200556endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200557call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100558call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
559call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100560if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100561 let s:treedepthstring= "│ "
562else
563 let s:treedepthstring= "| "
564endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200565call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000566
567" BufEnter event ignored by decho when following variable is true
568" Has a side effect that doau BufReadPost doesn't work, so
569" files read by network transfer aren't appropriately highlighted.
570"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571
Bram Moolenaaradc21822011-04-01 18:03:16 +0200572" ======================
573" Netrw Initialization: {{{1
574" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200575if 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 +0100576" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100577 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200578" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100579 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100580 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
581 au VimEnter * let s:initbeval= &beval
582"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100583" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
584" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
585" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
586" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
587" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
588" 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 +0200589endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200590au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200591
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200592if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100593 com! -nargs=* NetrwKeepj keepj <args>
594else
595 let g:netrw_keepj= ""
596 com! -nargs=* NetrwKeepj <args>
597endif
598
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000599" ==============================
600" Netrw Utility Functions: {{{1
601" ==============================
602
Bram Moolenaaradc21822011-04-01 18:03:16 +0200603" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100604" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100605if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100606" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100607 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100608 if &ft != "netrw"
609 return ""
610 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200611 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
612 " popup error window is still showing
613 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
614 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
615 " text under mouse hasn't changed; only close window when it changes
616 call popup_close(s:popuperr_id)
617 unlet s:popuperr_text
618 else
619 let s:popuperr_text= v:beval_text
620 endif
621 let mesg= ""
622 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 +0100623 let mesg= ""
624 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
625 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
626 elseif getline(v:beval_lnum) =~ '^"\s*/'
627 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
628 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100629 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100630 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
631 let mesg = "S: edit sorting sequence"
632 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
633 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
634 elseif v:beval_text == "Quick" || v:beval_text == "Help"
635 let mesg = "Help: press <F1>"
636 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
637 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
638 else
639 let mesg= ""
640 endif
641 return mesg
642 endfun
643"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100644" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
645" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
646" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
647" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
648" 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 +0200649endif
650
Bram Moolenaar071d4272004-06-13 20:20:40 +0000651" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200652" netrw#Explore: launch the local browser in the directory of the current file {{{2
653" indx: == -1: Nexplore
654" == -2: Pexplore
655" == +: this is overloaded:
656" * If Nexplore/Pexplore is in use, then this refers to the
657" indx'th item in the w:netrw_explore_list[] of items which
658" matched the */pattern **/pattern *//pattern **//pattern
659" * If Hexplore or Vexplore, then this will override
660" g:netrw_winsize to specify the qty of rows or columns the
661" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100662" 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 +0200663" dosplit==1: the window will be split before running the local browser
664" style == 0: Explore style == 1: Explore!
665" == 2: Hexplore style == 3: Hexplore!
666" == 4: Vexplore style == 5: Vexplore!
667" == 6: Texplore
668fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100669" 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 +0100670" 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 +0200671 if !exists("b:netrw_curdir")
672 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100673" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200674 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100675
676 " record current file for Rexplore's benefit
677 if &ft != "netrw"
678 let w:netrw_rexfile= expand("%:p")
679 endif
680
681 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200682 let curdir = simplify(b:netrw_curdir)
683 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200684 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200685 let curdir= substitute(curdir,'\','/','g')
686 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100687" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100688
689 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
690 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
691 " try Explore again.
692 if a:0 > 0
693" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100694 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
695 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
696 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
697 \ '~'.expand("<slnum>"))
698 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200699 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
700 if a1 != a:1
701 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
702 return
703 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100704 endif
705 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200706
707 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200708 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100709" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100710 sil! let keepregstar = @*
711 sil! let keepregplus = @+
712 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200713 sil! let keepregslash= @/
714
Bram Moolenaar8d043172014-01-23 14:24:41 +0100715 " if dosplit
716 " -or- file has been modified AND file not hidden when abandoned
717 " -or- Texplore used
718 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100719" 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 +0200720 call s:SaveWinVars()
721 let winsz= g:netrw_winsize
722 if a:indx > 0
723 let winsz= a:indx
724 endif
725
726 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100727" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200728 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200729 if winsz == 0|let winsz= ""|endif
730 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100731" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200732
733 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100734" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200735 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200736 if winsz == 0|let winsz= ""|endif
737 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100738" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200739
740 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100741" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200742 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200743 if winsz == 0|let winsz= ""|endif
744 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100745" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200746
747 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100748" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200749 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200750 if winsz == 0|let winsz= ""|endif
751 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100752" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200753
754 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100755" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200756 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200757 if winsz == 0|let winsz= ""|endif
758 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100759" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200760
761 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100762" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200763 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200764 if winsz == 0|let winsz= ""|endif
765 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100766" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200767
768 elseif a:style == 6 " Texplore
769 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100770" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200771 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100772" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200773 call s:RestoreBufVars()
774 endif
775 call s:RestoreWinVars()
776" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100777" 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 +0200778 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100779 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200780
781 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100782" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100784" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
790 if dirname !~ '/$'
791 let dirname= dirname."/"
792 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100793" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200794 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200798 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100799" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200800 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100801" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100803" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200804 let dirname= a:1
805 endif
806 else
807 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100808" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200809 call s:NetrwClearExplore()
810" call Dret("netrw#Explore : cleared list")
811 return
812 endif
813
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100814" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200815 if dirname =~ '\.\./\=$'
816 let dirname= simplify(fnamemodify(dirname,':p:h'))
817 elseif dirname =~ '\.\.' || dirname == '.'
818 let dirname= simplify(fnamemodify(dirname,':p'))
819 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100820" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200821
822 if dirname =~ '^\*//'
823 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100824" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200825 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
826 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100827" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200828 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
829
830 elseif dirname =~ '^\*\*//'
831 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100832" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200833 let pattern= substitute(dirname,'^\*\*//','','')
834 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100835" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200836
837 elseif dirname =~ '/\*\*/'
838 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100839" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200840 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200841 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200842 let b:netrw_curdir = prefixdir
843 else
844 let b:netrw_curdir= getcwd().'/'.prefixdir
845 endif
846 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
847 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100848" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
849" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200850
851 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200852 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200853 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100854" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200855
856 elseif dirname=~ '^\*\*/'
857 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
858 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100859" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200860
861 else
862 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100863" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200864 endif
865
866 if starpat == 0 && a:indx >= 0
867 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100868" 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 +0200869 if dirname == ""
870 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100871" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200872 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200873 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200874 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200875 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200876 if dirname == ""
877 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200878 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100879 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100880 " depending on whether backslashes have been converted to forward slashes by earlier code).
881 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200882 let dirname= b:netrw_curdir."/".dirname
883 endif
884 elseif dirname !~ '^/'
885 let dirname= b:netrw_curdir."/".dirname
886 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100887" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200888 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100889" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
890" 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 +0200891 endif
892 if exists("w:netrw_bannercnt")
893 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
894 " If one wants to return the same place in the netrw window, use :Rex instead.
895 exe w:netrw_bannercnt
896 endif
897
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100898" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200899 " ---------------------------------------------------------------------
900 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
901" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100902" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200903" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100904" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200905" endif
906 " ---------------------------------------------------------------------
907
908 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
909 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
910 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
911 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
912 elseif a:indx <= 0
913 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100914" 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 +0200915 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100916" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200917 let s:didstarstar= 1
918 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
919 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
920 endif
921
922 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100923" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200924 if !exists("w:netrw_explore_indx")
925 let w:netrw_explore_indx= 0
926 endif
927
928 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100929" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200930
931 if indx == -1
932 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100933" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200934 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100935 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 +0200936 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100937" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100938 if @* != keepregstar | sil! let @* = keepregstar | endif
939 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100940 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200941 sil! let @/ = keepregslash
942" call Dret("netrw#Explore")
943 return
944 endif
945 let indx= w:netrw_explore_indx
946 if indx < 0 | let indx= 0 | endif
947 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
948 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100949" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200950 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
951 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100952" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200953 endwhile
954 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100955" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200956
957 elseif indx == -2
958 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100959" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200960 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100961 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 +0200962 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100963" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100964 if @* != keepregstar | sil! let @* = keepregstar | endif
965 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100966 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200967 sil! let @/ = keepregslash
968" call Dret("netrw#Explore")
969 return
970 endif
971 let indx= w:netrw_explore_indx
972 if indx < 0 | let indx= 0 | endif
973 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
974 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100975" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200976 while indx >= 0 && curfile == w:netrw_explore_list[indx]
977 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100978" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200979 endwhile
980 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100981" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200982
983 else
984 " Explore -- initialize
985 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100986" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100987 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200988 let w:netrw_explore_indx= 0
989 if !exists("b:netrw_curdir")
990 let b:netrw_curdir= getcwd()
991 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100992" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200993
994 " switch on starpat to build the w:netrw_explore_list of files
995 if starpat == 1
996 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100997" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
998" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200999 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001000 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001001 catch /^Vim\%((\a\+)\)\=:E480/
1002 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1003" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1004 return
1005 endtry
1006 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1007 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1008
1009 elseif starpat == 2
1010 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001011" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1012" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001013 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001014 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001015 catch /^Vim\%((\a\+)\)\=:E480/
1016 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1017 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001018 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001019" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001020 if @* != keepregstar | sil! let @* = keepregstar | endif
1021 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001022 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001023 sil! let @/ = keepregslash
1024" call Dret("netrw#Explore : no files matched pattern")
1025 return
1026 endtry
1027 let s:netrw_curdir = b:netrw_curdir
1028 let w:netrw_explore_list = getqflist()
1029 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1030 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1031
1032 elseif starpat == 3
1033 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001034" 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 +02001035 let filepat= substitute(dirname,'^\*/','','')
1036 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001037" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1038" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001039 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1040 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1041
1042 elseif starpat == 4
1043 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001044" 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 +02001045 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1046 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1047 endif " switch on starpat to build w:netrw_explore_list
1048
1049 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001050" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1051" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001052
1053 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001054 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001055 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001056" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001057 if @* != keepregstar | sil! let @* = keepregstar | endif
1058 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001059 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001060 sil! let @/ = keepregslash
1061" call Dret("netrw#Explore : no files matched")
1062 return
1063 endif
1064 endif " if indx ... endif
1065
1066 " NetrwStatusLine support - for exploring support
1067 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001068" 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 +02001069
1070 " wrap the indx around, but issue a note
1071 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001072" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001073 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1074 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001075 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001076 endif
1077
1078 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001079" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001080 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001081" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001082
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001083" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001084 call netrw#LocalBrowseCheck(newdir)
1085 if !exists("w:netrw_liststyle")
1086 let w:netrw_liststyle= g:netrw_liststyle
1087 endif
1088 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001089 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001090 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001091 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001092 endif
1093 let w:netrw_explore_mtchcnt = indx + 1
1094 let w:netrw_explore_bufnr = bufnr("%")
1095 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001096 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001097" 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 +02001098
1099 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001100" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001101 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001102 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 +02001103 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001104 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001105" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001106 if @* != keepregstar | sil! let @* = keepregstar | endif
1107 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001108 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001109 sil! let @/ = keepregslash
1110" call Dret("netrw#Explore : missing +path_extra")
1111 return
1112 endif
1113
1114 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001115" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001116 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1117 sil! unlet w:netrw_treedict
1118 sil! unlet w:netrw_treetop
1119 endif
1120 let newdir= dirname
1121 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001122 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001123 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001124 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001125 endif
1126 endif
1127
1128 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001129" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1130" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001131 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001132" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001133 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001134 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001135" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001136 let s:explore_prvdir = b:netrw_curdir
1137 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001138 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001139 if b:netrw_curdir !~ '/$'
1140 let dirlen= dirlen + 1
1141 endif
1142 let prvfname= ""
1143 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001144" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001145 if fname =~ '^'.b:netrw_curdir
1146 if s:explore_match == ""
1147 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1148 else
1149 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1150 endif
1151 elseif fname !~ '^/' && fname != prvfname
1152 if s:explore_match == ""
1153 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1154 else
1155 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1156 endif
1157 endif
1158 let prvfname= fname
1159 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001160" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001161 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1162 exe "2match netrwMarkFile /".s:explore_match."/"
1163 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001164 endif
1165 echo "<s-up>==Pexplore <s-down>==Nexplore"
1166 else
1167 2match none
1168 if exists("s:explore_match") | unlet s:explore_match | endif
1169 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001170" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001171 endif
1172
Bram Moolenaara6878372014-03-22 21:02:50 +01001173 " since Explore may be used to initialize netrw's browser,
1174 " there's no danger of a late FocusGained event on initialization.
1175 " Consequently, set s:netrw_events to 2.
1176 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001177 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001178" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001179 if @* != keepregstar | sil! let @* = keepregstar | endif
1180 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001181 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001182 sil! let @/ = keepregslash
1183" call Dret("netrw#Explore : @/<".@/.">")
1184endfun
1185
1186" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001187" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001188" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1189" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1190" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1191" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1192" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001193fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001194" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001195 let curwin= winnr()
1196
Bram Moolenaara6878372014-03-22 21:02:50 +01001197 if a:0 > 0 && a:1 != ""
1198 " if a netrw window is already on the left-side of the tab
1199 " and a directory has been specified, explore with that
1200 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001201" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001202 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001203" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001204 exe "1wincmd w"
1205 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001206" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207 exe "Explore ".fnameescape(a1)
1208 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001209 let s:lexplore_win= curwin
1210 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001211 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001212" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001213 unlet t:netrw_lexposn
1214 endif
1215" call Dret("netrw#Lexplore")
1216 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001217 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001218 exe curwin."wincmd w"
1219 else
1220 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001221" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001222 endif
1223
Bram Moolenaar8d043172014-01-23 14:24:41 +01001224 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001225 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001226 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001227" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001228 else
1229 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001230" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001231 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001232" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001233
1234 if lexwinnr > 0
1235 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001236" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001237 exe lexwinnr."wincmd w"
1238 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001239 let t:netrw_lexposn = winsaveview()
1240" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001241" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001242 close
1243 if lexwinnr < curwin
1244 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001245 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001246 if lexwinnr != curwin
1247 exe curwin."wincmd w"
1248 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001249 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001250" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001251
1252 else
1253 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001254" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001255 exe "1wincmd w"
1256 let keep_altv = g:netrw_altv
1257 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001258 if a:count != 0
1259 let netrw_winsize = g:netrw_winsize
1260 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001261 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001262 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001263" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001264 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 +02001265" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001267" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001268 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001269 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001270 elseif curfile =~ '^\a\{3,}://'
1271" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001272 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001273 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001274" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001275 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001276 endif
1277 if a:count != 0
1278 let g:netrw_winsize = netrw_winsize
1279 endif
1280 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001281 let g:netrw_altv = keep_altv
1282 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001283 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1284 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001285 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001286 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001287" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1288" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001289 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001290" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001291" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1292 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001293 unlet t:netrw_lexposn
1294 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001295 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001296
1297 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001298 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001299 if a:rightside
1300 let g:netrw_chgwin= 1
1301 else
1302 let g:netrw_chgwin= 2
1303 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001304" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001305 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001306
Bram Moolenaar8d043172014-01-23 14:24:41 +01001307" call Dret("netrw#Lexplore")
1308endfun
1309
1310" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001311" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001312" supports :NetrwClean -- remove netrw from first directory on runtimepath
1313" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001314fun! netrw#Clean(sys)
1315" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001316
1317 if a:sys
1318 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1319 else
1320 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1321 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001322" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001323 let diddel= 0
1324 let diddir= ""
1325
1326 if choice == 1
1327 for dir in split(&rtp,',')
1328 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001329" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001330 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1331 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1332 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1333 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1334 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1335 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 +00001336 let diddir= dir
1337 let diddel= diddel + 1
1338 if !a:sys|break|endif
1339 endif
1340 endfor
1341 endif
1342
1343 echohl WarningMsg
1344 if diddel == 0
1345 echomsg "netrw is either not installed or not removable"
1346 elseif diddel == 1
1347 echomsg "removed one copy of netrw from <".diddir.">"
1348 else
1349 echomsg "removed ".diddel." copies of netrw"
1350 endif
1351 echohl None
1352
Bram Moolenaara6878372014-03-22 21:02:50 +01001353" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001354endfun
1355
Bram Moolenaar5c736222010-01-06 20:54:52 +01001356" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001357" netrw#MakeTgt: make a target out of the directory name provided {{{2
1358fun! netrw#MakeTgt(dname)
1359" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1360 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001361 let svpos = winsaveview()
1362" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001363 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1364" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001365 if s:netrwmftgt_islocal
1366 let netrwmftgt= simplify(a:dname)
1367 else
1368 let netrwmftgt= a:dname
1369 endif
1370 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1371 " re-selected target, so just clear it
1372 unlet s:netrwmftgt s:netrwmftgt_islocal
1373 else
1374 let s:netrwmftgt= netrwmftgt
1375 endif
1376 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001377 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001378 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001379" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1380 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001381" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001382endfun
1383
Bram Moolenaara6878372014-03-22 21:02:50 +01001384" ---------------------------------------------------------------------
1385" netrw#Obtain: {{{2
1386" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001387" islocal=0 obtain from remote source
1388" =1 obtain from local source
1389" fname : a filename or a list of filenames
1390" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001391fun! netrw#Obtain(islocal,fname,...)
1392" 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 +02001393 " NetrwStatusLine support - for obtaining support
1394
1395 if type(a:fname) == 1
1396 let fnamelist= [ a:fname ]
1397 elseif type(a:fname) == 3
1398 let fnamelist= a:fname
1399 else
1400 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 +01001401" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001402 return
1403 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001404" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001405 if a:0 > 0
1406 let tgtdir= a:1
1407 else
1408 let tgtdir= getcwd()
1409 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001410" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001411
1412 if exists("b:netrw_islocal") && b:netrw_islocal
1413 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001414" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001415 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1416 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001417 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001418 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001419" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001420 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001421" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001422 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001423 if v:shell_error != 0
1424 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 +01001425" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001426 return
1427 endif
1428 endfor
1429 else
1430 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001431" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1432 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1433" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001434 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001435 if v:shell_error != 0
1436 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 +01001437" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001438 return
1439 endif
1440 endif
1441 elseif !exists("b:netrw_curdir")
1442 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1443 else
1444 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1445 endif
1446
1447 else
1448 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001449" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001450 if type(a:fname) == 1
1451 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1452 endif
1453 call s:NetrwMethod(b:netrw_curdir)
1454
1455 if b:netrw_method == 4
1456 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001457" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001458 if exists("g:netrw_port") && g:netrw_port != ""
1459 let useport= " ".g:netrw_scpport." ".g:netrw_port
1460 else
1461 let useport= ""
1462 endif
1463 if b:netrw_fname =~ '/'
1464 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1465 else
1466 let path= ""
1467 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001468 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001469 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 +02001470
1471 elseif b:netrw_method == 2
1472 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001473" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001474 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001475 let tmpbufnr= bufnr("%")
1476 setl ff=unix
1477 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001478 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001479" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001480 endif
1481
1482 if exists("b:netrw_fname") && b:netrw_fname != ""
1483 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001484" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001485 endif
1486
1487 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001488 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001489" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001490 endif
1491 for fname in fnamelist
1492 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001493" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001494 endfor
1495 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001496 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 +02001497 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001498 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001499 endif
1500 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1501 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1502 let debugkeep= &debug
1503 setl debug=msg
1504 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1505 let &debug= debugkeep
1506 endif
1507
1508 elseif b:netrw_method == 3
1509 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001510" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001511 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001512 let tmpbufnr= bufnr("%")
1513 setl ff=unix
1514
1515 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001516 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001517" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001518 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001519 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001520" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001521 endif
1522
1523 if exists("g:netrw_uid") && g:netrw_uid != ""
1524 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001525 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001526" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001527 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001528 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001529 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001530" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001531 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001532 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001533" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001534 endif
1535 endif
1536
1537 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001538 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001539" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001540 endif
1541
1542 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001543 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001544" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001545 endif
1546
1547 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001548 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001549" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001550 endif
1551
1552 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001553 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001554" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001555 endif
1556 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001557 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001558 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001559" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001560
1561 " perform ftp:
1562 " -i : turns off interactive prompting from ftp
1563 " -n unix : DON'T use <.netrc>, even though it exists
1564 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001565 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1566 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001567 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001568 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1569 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001570" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001571 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001572 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001573 endif
1574 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001575
1576 elseif b:netrw_method == 9
1577 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001578" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001579 if a:fname =~ '/'
1580 let localfile= substitute(a:fname,'^.*/','','')
1581 else
1582 let localfile= a:fname
1583 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001584 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 +02001585
Bram Moolenaarff034192013-04-24 18:51:19 +02001586 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001587 " probably a badly formed url; protocol not recognized
1588" call Dret("netrw#Obtain : unsupported method")
1589 return
1590
1591 else
1592 " protocol recognized but not supported for Obtain (yet?)
1593 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001594 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001595 endif
1596" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001597 return
1598 endif
1599
1600 " restore status line
1601 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001602 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001603 endif
1604
1605 endif
1606
1607 " cleanup
1608 if exists("tmpbufnr")
1609 if bufnr("%") != tmpbufnr
1610 exe tmpbufnr."bw!"
1611 else
1612 q!
1613 endif
1614 endif
1615
Bram Moolenaara6878372014-03-22 21:02:50 +01001616" call Dret("netrw#Obtain")
1617endfun
1618
1619" ---------------------------------------------------------------------
1620" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1621fun! netrw#Nread(mode,fname)
1622" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001623 let svpos= winsaveview()
1624" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001625 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001626" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1627 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001628
1629 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1630 if exists("w:netrw_bannercnt")
1631 " start with cursor just after the banner
1632 exe w:netrw_bannercnt
1633 endif
1634 endif
1635" call Dret("netrw#Nread")
1636endfun
1637
1638" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001639" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1640" Options get restored by s:NetrwOptionsRestore()
1641"
1642" Option handling:
1643" * save user's options (s:NetrwOptionsSave)
1644" * set netrw-safe options (s:NetrwOptionsSafe)
1645" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1646" * restore user's options (s:netrwOPtionsRestore)
1647" - restore a user option when != safe option (s:NetrwRestoreSetting)
1648" vt: (variable type) normally its either "w:" or "s:"
1649fun! s:NetrwOptionsSave(vt)
1650" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1651" 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 +02001652" 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>"))
1653" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001654
1655 if !exists("{a:vt}netrw_optionsave")
1656 let {a:vt}netrw_optionsave= 1
1657 else
1658" call Dret("s:NetrwOptionsSave : options already saved")
1659 return
1660 endif
1661" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1662
1663 " Save current settings and current directory
1664" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1665 let s:yykeep = @@
1666 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1667 let {a:vt}netrw_aikeep = &l:ai
1668 let {a:vt}netrw_awkeep = &l:aw
1669 let {a:vt}netrw_bhkeep = &l:bh
1670 let {a:vt}netrw_blkeep = &l:bl
1671 let {a:vt}netrw_btkeep = &l:bt
1672 let {a:vt}netrw_bombkeep = &l:bomb
1673 let {a:vt}netrw_cedit = &cedit
1674 let {a:vt}netrw_cikeep = &l:ci
1675 let {a:vt}netrw_cinkeep = &l:cin
1676 let {a:vt}netrw_cinokeep = &l:cino
1677 let {a:vt}netrw_comkeep = &l:com
1678 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001679 let {a:vt}netrw_cuckeep = &l:cuc
1680 let {a:vt}netrw_culkeep = &l:cul
1681" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001682 let {a:vt}netrw_diffkeep = &l:diff
1683 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001684 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1685 let {a:vt}netrw_ffkeep = &l:ff
1686 endif
1687 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1688 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001689 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001690 let {a:vt}netrw_hidkeep = &l:hidden
1691 let {a:vt}netrw_imkeep = &l:im
1692 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001693 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001694 let {a:vt}netrw_lskeep = &l:ls
1695 let {a:vt}netrw_makeep = &l:ma
1696 let {a:vt}netrw_magickeep = &l:magic
1697 let {a:vt}netrw_modkeep = &l:mod
1698 let {a:vt}netrw_nukeep = &l:nu
1699 let {a:vt}netrw_rnukeep = &l:rnu
1700 let {a:vt}netrw_repkeep = &l:report
1701 let {a:vt}netrw_rokeep = &l:ro
1702 let {a:vt}netrw_selkeep = &l:sel
1703 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001704 if !g:netrw_use_noswf
1705 let {a:vt}netrw_swfkeep = &l:swf
1706 endif
1707 let {a:vt}netrw_tskeep = &l:ts
1708 let {a:vt}netrw_twkeep = &l:tw " textwidth
1709 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1710 let {a:vt}netrw_wrapkeep = &l:wrap
1711 let {a:vt}netrw_writekeep = &l:write
1712
1713 " save a few selected netrw-related variables
1714" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1715 if g:netrw_keepdir
1716 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001717" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001718 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001719 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001720 sil! let {a:vt}netrw_starkeep = @*
1721 sil! let {a:vt}netrw_pluskeep = @+
1722 endif
1723 sil! let {a:vt}netrw_slashkeep= @/
1724
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001725" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001726" 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>"))
1727" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1728endfun
1729
1730" ---------------------------------------------------------------------
1731" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1732" Use s:NetrwSaveOptions() to save user settings
1733" Use s:NetrwOptionsRestore() to restore user settings
1734fun! s:NetrwOptionsSafe(islocal)
1735" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1736" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1737" 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>"))
1738 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1739 call s:NetrwSetSafeSetting("&l:ai",0)
1740 call s:NetrwSetSafeSetting("&l:aw",0)
1741 call s:NetrwSetSafeSetting("&l:bl",0)
1742 call s:NetrwSetSafeSetting("&l:bomb",0)
1743 if a:islocal
1744 call s:NetrwSetSafeSetting("&l:bt","nofile")
1745 else
1746 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1747 endif
1748 call s:NetrwSetSafeSetting("&l:ci",0)
1749 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001750 if g:netrw_fastbrowse > a:islocal
1751 call s:NetrwSetSafeSetting("&l:bh","hide")
1752 else
1753 call s:NetrwSetSafeSetting("&l:bh","delete")
1754 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001755 call s:NetrwSetSafeSetting("&l:cino","")
1756 call s:NetrwSetSafeSetting("&l:com","")
1757 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1758 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1759 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001760 if &go =~ 'a' | set go-=a | endif
1761 if &go =~ 'A' | set go-=A | endif
1762 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001763 call s:NetrwSetSafeSetting("&l:hid",0)
1764 call s:NetrwSetSafeSetting("&l:im",0)
1765 setl isk+=@ isk+=* isk+=/
1766 call s:NetrwSetSafeSetting("&l:magic",1)
1767 if g:netrw_use_noswf
1768 call s:NetrwSetSafeSetting("swf",0)
1769 endif
1770 call s:NetrwSetSafeSetting("&l:report",10000)
1771 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1772 call s:NetrwSetSafeSetting("&l:spell",0)
1773 call s:NetrwSetSafeSetting("&l:tw",0)
1774 call s:NetrwSetSafeSetting("&l:wig","")
1775 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001776
1777 " set up cuc and cul based on g:netrw_cursor and listing style
1778 " COMBAK -- cuc cul related
1779 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001780
1781 " allow the user to override safe options
1782" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1783 if &ft == "netrw"
1784" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1785 keepalt NetrwKeepj doau FileType netrw
1786 endif
1787
1788" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1789" 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>"))
1790" call Dret("s:NetrwOptionsSafe")
1791endfun
1792
1793" ---------------------------------------------------------------------
1794" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1795fun! s:NetrwOptionsRestore(vt)
1796" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001797" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001798" 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 +01001799 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001800" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001801
1802 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1803 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001804" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001805 filetype detect
1806" 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>"))
1807 else
1808 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001809 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001810" 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 +02001811" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001812 return
1813 endif
1814 unlet {a:vt}netrw_optionsave
1815
1816 if exists("+acd")
1817 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001818" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001819 let curdir = getcwd()
1820 let &l:acd = {a:vt}netrw_acdkeep
1821 unlet {a:vt}netrw_acdkeep
1822 if &l:acd
1823 call s:NetrwLcd(curdir)
1824 endif
1825 endif
1826 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001827" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001828 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1829 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1830 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1831 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1832 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001833" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001834 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1835 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1836 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1837 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1838 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001839" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001840 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1841 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1842 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1843 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1844 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001845 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001846" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1847 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1848 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001849 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001850 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1851" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1852 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1853 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1854" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1855 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1856" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1857 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1858 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001859 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001860 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1861 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1862" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1863 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1864 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1865 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1866 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1867" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001868 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001869 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1870 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1871 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001872 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001873" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001874 call s:NetrwRestoreSetting("s:yykeep","@@")
1875 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1876 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1877 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1878 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1879
Bram Moolenaara6878372014-03-22 21:02:50 +01001880 if exists("{a:vt}netrw_swfkeep")
1881 if &directory == ""
1882 " user hasn't specified a swapfile directory;
1883 " netrw will temporarily set the swapfile directory
1884 " to the current directory as returned by getcwd().
1885 let &l:directory= getcwd()
1886 sil! let &l:swf = {a:vt}netrw_swfkeep
1887 setl directory=
1888 unlet {a:vt}netrw_swfkeep
1889 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001890 if !g:netrw_use_noswf
1891 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1892 sil! let &l:swf= {a:vt}netrw_swfkeep
1893 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001894 unlet {a:vt}netrw_swfkeep
1895 endif
1896 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001897 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001898 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1899 if exists("{a:vt}netrw_dirkeep")
1900 call s:NetrwLcd(dirkeep)
1901 unlet {a:vt}netrw_dirkeep
1902 endif
1903 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001904 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001905" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001906 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1907 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001908 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001909 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001910
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001911" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1912" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1913" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1914" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1915" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001916 " Moved the filetype detect here from NetrwGetFile() because remote files
1917 " were having their filetype detect-generated settings overwritten by
1918 " NetrwOptionRestore.
1919 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001920" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1921 filetype detect
1922" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001923 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001924" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001925" 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 +02001926" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001927endfun
1928
1929" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001930" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1931" but only when the options' value and the safe setting differ
1932" Doing this means that netrw will not come up as having changed a
1933" setting last when it really didn't actually change it.
1934"
1935" Called from s:NetrwOptionsSafe
1936" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1937fun! s:NetrwSetSafeSetting(setting,safesetting)
1938" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001939
Bram Moolenaar85850f32019-07-19 22:05:51 +02001940 if a:setting =~ '^&'
1941" call Decho("fyi: a:setting starts with &")
1942 exe "let settingval= ".a:setting
1943" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001944
Bram Moolenaar85850f32019-07-19 22:05:51 +02001945 if settingval != a:safesetting
1946" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1947 if type(a:safesetting) == 0
1948 exe "let ".a:setting."=".a:safesetting
1949 elseif type(a:safesetting) == 1
1950 exe "let ".a:setting."= '".a:safesetting."'"
1951 else
1952 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1953 endif
1954 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001955 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001956
Bram Moolenaar85850f32019-07-19 22:05:51 +02001957" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001958endfun
1959
1960" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001961" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1962" but only if the setting value differs from the associated keepvar.
1963" Doing this means that netrw will not come up as having changed a
1964" setting last when it really didn't actually change it.
1965"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001966" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001967" keepvars are set up by s:NetrwOptionsSave
1968fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001969""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001970
Bram Moolenaar85850f32019-07-19 22:05:51 +02001971 " typically called from s:NetrwOptionsRestore
1972 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1973 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001974 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001975 if exists(a:keepvar)
1976 exe "let keepvarval= ".a:keepvar
1977 exe "let setting= ".a:setting
1978
1979"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1980"" call Decho("fyi: keepvarval=".keepvarval)
1981"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1982
1983 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001984"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001985 if type(a:setting) == 0
1986 exe "let ".a:setting."= ".keepvarval
1987 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001988 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001989 else
1990 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1991 endif
1992 endif
1993
1994 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001995 endif
1996
Bram Moolenaar85850f32019-07-19 22:05:51 +02001997"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001998endfun
1999
2000" ---------------------------------------------------------------------
2001" NetrwStatusLine: {{{2
2002fun! NetrwStatusLine()
2003
2004" vvv NetrwStatusLine() debugging vvv
2005" let g:stlmsg=""
2006" if !exists("w:netrw_explore_bufnr")
2007" let g:stlmsg="!X<explore_bufnr>"
2008" elseif w:netrw_explore_bufnr != bufnr("%")
2009" let g:stlmsg="explore_bufnr!=".bufnr("%")
2010" endif
2011" if !exists("w:netrw_explore_line")
2012" let g:stlmsg=" !X<explore_line>"
2013" elseif w:netrw_explore_line != line(".")
2014" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2015" endif
2016" if !exists("w:netrw_explore_list")
2017" let g:stlmsg=" !X<explore_list>"
2018" endif
2019" ^^^ NetrwStatusLine() debugging ^^^
2020
2021 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")
2022 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002023 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002024 let &laststatus = s:netrw_users_ls
2025 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2026 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2027 return ""
2028 else
2029 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2030 endif
2031endfun
2032
Bram Moolenaar85850f32019-07-19 22:05:51 +02002033" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002034" Netrw Transfer Functions: {{{1
2035" ===============================
2036
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002038" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002039" mode: =0 read remote file and insert before current line
2040" =1 read remote file and insert after current line
2041" =2 replace with remote file
2042" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002043fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002044" 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 +00002045
Bram Moolenaar5c736222010-01-06 20:54:52 +01002046 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002047 call s:NetrwOptionsSave("w:")
2048 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002049 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002050 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2051 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2052 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002053" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002054
Bram Moolenaar5c736222010-01-06 20:54:52 +01002055 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002057 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002058 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002059 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002060 elseif a:mode == 2 " replace with remote file
2061 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002062 elseif a:mode == 3 " skip read of file (leave as temporary)
2063 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002064 else
2065 exe a:mode
2066 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002067 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002068 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002069" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002070
Bram Moolenaar5c736222010-01-06 20:54:52 +01002071 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002072 let tmpfile= s:GetTempfile("")
2073 if tmpfile == ""
2074" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002075 return
2076 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002077
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002078 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002079
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002080 " attempt to repeat with previous host-file-etc
2081 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002082" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002083 let choice = b:netrw_lastfile
2084 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002085
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002086 else
2087 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002088" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002089
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002090 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002091 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002092 echomsg 'NetRead Usage:'
2093 echomsg ':Nread machine:path uses rcp'
2094 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2095 echomsg ':Nread "machine id password path" uses ftp'
2096 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2097 echomsg ':Nread fetch://machine/path uses fetch'
2098 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2099 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002100 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002101 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002102 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2103 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2104 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2105 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002106 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002107 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002108
Bram Moolenaar9964e462007-05-05 17:54:07 +00002109 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002110 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002111" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002112 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002113 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002114 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002115 else
2116 " case "... ... ..."
2117 let choice = strpart(choice,1,strlen(choice)-1)
2118 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002119
Bram Moolenaar9964e462007-05-05 17:54:07 +00002120 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002121 let wholechoice = wholechoice . " " . choice
2122 let ichoice = ichoice + 1
2123 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002124 if !exists("g:netrw_quiet")
2125 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2126 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002127" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002128 return
2129 endif
2130 let choice= a:{ichoice}
2131 endwhile
2132 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2133 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134 endif
2135 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002137" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002138 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002139
Bram Moolenaar5c736222010-01-06 20:54:52 +01002140 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002141 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002142 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002143" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002144 return
2145 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002146 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002147
Bram Moolenaar8d043172014-01-23 14:24:41 +01002148 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002149" 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 +02002150 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002151" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002152 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002153" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002154 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002155 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002156
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002157 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002158 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002159 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002160 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2161 echo "(netrw) Processing your read request..."
2162 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002163
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002164 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002165 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002167" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002168 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002169 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002170 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002171 " ER: the tmpfile is full path: rcp sees C:\... as host C
2172 if s:netrw_has_nt_rcp == 1
2173 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2174 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2175 else
2176 " Any way needed it machine contains a '.'
2177 let uid_machine = g:netrw_machine .'.'. $USERNAME
2178 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002180 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2181 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2182 else
2183 let uid_machine = g:netrw_machine
2184 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002185 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002186 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 +00002187 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002188 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002189
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002190 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002191 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002192 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002193" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002194 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002195 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002196 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002197 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002198 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002199" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002200 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002201 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002202" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002203 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002204 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002206 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002207 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 +00002208 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002209 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002210 endif
2211 " 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 +00002212 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002213 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002214 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002215 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002216 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002217 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002218 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002219 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002220 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2221 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002222 q!
2223 endif
2224 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002225 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002227
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002229 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2231 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002232" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002233 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002234 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002235 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002236 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002237 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002238 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002239" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002240 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002241 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002242" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002243 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002244
Bram Moolenaar97d62492012-11-15 21:28:22 +01002245 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002246 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002247 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002248" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002249 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002250 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002251 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002252" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002253 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002254 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002255" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002256 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002257 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002258
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002259 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002260 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002261" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002262 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002263 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002264 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002265" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002266 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002267 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002268" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002269
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002270 " perform ftp:
2271 " -i : turns off interactive prompting from ftp
2272 " -n unix : DON'T use <.netrc>, even though it exists
2273 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002274 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002275 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002276 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2277 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002278" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002279 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002280 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002281 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002283 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002284 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002285 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002286
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002287 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002288 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002289 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002290" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002291 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002292 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002293 else
2294 let useport= ""
2295 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002296 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2297 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002298 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002299 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2300 else
2301 let tmpfile_get = tmpfile
2302 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002303 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 +00002304 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002305 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002306
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002307 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002308 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002309 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002310" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002311 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002312 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002313 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002314 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002315" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002316 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002317 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002318
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002319 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2320 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002321" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002322 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002323 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 +00002324 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002325 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 +00002326 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002327 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002328
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002329 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002330 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002331" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002332 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2333 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002334" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2335" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2336 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 +00002337 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002338" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002339 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002340 endif
2341 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002342" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002343 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002344
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002345 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002346 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002347 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002348" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002349
Bram Moolenaar5c736222010-01-06 20:54:52 +01002350 if !executable(g:netrw_dav_cmd)
2351 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2352" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2353 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002354 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002355 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002356 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 +01002357 else
2358 " Construct execution string (four lines) which will be passed through filter
2359 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2360 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002361 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002362 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002363 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002364 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002365 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002366 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002367 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002368 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002369 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002370 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2371 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002372
Bram Moolenaar5c736222010-01-06 20:54:52 +01002373 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002374 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002375 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002376 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002377 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002378 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002379 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002380
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002381 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002382 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002383 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002384" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002385 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 +00002386 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002388
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002390 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002392 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002393" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002394 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002395 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002396 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002397 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002398" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002399 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002400 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002401 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002402 let netrw_option= "http"
2403 else
2404 let netrw_option= "ftp"
2405 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002406" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002407
Bram Moolenaar446cb832008-06-24 21:56:24 +00002408 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002409 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 +00002410 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002411 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 +00002412 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002413
Bram Moolenaar446cb832008-06-24 21:56:24 +00002414 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002415 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002416" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002417 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002418
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002419 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002420 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002421 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002422" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2423 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 +00002424 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002425 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002426
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002427 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002428 " NetRead: (file) NetRead Method #10 {{{3
2429 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002430" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2431 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002432 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2433 let b:netrw_lastfile = choice
2434
2435 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002436 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002437 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002438 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002439 endif
2440 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002441
Bram Moolenaar5c736222010-01-06 20:54:52 +01002442 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002443 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002444" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002445 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002446 unlet b:netrw_fname
2447 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002448 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 +01002449" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002450 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002451 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002452 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002453
Bram Moolenaar9964e462007-05-05 17:54:07 +00002454" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002455endfun
2456
2457" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002458" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002459fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002460" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002461
Bram Moolenaar5c736222010-01-06 20:54:52 +01002462 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002463 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002464 call s:NetrwOptionsSave("w:")
2465 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002466
Bram Moolenaar5c736222010-01-06 20:54:52 +01002467 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002468 let tmpfile= s:GetTempfile("")
2469 if tmpfile == ""
2470" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002471 return
2472 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002473
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002474 if a:0 == 0
2475 let ichoice = 0
2476 else
2477 let ichoice = 1
2478 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002479
Bram Moolenaar9964e462007-05-05 17:54:07 +00002480 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002481" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002482 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002483 " For binary writes, always write entire file.
2484 " (line numbers don't really make sense for that).
2485 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002486" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002487 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002488 elseif g:netrw_cygwin
2489 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002490 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002491" 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 +01002492 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002493 else
2494 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002495" 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 +01002496 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002497 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002498
Bram Moolenaar9964e462007-05-05 17:54:07 +00002499 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002500 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002501 " on the temporary file's name. Deletion of the temporary file during
2502 " cleanup then causes an error message.
2503 0file!
2504 endif
2505
Bram Moolenaar5c736222010-01-06 20:54:52 +01002506 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002507 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002508
Bram Moolenaar9964e462007-05-05 17:54:07 +00002509 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002510 " attempt to repeat with previous host-file-etc
2511 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002512" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002513 let choice = b:netrw_lastfile
2514 let ichoice= ichoice + 1
2515 else
2516 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002517
Bram Moolenaar8d043172014-01-23 14:24:41 +01002518 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002519 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002520 echomsg 'NetWrite Usage:"'
2521 echomsg ':Nwrite machine:path uses rcp'
2522 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2523 echomsg ':Nwrite "machine id password path" uses ftp'
2524 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2525 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2526 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2527 echomsg ':Nwrite rcp://machine/path uses rcp'
2528 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2529 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2530 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002531 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002532 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002533
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002534 elseif match(choice,"^\"") != -1
2535 if match(choice,"\"$") != -1
2536 " case "..."
2537 let choice=strpart(choice,1,strlen(choice)-2)
2538 else
2539 " case "... ... ..."
2540 let choice = strpart(choice,1,strlen(choice)-1)
2541 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002542
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002543 while match(choice,"\"$") == -1
2544 let wholechoice= wholechoice . " " . choice
2545 let ichoice = ichoice + 1
2546 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002547 if !exists("g:netrw_quiet")
2548 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2549 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002550" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002551 return
2552 endif
2553 let choice= a:{ichoice}
2554 endwhile
2555 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2556 endif
2557 endif
2558 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002559 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002560" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002561
Bram Moolenaar9964e462007-05-05 17:54:07 +00002562 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002563 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002564 if !exists("b:netrw_method") || b:netrw_method < 0
2565" call Dfunc("netrw#NetWrite : unsupported method")
2566 return
2567 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002568
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002569 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002570 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002571 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002572 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2573 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002574" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002575 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002576
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002577 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002578 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002579 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002580" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002581 if s:netrw_has_nt_rcp == 1
2582 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2583 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2584 else
2585 let uid_machine = g:netrw_machine .'.'. $USERNAME
2586 endif
2587 else
2588 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2589 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2590 else
2591 let uid_machine = g:netrw_machine
2592 endif
2593 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002594 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 +00002595 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002596
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002597 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002598 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002599 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002600" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002601 let netrw_fname = b:netrw_fname
2602
2603 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2604 let bhkeep = &l:bh
2605 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002606 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002607 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002608
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002610 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002611 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002612" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002613 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002614 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002615" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002616 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002617 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002618" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002620 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 +00002621 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002622" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2623 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 endif
2625 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2626 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002627 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002628 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002629 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002630 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002632
2633 " remove enew buffer (quietly)
2634 let filtbuf= bufnr("%")
2635 exe curbuf."b!"
2636 let &l:bh = bhkeep
2637 exe filtbuf."bw!"
2638
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002640
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002641 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002642 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002643 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002644 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002645" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002646 let netrw_fname = b:netrw_fname
2647 let bhkeep = &l:bh
2648
2649 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2650 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002651 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002652 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002653 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002654
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002655 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002656 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002657" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002658 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002659 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002660" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002661 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002662 if exists("g:netrw_uid") && g:netrw_uid != ""
2663 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002664 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002665" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002666 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002667 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002668 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002669" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002670 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002671 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002672" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002673 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002674 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002675 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002676" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002677 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002678 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002679" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002680 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002681 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002682" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002683 " save choice/id/password for future use
2684 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002685
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002686 " perform ftp:
2687 " -i : turns off interactive prompting from ftp
2688 " -n unix : DON'T use <.netrc>, even though it exists
2689 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002690 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002691 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002692 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2693 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002694 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002695 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002696 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002697 let mod=1
2698 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002699
2700 " remove enew buffer (quietly)
2701 let filtbuf= bufnr("%")
2702 exe curbuf."b!"
2703 let &l:bh= bhkeep
2704 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002705
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002706 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002707 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002708 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002709" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002710 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002711 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002712 else
2713 let useport= ""
2714 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002715 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 +00002716 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002717
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002718 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002719 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002720 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002721" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002722 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2723 if executable(curl)
2724 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002725 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 +01002726 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002727 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002728 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002729
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002730 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002731 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002732 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002733" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002734
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002735 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002736 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2737 let bhkeep = &l:bh
2738
2739 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2740 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002741 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002742 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002743
Bram Moolenaarff034192013-04-24 18:51:19 +02002744 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002745 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002746 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002747 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002748 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002749 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002750 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002751 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002752 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002753 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002754
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002755 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002756 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002757 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002758
2759 " remove enew buffer (quietly)
2760 let filtbuf= bufnr("%")
2761 exe curbuf."b!"
2762 let &l:bh = bhkeep
2763 exe filtbuf."bw!"
2764
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002765 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002766
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002767 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002768 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002769 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002770" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002771 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 +00002772 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002773
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002774 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002775 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002776 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002777" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002778 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2780 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2781 else
2782 let uid_machine = g:netrw_machine
2783 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002784
2785 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2786 let bhkeep = &l:bh
2787 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002788 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002789 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002790
Bram Moolenaarff034192013-04-24 18:51:19 +02002791 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002792 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002793" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002794 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002795 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002796 let filtbuf= bufnr("%")
2797 exe curbuf."b!"
2798 let &l:bh = bhkeep
2799 exe filtbuf."bw!"
2800 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002801
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002802 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002803 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002804 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002805 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002806 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002807 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002808 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002809
Bram Moolenaar5c736222010-01-06 20:54:52 +01002810 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002811" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002812 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002813" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002814 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002815 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002816 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002817
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002818 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002819 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002820 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002821" 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 +02002822 elseif !exists("leavemod")
2823 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002824" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002825 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002826" 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 +00002827 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002828
Bram Moolenaar9964e462007-05-05 17:54:07 +00002829" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002830endfun
2831
2832" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002833" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002834" uses NetRead to get a copy of the file into a temporarily file,
2835" then sources that file,
2836" then removes that file.
2837fun! netrw#NetSource(...)
2838" call Dfunc("netrw#NetSource() a:0=".a:0)
2839 if a:0 > 0 && a:1 == '?'
2840 " give help
2841 echomsg 'NetSource Usage:'
2842 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2843 echomsg ':Nsource fetch://machine/path uses fetch'
2844 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002845 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002846 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2847 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2848 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2849 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2850 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002851 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002852 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002853 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002854 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002855" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002856 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002857" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002858 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002859" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002860 if delete(s:netrw_tmpfile)
2861 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2862 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002863 unlet s:netrw_tmpfile
2864 else
2865 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2866 endif
2867 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002868 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002869 endif
2870" call Dret("netrw#NetSource")
2871endfun
2872
Bram Moolenaar8d043172014-01-23 14:24:41 +01002873" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002874" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2875" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002876fun! netrw#SetTreetop(iscmd,...)
2877" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2878" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002879
Bram Moolenaar85850f32019-07-19 22:05:51 +02002880 " iscmd==0: netrw#SetTreetop called using gn mapping
2881 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2882" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002883 " clear out the current tree
2884 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002885" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002886 let inittreetop= w:netrw_treetop
2887 unlet w:netrw_treetop
2888 endif
2889 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002890" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002891 unlet w:netrw_treedict
2892 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002893" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002894
Bram Moolenaar85850f32019-07-19 22:05:51 +02002895 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002896 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002897" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002898 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002899 if isdirectory(s:NetrwFile(a:1))
2900" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002901 let treedir = a:1
2902 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002903 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002904 let treedir = b:netrw_curdir."/".a:1
2905 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002906" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002907 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002908 " normally the cursor is left in the message window.
2909 " However, here this results in the directory being listed in the message window, which is not wanted.
2910 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002911 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002912 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002913 let treedir = "."
2914 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002915 endif
2916 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002917" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002918
2919 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002920 let islocal= expand("%") !~ '^\a\{3,}://'
2921" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002922
2923 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002924 if islocal
2925 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2926 else
2927 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2928 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002929
Bram Moolenaara6878372014-03-22 21:02:50 +01002930" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002931endfun
2932
Bram Moolenaar9964e462007-05-05 17:54:07 +00002933" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002934" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002935" readcmd == %r : replace buffer with newly read file
2936" == 0r : read file at top of buffer
2937" == r : read file after current line
2938" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002939fun! s:NetrwGetFile(readcmd, tfile, method)
2940" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002941
2942 " readcmd=='t': simply do nothing
2943 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002944" 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 +01002945" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002946 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002947 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002948
Bram Moolenaar9964e462007-05-05 17:54:07 +00002949 " get name of remote filename (ie. url and all)
2950 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002951" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002952
Bram Moolenaar9964e462007-05-05 17:54:07 +00002953 if exists("*NetReadFixup")
2954 " for the use of NetReadFixup (not otherwise used internally)
2955 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002956 endif
2957
Bram Moolenaar9964e462007-05-05 17:54:07 +00002958 if a:readcmd[0] == '%'
2959 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002960" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002961
2962 " rename the current buffer to the temp file (ie. tfile)
2963 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002964 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002965 else
2966 let tfile= a:tfile
2967 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002968 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002969
2970 " edit temporary file (ie. read the temporary file in)
2971 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002972" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002973 call zip#Browse(tfile)
2974 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002975" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002976 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002977 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002978" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002979 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002980 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002981" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002982 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002983 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002984" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002985 call tar#Browse(tfile)
2986 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002987" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002988 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002989 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002990" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002991 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002992 endif
2993
2994 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002995 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002996
Bram Moolenaar71badf92023-04-22 22:40:14 +01002997 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002998 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002999 " Note that isk must not include a "/" for scripts.vim
3000 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01003001" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
3002" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003003" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003004" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3005 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003006 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003007 filetype detect
3008" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003009 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003010" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003011 let line1 = 1
3012 let line2 = line("$")
3013
Bram Moolenaar8d043172014-01-23 14:24:41 +01003014 elseif !&ma
3015 " 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 +01003016 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003017" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003018 return
3019
Bram Moolenaar9964e462007-05-05 17:54:07 +00003020 elseif s:FileReadable(a:tfile)
3021 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003022" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003023 let curline = line(".")
3024 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003025" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003026 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003027 let line1= curline + 1
3028 let line2= line("$") - lastline + 1
3029
3030 else
3031 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003032" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3033" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003034 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003035" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003036 return
3037 endif
3038
3039 " User-provided (ie. optional) fix-it-up command
3040 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003041" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003042 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003043" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003044" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003045 endif
3046
Bram Moolenaaradc21822011-04-01 18:03:16 +02003047 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003048 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003049 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003050 endif
3051
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003052" 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 +00003053
3054 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003055" redraw!
3056
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003057" 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 +00003058" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003059endfun
3060
Bram Moolenaar9964e462007-05-05 17:54:07 +00003061" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003062" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003063" Input:
3064" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3065" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003066" b:netrw_method= 1: rcp
3067" 2: ftp + <.netrc>
3068" 3: ftp + machine, id, password, and [path]filename
3069" 4: scp
3070" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003071" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003072" 7: rsync
3073" 8: fetch
3074" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003075" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003076" g:netrw_machine= hostname
3077" b:netrw_fname = filename
3078" g:netrw_port = optional port number (for ftp)
3079" g:netrw_choice = copy of input url (choice)
3080fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003081" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003082
Bram Moolenaar251e1912011-06-19 05:09:16 +02003083 " sanity check: choice should have at least three slashes in it
3084 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3085 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3086 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003087" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003088 return
3089 endif
3090
Bram Moolenaar5c736222010-01-06 20:54:52 +01003091 " record current g:netrw_machine, if any
3092 " curmachine used if protocol == ftp and no .netrc
3093 if exists("g:netrw_machine")
3094 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003095" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003096 else
3097 let curmachine= "N O T A HOST"
3098 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003099 if exists("g:netrw_port")
3100 let netrw_port= g:netrw_port
3101 endif
3102
3103 " insure that netrw_ftp_cmd starts off every method determination
3104 " with the current g:netrw_ftp_cmd
3105 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003106
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003107 " initialization
3108 let b:netrw_method = 0
3109 let g:netrw_machine = ""
3110 let b:netrw_fname = ""
3111 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003112 let g:netrw_choice = a:choice
3113
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003114 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003115 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003116 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3117 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003118 " rcpurm : rcp://[user@]host/filename Use rcp
3119 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003120 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003121 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003122 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003123 " rsyncurm : rsync://host[:port]/path Use rsync
3124 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3125 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003126 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003127 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3128 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003129 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3130 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003131 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003132 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003133 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003134 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003135 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003136 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003137 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003138 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003139
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003140" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003141 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003142 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003143 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003144" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003145 let b:netrw_method = 1
3146 let userid = substitute(a:choice,rcpurm,'\1',"")
3147 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3148 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003149 if userid != ""
3150 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003152
Bram Moolenaaradc21822011-04-01 18:03:16 +02003153 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003154 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003155" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003156 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003157 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3158 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3159 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003160
Bram Moolenaar15146672011-10-20 22:22:38 +02003161 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003162 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003163" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003164 let b:netrw_method = 5
3165 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3166 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003167 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003168
Bram Moolenaaradc21822011-04-01 18:03:16 +02003169 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003170 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003171" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003172 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003173 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003174 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3175 else
3176 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3177 endif
3178 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003179
Bram Moolenaaradc21822011-04-01 18:03:16 +02003180 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003181 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003182" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003183 let b:netrw_method = 7
3184 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3185 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003186
Bram Moolenaaradc21822011-04-01 18:03:16 +02003187 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003188 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003189" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003190 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003191 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3192 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3193 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003194" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003195 if userid != ""
3196 let g:netrw_uid= userid
3197 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003198
Bram Moolenaaradc21822011-04-01 18:03:16 +02003199 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003200 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003201 call NetUserPass("ftp:".g:netrw_machine)
3202 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003203 " if there's a change in hostname, require password re-entry
3204 unlet s:netrw_passwd
3205 endif
3206 if exists("netrw_port")
3207 unlet netrw_port
3208 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003209 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003210
Bram Moolenaar446cb832008-06-24 21:56:24 +00003211 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003212 let b:netrw_method = 3
3213 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003214 let host= substitute(g:netrw_machine,'\..*$','','')
3215 if exists("s:netrw_hup[host]")
3216 call NetUserPass("ftp:".host)
3217
Nir Lichtman1e34b952024-05-08 19:19:34 +02003218 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003219" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3220" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003221 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003222 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003223" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003224 endif
3225 let b:netrw_method= 2
3226 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003227" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003228 let b:netrw_method= 2
3229 else
3230 if !exists("g:netrw_uid") || g:netrw_uid == ""
3231 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003232 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003233 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003234 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003235 endif
3236 let b:netrw_method= 3
3237 endif
3238 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003239
Bram Moolenaaradc21822011-04-01 18:03:16 +02003240 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003241 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003242" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003243 let b:netrw_method = 8
3244 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3245 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3246 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3247 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003248
Bram Moolenaaradc21822011-04-01 18:03:16 +02003249 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003250 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003251" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003253 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3254 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003255 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003256 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003257 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003258
Bram Moolenaaradc21822011-04-01 18:03:16 +02003259 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003260 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003261" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003262 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003263 let b:netrw_method = 3
3264 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3265 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003266
Bram Moolenaar9964e462007-05-05 17:54:07 +00003267 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003268 let b:netrw_method = 2
3269 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3270 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3271 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003272
Bram Moolenaaradc21822011-04-01 18:03:16 +02003273 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003274 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003275" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003276 let b:netrw_method = 9
3277 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3278 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003279
Bram Moolenaaradc21822011-04-01 18:03:16 +02003280 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003281 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003282" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003283 let b:netrw_method = 1
3284 let userid = substitute(a:choice,rcphf,'\2',"")
3285 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3286 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003287" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3288" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3289" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3290" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003291 if userid != ""
3292 let g:netrw_uid= userid
3293 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003294
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003295 " Method#10: file://user@hostname/...path-to-file {{{3
3296 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003297" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003298 let b:netrw_method = 10
3299 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003300" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003301
Bram Moolenaaradc21822011-04-01 18:03:16 +02003302 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003303 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003304 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003305 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003306 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003307 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003309 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003310
Bram Moolenaar81695252004-12-29 20:58:21 +00003311 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003312 " remove any leading [:#] from port number
3313 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3314 elseif exists("netrw_port")
3315 " retain port number as implicit for subsequent ftp operations
3316 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003317 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003318
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003319" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3320" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3321" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3322" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003323" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003324" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003325" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003326" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003327" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003328" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003329" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003330" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003332
Bram Moolenaar9964e462007-05-05 17:54:07 +00003333" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003334" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003335" Usage: :call NetUserPass() -- will prompt for userid and password
3336" :call NetUserPass("uid") -- will prompt for password
3337" :call NetUserPass("uid","password") -- sets global userid and password
3338" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3339" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003340fun! NetUserPass(...)
3341
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003342" call Dfunc("NetUserPass() a:0=".a:0)
3343
3344 if !exists('s:netrw_hup')
3345 let s:netrw_hup= {}
3346 endif
3347
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003349 " case: no input arguments
3350
3351 " change host and username if not previously entered; get new password
3352 if !exists("g:netrw_machine")
3353 let g:netrw_machine= input('Enter hostname: ')
3354 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003355 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003356 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 let g:netrw_uid= input('Enter username: ')
3358 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003359 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003360 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003361
3362 " set up hup database
3363 let host = substitute(g:netrw_machine,'\..*$','','')
3364 if !exists('s:netrw_hup[host]')
3365 let s:netrw_hup[host]= {}
3366 endif
3367 let s:netrw_hup[host].uid = g:netrw_uid
3368 let s:netrw_hup[host].passwd = s:netrw_passwd
3369
3370 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003371 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003372
3373 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003374 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003375 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003376" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003377 let host = substitute(a:1,'^ftp:','','')
3378 let host = substitute(host,'\..*','','')
3379 if exists("s:netrw_hup[host]")
3380 let g:netrw_uid = s:netrw_hup[host].uid
3381 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003382" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3383" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003384 else
3385 let g:netrw_uid = input("Enter UserId: ")
3386 let s:netrw_passwd = inputsecret("Enter Password: ")
3387 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003388
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003389 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003390 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003391" 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 +02003392 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003393 if g:netrw_machine =~ '[0-9.]\+'
3394 let host= g:netrw_machine
3395 else
3396 let host= substitute(g:netrw_machine,'\..*$','','')
3397 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003398 else
3399 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003400 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003401 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003402" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003403 if exists("g:netrw_passwd")
3404 " ask for password if one not previously entered
3405 let s:netrw_passwd= g:netrw_passwd
3406 else
3407 let s:netrw_passwd = inputsecret("Enter Password: ")
3408 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003409 endif
3410
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003411" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003412 if exists("host")
3413 if !exists('s:netrw_hup[host]')
3414 let s:netrw_hup[host]= {}
3415 endif
3416 let s:netrw_hup[host].uid = g:netrw_uid
3417 let s:netrw_hup[host].passwd = s:netrw_passwd
3418 endif
3419
3420 elseif a:0 == 2
3421 let g:netrw_uid = a:1
3422 let s:netrw_passwd = a:2
3423
3424 elseif a:0 == 3
3425 " enter hostname, user-id, and password into the hup dictionary
3426 let host = substitute(a:1,'^\a\+:','','')
3427 let host = substitute(host,'\..*$','','')
3428 if !exists('s:netrw_hup[host]')
3429 let s:netrw_hup[host]= {}
3430 endif
3431 let s:netrw_hup[host].uid = a:2
3432 let s:netrw_hup[host].passwd = a:3
3433 let g:netrw_uid = s:netrw_hup[host].uid
3434 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003435" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3436" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003438
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003439" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441
Bram Moolenaar85850f32019-07-19 22:05:51 +02003442" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003443" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003444" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003446" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003447" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3448fun! s:ExplorePatHls(pattern)
3449" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3450 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003451" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003452 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003453" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003454 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3455" call Dret("s:ExplorePatHls repat<".repat.">")
3456 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003457endfun
3458
3459" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003460" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003461" 0: (user: <mb>) bookmark current directory
3462" 1: (user: <gb>) change to the bookmarked directory
3463" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003464" 3: (browsing) records current directory history
3465" 4: (user: <u>) go up (previous) directory, using history
3466" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003467" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003468fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003469" 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 +02003470 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3471" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3472 return
3473 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003474
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003475 let ykeep = @@
3476 let curbufnr = bufnr("%")
3477
Bram Moolenaar9964e462007-05-05 17:54:07 +00003478 if a:chg == 0
3479 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003480" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003481 if exists("s:netrwmarkfilelist_{curbufnr}")
3482 call s:NetrwBookmark(0)
3483 echo "bookmarked marked files"
3484 else
3485 call s:MakeBookmark(a:curdir)
3486 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003487 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003488
KSR-Yasudaf4498252023-10-06 03:34:17 +09003489 try
3490 call s:NetrwBookHistSave()
3491 catch
3492 endtry
3493
Bram Moolenaar9964e462007-05-05 17:54:07 +00003494 elseif a:chg == 1
3495 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003496" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003497 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003498" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003499 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003500 else
3501 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3502 endif
3503
3504 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003505" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003506 let didwork= 0
3507 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003508" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003509 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003510" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003511 let cnt= 1
3512 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003513" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003514 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003515 let didwork = 1
3516 let cnt = cnt + 1
3517 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003518 endif
3519
3520 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003521 " Note: history is saved only when PerformListing is done;
3522 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3523 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003524 let first = 1
3525 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003526 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003527 while ( first || cnt != g:netrw_dirhistcnt )
3528" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003529 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003530" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003531 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003532 let didwork= 1
3533 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003534 let histcnt = histcnt + 1
3535 let first = 0
3536 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003537 if cnt < 0
3538 let cnt= cnt + g:netrw_dirhistmax
3539 endif
3540 endwhile
3541 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003542 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003543 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003544 if didwork
3545 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3546 endif
3547
3548 elseif a:chg == 3
3549 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003550" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003551 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 +02003552 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003553 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3554 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003555 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003556" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003557 endif
3558
3559 elseif a:chg == 4
3560 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003561" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003562 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003563 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3564 if g:netrw_dirhistcnt < 0
3565 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003566 endif
3567 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003568 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003569 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003570 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3571" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003572 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003573 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003574" call Decho("setl ma noro",'~'.expand("<slnum>"))
3575 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003576 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003577" call Decho("setl nomod",'~'.expand("<slnum>"))
3578" 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 +00003579 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003580" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3581 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003582 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003583 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003584 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003585 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003586 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003587 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003588 echo "Sorry, no predecessor directory exists yet"
3589 endif
3590
3591 elseif a:chg == 5
3592 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003593" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003594 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003595 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3596 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3597" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003598 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003599" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003600 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003601 sil! NetrwKeepj %d _
3602" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3603" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003604 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003605" 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 +02003606 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003607" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3608 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003609 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003610 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3611 if g:netrw_dirhistcnt < 0
3612 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003613 endif
3614 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003615 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003616 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003617 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003618 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003619 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003620
3621 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003622" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003623 if exists("s:netrwmarkfilelist_{curbufnr}")
3624 call s:NetrwBookmark(1)
3625 echo "removed marked files from bookmarks"
3626 else
3627 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003628 let iremove = v:count
3629 let dremove = g:netrw_bookmarklist[iremove - 1]
3630" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003631 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003632" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3633 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3634 echo "removed ".dremove." from g:netrw_bookmarklist"
3635" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003636 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003637" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003638
3639 try
3640 call s:NetrwBookHistSave()
3641 catch
3642 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003643 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003644 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003645 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003646 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003647" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003648endfun
3649
3650" ---------------------------------------------------------------------
3651" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003652" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003653" Sister function: s:NetrwBookHistSave()
3654fun! s:NetrwBookHistRead()
3655" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003656 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003657" 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 +02003658 return
3659 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003660 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003661
3662 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003663 if !exists("s:netrw_initbookhist")
3664 let home = s:NetrwHome()
3665 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003666 if filereadable(s:NetrwFile(savefile))
3667" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003668 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003669 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003670
3671 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003672 if g:netrw_dirhistmax > 0
3673 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003674 if filereadable(s:NetrwFile(savefile))
3675" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003676 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003677 endif
3678 let s:netrw_initbookhist= 1
3679 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003680 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003681 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003682
Bram Moolenaar97d62492012-11-15 21:28:22 +01003683 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003684" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3685" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003686" call Dret("s:NetrwBookHistRead")
3687endfun
3688
3689" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003690" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003691" Sister function: s:NetrwBookHistRead()
3692" I used to do this via viminfo but that appears to
3693" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003694" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3695" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003696" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003697fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003698" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003699 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003700" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003701 return
3702 endif
3703
Bram Moolenaar5c736222010-01-06 20:54:52 +01003704 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003705" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003706 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003707
3708 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003709 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003710" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003711 if g:netrw_use_noswf
3712 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3713 else
3714 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3715 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003716 setl nocin noai noci magic nospell nohid wig= noaw
3717 setl ma noro write
3718 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003719 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003720
Bram Moolenaar85850f32019-07-19 22:05:51 +02003721 " rename enew'd file: .netrwhist -- no attempt to merge
3722 " record dirhistmax and current dirhistcnt
3723 " save history
3724" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003725 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003726 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003727 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3728 if g:netrw_dirhistmax > 0
3729 let lastline = line("$")
3730 let cnt = g:netrw_dirhistcnt
3731 let first = 1
3732 while ( first || cnt != g:netrw_dirhistcnt )
3733 let lastline= lastline + 1
3734 if exists("g:netrw_dirhist_{cnt}")
3735 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3736" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3737 endif
3738 let first = 0
3739 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3740 if cnt < 0
3741 let cnt= cnt + g:netrw_dirhistmax
3742 endif
3743 endwhile
3744 exe "sil! w! ".savefile
3745" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3746 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003747
Bram Moolenaar85850f32019-07-19 22:05:51 +02003748 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003749 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003750 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003751" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003752 " merge and write .netrwbook
3753 let savefile= s:NetrwHome()."/.netrwbook"
3754
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003755 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003756 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003757 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003758 for bdm in booklist
3759 if index(g:netrw_bookmarklist,bdm) == -1
3760 call add(g:netrw_bookmarklist,bdm)
3761 endif
3762 endfor
3763 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003764 endif
3765
3766 " construct and save .netrwbook
3767 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003768 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003769" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003770 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003771
3772 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003773 let bgone= bufnr("%")
3774 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003775 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003776
3777" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003778endfun
3779
3780" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003781" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3782" list of the contents of a local or remote directory. It is assumed that the
3783" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3784" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003785" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003786fun! s:NetrwBrowse(islocal,dirname)
3787 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003788" 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 +02003789" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3790" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3791" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003792
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003793 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3794 " This is useful when one edits a local file, then :e ., then :Rex
3795 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3796 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003797" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003798 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003799
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003800 " s:NetrwBrowse : initialize history {{{3
3801 if !exists("s:netrw_initbookhist")
3802 NetrwKeepj call s:NetrwBookHistRead()
3803 endif
3804
3805 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003806 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003807 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003808" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003809 else
3810 let dirname= a:dirname
3811 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003812
Bram Moolenaar85850f32019-07-19 22:05:51 +02003813 " repoint t:netrw_lexbufnr if appropriate
3814 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3815" call Decho("set repointlexbufnr to true!")
3816 let repointlexbufnr= 1
3817 endif
3818
3819 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003820 if exists("s:netrw_skipbrowse")
3821 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003822" 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 +01003823" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003824 return
3825 endif
3826 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003827 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003828" call Dret("s:NetrwBrowse : missing shellescape()")
3829 return
3830 endif
3831 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003832 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003833" call Dret("s:NetrwBrowse : missing fnameescape()")
3834 return
3835 endif
3836
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003837 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003838 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003839
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003840 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003841 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3842 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3843" call Decho("clearing marked files",'~'.expand("<slnum>"))
3844 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3845 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003846 endif
3847
3848 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003849 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003850" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3851" 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 +02003852 if s:NetrwLcd(dirname)
3853" call Dret("s:NetrwBrowse : lcd failure")
3854 return
3855 endif
3856 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003857" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003858
Bram Moolenaar5c736222010-01-06 20:54:52 +01003859 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003860 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003861" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003862 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003863" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003864 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003865 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003866 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003867" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003868
3869 " remove any filetype indicator from end of dirname, except for the
3870 " "this is a directory" indicator (/).
3871 " There shouldn't be one of those here, anyway.
3872 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003873" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003874 call s:RemotePathAnalysis(dirname)
3875
3876 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3877 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003878 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003879 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003880" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003881 let b:netrw_curdir = dirname
3882 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003883 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003884 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3885 sil call netrw#NetRead(2,url)
3886 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003887" call Decho("url<".url.">",'~'.expand("<slnum>"))
3888" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3889" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003890 if s:path =~ '.bz2'
3891 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3892 elseif s:path =~ '.gz'
3893 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3894 elseif s:path =~ '.gz'
3895 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3896 else
3897 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3898 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003899 endif
3900
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003901 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003902 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003903 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003904" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003905 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003906" 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 +00003907
Bram Moolenaar446cb832008-06-24 21:56:24 +00003908" call Dret("s:NetrwBrowse : file<".s:fname.">")
3909 return
3910 endif
3911
Bram Moolenaaradc21822011-04-01 18:03:16 +02003912 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003913 call s:UseBufWinVars()
3914
3915 " set up some variables {{{3
3916 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003917 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003918 let s:last_sort_by = g:netrw_sort_by
3919
3920 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003921 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003922
Bram Moolenaar97d62492012-11-15 21:28:22 +01003923 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003924" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003925 let svpos = winsaveview()
3926" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003927 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003928
Bram Moolenaar446cb832008-06-24 21:56:24 +00003929 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003930 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3931 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3932" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3933" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3934 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3935 else
3936" " call Decho("2match none",'~'.expand("<slnum>"))
3937 2match none
3938 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003939 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003940 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003941 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003942" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003943 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944" 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 +01003945" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003946 return
3947 endif
3948
3949 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003950" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003951 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003952 if b:netrw_curdir =~ '[/\\]$'
3953 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3954 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003955 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003956 let b:netrw_curdir= b:netrw_curdir."/"
3957 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003958 if b:netrw_curdir == ''
3959 if has("amiga")
3960 " On the Amiga, the empty string connotes the current directory
3961 let b:netrw_curdir= getcwd()
3962 else
3963 " under unix, when the root directory is encountered, the result
3964 " from the preceding substitute is an empty string.
3965 let b:netrw_curdir= '/'
3966 endif
3967 endif
3968 if !a:islocal && b:netrw_curdir !~ '/$'
3969 let b:netrw_curdir= b:netrw_curdir.'/'
3970 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003971" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003972
3973 " ------------
3974 " (local only) {{{3
3975 " ------------
3976 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003977" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003978
3979 " Set up ShellCmdPost handling. Append current buffer to browselist
3980 call s:LocalFastBrowser()
3981
3982 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3983 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003984" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3985" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003986 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003987 if s:NetrwLcd(b:netrw_curdir)
3988" call Dret("s:NetrwBrowse : lcd failure")
3989 return
3990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003991 endif
3992 endif
3993
3994 " --------------------------------
3995 " remote handling: {{{3
3996 " --------------------------------
3997 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003998" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003999
Bram Moolenaar97d62492012-11-15 21:28:22 +01004000 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004001" 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 +02004002 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004003 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004004" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004005 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4006 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4007 if dirname !~ '/$'
4008 let dirname= dirname.'/'
4009 endif
4010 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004011" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004012 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004013 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004014" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004015 endif
4016
4017 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4018 if dirname !~ dirpat
4019 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004020 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004021 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004022 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004023" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004024 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004025" 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 +00004026" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4027 return
4028 endif
4029 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004030" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004031 endif " (additional remote handling)
4032
Bram Moolenaar85850f32019-07-19 22:05:51 +02004033 " -------------------------------
4034 " Perform Directory Listing: {{{3
4035 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004036 NetrwKeepj call s:NetrwMaps(a:islocal)
4037 NetrwKeepj call s:NetrwCommands(a:islocal)
4038 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004039
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004040 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004041 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004042" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4043
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004044 " If there is a rexposn: restore position with rexposn
4045 " Otherwise : set rexposn
4046 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004047" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4048 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4049 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4050 NetrwKeepj exe w:netrw_bannercnt
4051 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004052 else
4053 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4054 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004055 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004056 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004057" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004058 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004059 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004060
Bram Moolenaar85850f32019-07-19 22:05:51 +02004061 " repoint t:netrw_lexbufnr if appropriate
4062 if exists("repointlexbufnr")
4063 let t:netrw_lexbufnr= bufnr("%")
4064" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4065 endif
4066
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004067 " restore position
4068 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004069" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4070 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004071 endif
4072
Bram Moolenaara6878372014-03-22 21:02:50 +01004073 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004074 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4075 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004076" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4077" 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 +02004078" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004079 return
4080endfun
4081
4082" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004083" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4084" may not apply correctly; ie. netrw's idea of the current directory may
4085" differ from vim's. This function insures that netrw's idea of the current
4086" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004087" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004088fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004089" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4090" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4091" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4092" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4093" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004094
4095 " clean up any leading treedepthstring
4096 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4097 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004098" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004099 else
4100 let fname= a:fname
4101 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004102
4103 if g:netrw_keepdir
4104 " vim's idea of the current directory possibly may differ from netrw's
4105 if !exists("b:netrw_curdir")
4106 let b:netrw_curdir= getcwd()
4107 endif
4108
Nir Lichtman1e34b952024-05-08 19:19:34 +02004109 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004110 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004111 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004112 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004113" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004114 else
4115 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004116 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004117" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004118 endif
4119
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004120 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004121 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004122 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004123" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004124 else
4125 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004126 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004127" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004128 endif
4129 else
4130 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004131 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004132" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4133" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4134" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004135 endif
4136
Bram Moolenaar85850f32019-07-19 22:05:51 +02004137" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004138 return ret
4139endfun
4140
4141" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004142" s:NetrwFileInfo: supports qf (query for file information) {{{2
4143fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004144" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004145 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004146 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004147 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004148 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004149 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004150 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004151 let lsopt= "-lsadh --si"
4152 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004153" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004154 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004155
4156 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004157 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004158" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004159
Bram Moolenaara6878372014-03-22 21:02:50 +01004160 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004161 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004162" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004163
4164 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004165 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004166" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004167
Bram Moolenaar446cb832008-06-24 21:56:24 +00004168 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004169" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004170 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004171" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004172 endif
4173 else
4174 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004175" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4176 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004177 let fname= substitute(a:fname,".$","","")
4178 else
4179 let fname= a:fname
4180 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004181 let t = getftime(s:NetrwFile(fname))
4182 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004183 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004184 let sz= s:NetrwHumanReadable(sz)
4185 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004186 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4187" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004188 endif
4189 else
4190 echo "sorry, \"qf\" not supported yet for remote files"
4191 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004192 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004193" call Dret("s:NetrwFileInfo")
4194endfun
4195
4196" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004197" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4198fun! s:NetrwFullPath(filename)
4199" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4200 let filename= a:filename
4201 if filename !~ '^/'
4202 let filename= resolve(getcwd().'/'.filename)
4203 endif
4204 if filename != "/" && filename =~ '/$'
4205 let filename= substitute(filename,'/$','','')
4206 endif
4207" " call Dret("s:NetrwFullPath <".filename.">")
4208 return filename
4209endfun
4210
4211" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004212" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004213" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004214" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004215" 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 +00004216fun! s:NetrwGetBuffer(islocal,dirname)
4217" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004218" 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 +02004219" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4220" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004221 let dirname= a:dirname
4222
4223 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004224" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004225 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004226" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004227 let s:netrwbuf= {}
4228 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004229" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4230" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4231
4232 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4233 let bufnum = -1
4234
4235 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4236 if has_key(s:netrwbuf,"NetrwTreeListing")
4237 let bufnum= s:netrwbuf["NetrwTreeListing"]
4238 else
4239 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4240 endif
4241" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4242 if !bufexists(bufnum)
4243 call remove(s:netrwbuf,"NetrwTreeListing"])
4244 let bufnum= -1
4245 endif
4246 elseif bufnr("NetrwTreeListing") != -1
4247 let bufnum= bufnr("NetrwTreeListing")
4248" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4249 else
4250" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4251 let bufnum= -1
4252 endif
4253
4254 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004255 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004256" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004257 if !bufexists(bufnum)
4258 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4259 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004260 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004261
Bram Moolenaar446cb832008-06-24 21:56:24 +00004262 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004263" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004264 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004265 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004266" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4267
Bram Moolenaar71badf92023-04-22 22:40:14 +01004268 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004269 " IF the buffer already has the desired name
4270 " AND it is empty
4271 let curbuf = bufname("%")
4272 if curbuf == '.'
4273 let curbuf = getcwd()
4274 endif
4275" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004276" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004277" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4278" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4279" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4280" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4281 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004282" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4283 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004284 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004285" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004286 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004287 " 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 +00004288
4289 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004290 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004291" 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 +00004292 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004293" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004294 " name the buffer
4295 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4296 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004297" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004298 let w:netrw_treebufnr = bufnr("%")
4299 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004300 if g:netrw_use_noswf
4301 setl nobl bt=nofile noswf
4302 else
4303 setl nobl bt=nofile
4304 endif
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>
4308 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004309" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004310 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004311 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004312 " enter the new buffer into the s:netrwbuf dictionary
4313 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4314" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4315" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004316 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004317" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004318
4319 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004320" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004321 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004322 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004323 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004324
4325 if &ft == "netrw"
4326" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4327 exe "sil! NetrwKeepj noswapfile b ".bufnum
4328" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004329 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004330" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4331 call s:NetrwEditBuf(bufnum)
4332" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004333 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004334" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004335 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004336 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004337 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004338
4339 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004340 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004341
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004342 if line("$") <= 1 && getline(1) == ""
4343 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004344 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004345" 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>"))
4346" 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 +01004347" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4348 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004349
Bram Moolenaar97d62492012-11-15 21:28:22 +01004350 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004351" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004352 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004353 sil NetrwKeepj %d _
4354" 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>"))
4355" 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 +01004356" 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 +00004357 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004358
Bram Moolenaar446cb832008-06-24 21:56:24 +00004359 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004360" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4361" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004362 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004363 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004364 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004365" 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>"))
4366" 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 +01004367" 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 +00004368 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004369
Bram Moolenaar446cb832008-06-24 21:56:24 +00004370 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004371" 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>"))
4372" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4373" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004374 return 1
4375 endif
4376 endif
4377
4378 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4379 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4380 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4381 " med 1 D H
4382 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004383" 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 +00004384 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004385 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004386 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004387
4388 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004389" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4390" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4391 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004392
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004393" 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>"))
4394" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4395" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004396 return 0
4397endfun
4398
4399" ---------------------------------------------------------------------
4400" s:NetrwGetcwd: get the current directory. {{{2
4401" Change backslashes to forward slashes, if any.
4402" If doesc is true, escape certain troublesome characters
4403fun! s:NetrwGetcwd(doesc)
4404" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4405 let curdir= substitute(getcwd(),'\\','/','ge')
4406 if curdir !~ '[\/]$'
4407 let curdir= curdir.'/'
4408 endif
4409 if a:doesc
4410 let curdir= fnameescape(curdir)
4411 endif
4412" call Dret("NetrwGetcwd <".curdir.">")
4413 return curdir
4414endfun
4415
4416" ---------------------------------------------------------------------
4417" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4418fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004419" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4420" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4421 let keepsol= &l:sol
4422 setl nosol
4423
Bram Moolenaar446cb832008-06-24 21:56:24 +00004424 call s:UseBufWinVars()
4425
4426 " insure that w:netrw_liststyle is set up
4427 if !exists("w:netrw_liststyle")
4428 if exists("g:netrw_liststyle")
4429 let w:netrw_liststyle= g:netrw_liststyle
4430 else
4431 let w:netrw_liststyle= s:THINLIST
4432 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004433" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004434 endif
4435
4436 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4437 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004438" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004439 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440 let dirname= "./"
4441 let curline= getline('.')
4442
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004443 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004444 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004445 let s:netrw_skipbrowse= 1
4446 echo 'Pressing "s" also works'
4447
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004448 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004449 let s:netrw_skipbrowse= 1
4450 echo 'Press "S" to edit sorting sequence'
4451
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004452 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004453 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004454 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004455
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004456 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004457 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004458 let s:netrw_skipbrowse= 1
4459 echo 'Pressing "a" also works'
4460
4461 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004462 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004463 endif
4464
4465 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004466" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004467 NetrwKeepj norm! 0
4468 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004469
4470 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004471" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004472 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004473 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4474
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004475 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004476" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004477 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004478 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004479
4480 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004481" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004482 let dirname= getline('.')
4483
4484 if !exists("b:netrw_cpf")
4485 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004486 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 +01004487 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004488" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489 endif
4490
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004491" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004492 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004493" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4494" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004495 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004496 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004497 else
4498 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004499 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004500 endif
Enno3146d632024-07-04 19:44:42 +02004501
4502 let dict={}
4503 " save the unnamed register and register 0-9 and a
4504 let dict.a=[getreg('a'), getregtype('a')]
4505 for i in range(0, 9)
4506 let dict[i] = [getreg(i), getregtype(i)]
4507 endfor
4508 let dict.unnamed = [getreg(''), getregtype('')]
4509
Bram Moolenaarc236c162008-07-13 17:41:49 +00004510 let eofname= filestart + b:netrw_cpf + 1
4511 if eofname <= col("$")
4512 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004513 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004514 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004515 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004516 endif
Enno3146d632024-07-04 19:44:42 +02004517
Bram Moolenaar446cb832008-06-24 21:56:24 +00004518 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004519 call s:RestoreRegister(dict)
4520
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004521" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004522 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004523" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004524 endif
4525
4526 " symlinks are indicated by a trailing "@". Remove it before further processing.
4527 let dirname= substitute(dirname,"@$","","")
4528
4529 " executables are indicated by a trailing "*". Remove it before further processing.
4530 let dirname= substitute(dirname,"\*$","","")
4531
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004532 let &l:sol= keepsol
4533
Bram Moolenaar446cb832008-06-24 21:56:24 +00004534" call Dret("s:NetrwGetWord <".dirname.">")
4535 return dirname
4536endfun
4537
4538" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004539" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4540" g:netrw_bufsettings will be used after the listing is produced.
4541" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004542fun! s:NetrwListSettings(islocal)
4543" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004544" 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 +00004545 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004546" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4547 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4548 setl bt=nofile nobl ma nonu nowrap noro nornu
4549 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004550 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004551 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004552 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004553" call Dredir("ls!","s:NetrwListSettings")
4554" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004555 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004556 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004557 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004558 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004559 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004560 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004561 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004562" 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 +00004563" call Dret("s:NetrwListSettings")
4564endfun
4565
4566" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004567" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004568" islocal=0: remote browsing
4569" =1: local browsing
4570fun! s:NetrwListStyle(islocal)
4571" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004572
Bram Moolenaar97d62492012-11-15 21:28:22 +01004573 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004574 let fname = s:NetrwGetWord()
4575 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004576 let svpos = winsaveview()
4577" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004578 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004579" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4580" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4581" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004582
Bram Moolenaar85850f32019-07-19 22:05:51 +02004583 " repoint t:netrw_lexbufnr if appropriate
4584 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4585" call Decho("set repointlexbufnr to true!")
4586 let repointlexbufnr= 1
4587 endif
4588
Bram Moolenaar446cb832008-06-24 21:56:24 +00004589 if w:netrw_liststyle == s:THINLIST
4590 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004591" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004592 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4593
4594 elseif w:netrw_liststyle == s:LONGLIST
4595 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004596" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004597 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4598
4599 elseif w:netrw_liststyle == s:WIDELIST
4600 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004601" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004602 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4603
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004604 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004605" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004606 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4607
4608 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004609 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004610 let g:netrw_liststyle = s:THINLIST
4611 let w:netrw_liststyle = g:netrw_liststyle
4612 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4613 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004614 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004615" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004616
4617 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004618" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4619 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004620 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004621" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004622 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004623" 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 +00004624
4625 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004626" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004627 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004628 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004629
Bram Moolenaar85850f32019-07-19 22:05:51 +02004630 " repoint t:netrw_lexbufnr if appropriate
4631 if exists("repointlexbufnr")
4632 let t:netrw_lexbufnr= bufnr("%")
4633" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4634 endif
4635
Bram Moolenaar13600302014-05-22 18:26:40 +02004636 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004637" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4638 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004639 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004640
4641" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4642endfun
4643
4644" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004645" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4646fun! s:NetrwBannerCtrl(islocal)
4647" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4648
Bram Moolenaar97d62492012-11-15 21:28:22 +01004649 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004650 " toggle the banner (enable/suppress)
4651 let g:netrw_banner= !g:netrw_banner
4652
4653 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004654 let svpos= winsaveview()
4655" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004656 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4657
4658 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004659 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4660 let fname= s:NetrwGetWord()
4661 sil NetrwKeepj $
4662 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4663" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4664 if result <= 0 && exists("w:netrw_bannercnt")
4665 exe "NetrwKeepj ".w:netrw_bannercnt
4666 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004667 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004668 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004669" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4670endfun
4671
4672" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004673" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4674"
4675" No bang: enters files/directories into Netrw's bookmark system
4676" No argument and in netrw buffer:
4677" if there are marked files: bookmark marked files
4678" otherwise : bookmark file/directory under cursor
4679" No argument and not in netrw buffer: bookmarks current open file
4680" Has arguments: globs them individually and bookmarks them
4681"
4682" With bang: deletes files/directories from Netrw's bookmark system
4683fun! s:NetrwBookmark(del,...)
4684" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4685 if a:0 == 0
4686 if &ft == "netrw"
4687 let curbufnr = bufnr("%")
4688
4689 if exists("s:netrwmarkfilelist_{curbufnr}")
4690 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004691" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004692 let svpos = winsaveview()
4693" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004694 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004695 for fname in s:netrwmarkfilelist_{curbufnr}
4696 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4697 endfor
4698 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4699 call s:NetrwUnmarkList(curbufnr,curdir)
4700 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004701" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4702 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004703 else
4704 let fname= s:NetrwGetWord()
4705 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4706 endif
4707
4708 else
4709 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004710" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004711 let fname= expand("%")
4712 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4713 endif
4714
4715 else
4716 " bookmark specified files
4717 " attempts to infer if working remote or local
4718 " by deciding if the current file begins with an url
4719 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004720 let islocal= expand("%") !~ '^\a\{3,}://'
4721" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004722 let i = 1
4723 while i <= a:0
4724 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004725 if v:version > 704 || (v:version == 704 && has("patch656"))
4726 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004727 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004728 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004729 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004730 else
4731 let mbfiles= [a:{i}]
4732 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004733" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004734 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004735" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004736 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4737 endfor
4738 let i= i + 1
4739 endwhile
4740 endif
4741
4742 " update the menu
4743 call s:NetrwBookmarkMenu()
4744
4745" call Dret("s:NetrwBookmark")
4746endfun
4747
4748" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004749" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4750" .2.[cnt] for bookmarks, and
4751" .3.[cnt] for history
4752" (see s:NetrwMenu())
4753fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004754 if !exists("s:netrw_menucnt")
4755 return
4756 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004757" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004758
4759 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004760 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004761 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004762" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004763 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4764 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004765 endif
4766 if !exists("s:netrw_initbookhist")
4767 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004768 endif
4769
4770 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004771 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004772 let cnt= 1
4773 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004774" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004775 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004776
4777 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004778 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004779
4780 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004781 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 +01004782 let cnt= cnt + 1
4783 endfor
4784
4785 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004786
4787 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004788 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004789 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004790 let first = 1
4791 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004792 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004793 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004794 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004795 if exists("g:netrw_dirhist_{cnt}")
4796 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004797" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004798 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4799 endif
4800 let first = 0
4801 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4802 if cnt < 0
4803 let cnt= cnt + g:netrw_dirhistmax
4804 endif
4805 endwhile
4806 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004807
Bram Moolenaar9964e462007-05-05 17:54:07 +00004808 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004809" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004810endfun
4811
4812" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004813" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4814" directory and a new directory name. Also, if the
4815" "new directory name" is actually a file,
4816" NetrwBrowseChgDir() edits the file.
4817fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004818" 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 +01004819" 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 +00004820
Bram Moolenaar97d62492012-11-15 21:28:22 +01004821 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004822 if !exists("b:netrw_curdir")
4823 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4824 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004825 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004826" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4827" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004828" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004829" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004830 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004831 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004832" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004833
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004834 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004835" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004836 call s:SavePosn(s:netrw_posn)
4837 NetrwKeepj call s:NetrwOptionsSave("s:")
4838 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004839 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004840 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004841 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004842 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004843 endif
4844 let newdir = a:newdir
4845 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004846 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004847" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004848" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004849" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004850
4851 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004852" 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 +01004853 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004854" 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 +01004855 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004856 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004857" 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 +01004858 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004859" 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 +02004860 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004861 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004862 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004863 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004864" 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 +01004865 endif
4866 endif
4867" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004868" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004869 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004870
Bram Moolenaar446cb832008-06-24 21:56:24 +00004871 " set up o/s-dependent directory recognition pattern
4872 if has("amiga")
4873 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004874 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004875 let dirpat= '[\/]$'
4876 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004877" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004878
4879 if dirname !~ dirpat
4880 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004881 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004882 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004883" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004884 endif
4885
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004886" 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 +01004887 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004888 " ------------------------------
4889 " NetrwBrowseChgDir: edit a file {{{3
4890 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004891" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004892
Bram Moolenaar97d62492012-11-15 21:28:22 +01004893 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004894 let s:rexposn_{bufnr("%")}= winsaveview()
4895" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004896" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4897" 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 +01004898
Bram Moolenaar446cb832008-06-24 21:56:24 +00004899 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004900" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4901" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004902" let newdir = s:NetrwTreePath(s:netrw_treetop)
4903" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004904 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004905 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4906" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4907 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004908 if dirname =~ '/$'
4909 let dirname= dirname.newdir
4910 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004911 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004912 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004913" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4914" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004915 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004916" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004917 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004918 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004919 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004920 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004921" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004922 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004923 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004924" 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 +02004925 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004926 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004927 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004928" " 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 +01004929 if type(g:netrw_browse_split) == 3
4930 " open file in server
4931 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004932" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004933 call s:NetrwServerEdit(a:islocal,dirname)
4934" call Dret("s:NetrwBrowseChgDir")
4935 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004936
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004937 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004938 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004939" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004940 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4941 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004942 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004943 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004944 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004945 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004946
Bram Moolenaar446cb832008-06-24 21:56:24 +00004947 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004948 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004949" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004950 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4951 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004952 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004953 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004954 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004955 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004956
Bram Moolenaar446cb832008-06-24 21:56:24 +00004957 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004958 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004959" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004960 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004961 if !exists("b:netrw_curdir")
4962 let b:netrw_curdir= getcwd()
4963 endif
4964 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004965
Bram Moolenaar446cb832008-06-24 21:56:24 +00004966 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004967 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004968" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004969 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004970 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004971" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004972 return
4973 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004974 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004975
Bram Moolenaar9964e462007-05-05 17:54:07 +00004976 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004977 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004978" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004979 call s:NetrwMenu(0)
4980 " optional change to window
4981 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004982" 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 +02004983 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004984 " if g:netrw_chgwin is set to one more than the last window, then
4985 " vertically split the last window to make that window available.
4986 let curwin= winnr()
4987 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4988 vs
4989 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004990 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004991 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004992 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004993 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004994 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004995
Bram Moolenaar9964e462007-05-05 17:54:07 +00004996 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004997
Bram Moolenaar446cb832008-06-24 21:56:24 +00004998 " the point where netrw actually edits the (local) file
4999 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01005000 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005001 if !&mod
5002 " if e the new file would fail due to &mod, then don't change any of the flags
5003 let dolockout= 1
5004 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005005 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005006" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005007 " some like c-^ to return to the last edited file
5008 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005009 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5010 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005011 call s:NetrwEditFile("e","",dirname)
5012" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005013 " COMBAK -- cuc cul related
5014 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005015 if &hidden || &bufhidden == "hide"
5016 " file came from vim's hidden storage. Don't "restore" options with it.
5017 let dorestore= 0
5018 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005019 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005020" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005021 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005022
5023 " handle g:Netrw_funcref -- call external-to-netrw functions
5024 " This code will handle g:Netrw_funcref as an individual function reference
5025 " or as a list of function references. It will ignore anything that's not
5026 " a function reference. See :help Funcref for information about function references.
5027 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005028" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005029 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005030" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005031 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005032 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005033" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005034 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005035 if type(Fncref) == 2
5036 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005037 endif
5038 endfor
5039 endif
5040 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005041 endif
5042
5043 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005044 " ----------------------------------------------------
5045 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5046 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005047" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005048 let dirname = newdir
5049 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005050 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005051 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005052
5053 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005054 " ---------------------------------------------
5055 " NetrwBrowseChgDir: refresh the directory list {{{3
5056 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005057" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005058 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005059 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005060
5061 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005062 " --------------------------------------
5063 " NetrwBrowseChgDir: go up one directory {{{3
5064 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005065" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005066
5067 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5068 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005069" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5070" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005071 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005072 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005073 endif
5074
5075 if has("amiga")
5076 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005077" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005078 if a:islocal
5079 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5080 let dirname= substitute(dirname,'/$','','')
5081 else
5082 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5083 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005084" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005085
Nir Lichtman1e34b952024-05-08 19:19:34 +02005086 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005087 " windows
5088 if a:islocal
5089 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5090 if dirname == ""
5091 let dirname= '/'
5092 endif
5093 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005094 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005095 endif
5096 if dirname =~ '^\a:$'
5097 let dirname= dirname.'/'
5098 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005099" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005100
Bram Moolenaar446cb832008-06-24 21:56:24 +00005101 else
5102 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005103" 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 +00005104 if a:islocal
5105 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5106 if dirname == ""
5107 let dirname= '/'
5108 endif
5109 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005110 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005111 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005112" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005113 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005114 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005115 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005116
5117 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005118 " --------------------------------------
5119 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5120 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005121" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005122 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5123" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005124 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005125 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005126" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5127 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005128 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005129 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005130" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005131 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005132 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005133" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005134
5135 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005136" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005137 if has_key(w:netrw_treedict,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
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005144 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005145" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005146 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005147 if has_key(w:netrw_treedict,treedir."/")
5148 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005149" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005150 let haskey = 1
5151 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005152" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005153 endif
5154 endif
5155
5156 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005157" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005158 if !haskey && treedir =~ '/$'
5159 let treedir= substitute(treedir,'/$','','')
5160 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005161" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005162 let haskey = 1
5163 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005164" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005165 endif
5166 endif
5167
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005168" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005169 if haskey
5170 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005171" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005172 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005173" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5174" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005175 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005176 else
5177 " go down one directory
5178 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005179" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5180" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005181 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005182 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005183" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005184 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005185
5186 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005187 " ----------------------------------------
5188 " NetrwBrowseChgDir: Go down one directory {{{3
5189 " ----------------------------------------
5190 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005191" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005192 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005193 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005194 endif
5195
Bram Moolenaar97d62492012-11-15 21:28:22 +01005196 " --------------------------------------
5197 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5198 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005199 if dorestore
5200 " dorestore is zero'd when a local file was hidden or bufhidden;
5201 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005202" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005203 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005204" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005205" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005206 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005207 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005208" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005209 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005210" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5211" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005212 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005213" 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 +02005214 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005215" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5216" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005217 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005218" 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 +02005219 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005220 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005221 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005222 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005223
Bram Moolenaar446cb832008-06-24 21:56:24 +00005224" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5225 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005226endfun
5227
5228" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005229" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5230" for thin, long, and wide: cursor placed just after banner
5231" for tree, keeps cursor on current filename
5232fun! s:NetrwBrowseUpDir(islocal)
5233" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005234 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5235 " this test needed because occasionally this function seems to be incorrectly called
5236 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005237 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005238 " directories.
5239" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5240 return
5241 endif
5242
Bram Moolenaara6878372014-03-22 21:02:50 +01005243 norm! 0
5244 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005245" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005246 let curline= getline(".")
5247 let swwline= winline() - 1
5248 if exists("w:netrw_treetop")
5249 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005250 elseif exists("b:netrw_curdir")
5251 let w:netrw_treetop= b:netrw_curdir
5252 else
5253 let w:netrw_treetop= getcwd()
5254 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005255 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005256 let curfile = getline(".")
5257 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005258 if a:islocal
5259 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5260 else
5261 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5262 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005263" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5264" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5265 if w:netrw_treetop == '/'
5266 keepj call search('^\M'.curfile,"w")
5267 elseif curfile == '../'
5268 keepj call search('^\M'.curfile,"wb")
5269 else
5270" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5271 while 1
5272 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5273 let treepath= s:NetrwTreePath(w:netrw_treetop)
5274" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5275 if treepath == curpath
5276 break
5277 endif
5278 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005279 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005280
Bram Moolenaara6878372014-03-22 21:02:50 +01005281 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005282" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005283 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005284 if exists("b:netrw_curdir")
5285 let curdir= b:netrw_curdir
5286 else
5287 let curdir= expand(getcwd())
5288 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005289 if a:islocal
5290 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5291 else
5292 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5293 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005294 call s:RestorePosn(s:netrw_posn)
5295 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005296 let curdir= '\<'. escape(curdir, '~'). '/'
5297 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005298 endif
5299" call Dret("s:NetrwBrowseUpDir")
5300endfun
5301
5302" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005303" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005304" given filename; typically this means given their extension.
5305" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005306fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005307 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005308" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005309
Bram Moolenaar91359012019-11-30 17:57:03 +01005310 if a:remote == 0 && isdirectory(a:fname)
5311 " if its really just a local directory, then do a "gf" instead
5312" 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 +01005313" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5314 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005315" call Dret("netrw#BrowseX")
5316 return
5317 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5318 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5319" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5320" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5321" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5322" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5323 norm! gf
5324" call Dret("netrw#BrowseX")
5325 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005326 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005327" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005328
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005329 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5330 let remote = a:remote
5331 else
5332 let remote = 0
5333 endif
5334
Bram Moolenaar97d62492012-11-15 21:28:22 +01005335 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005336 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005337" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005338
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005339 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5340 let awkeep = &aw
5341 set noaw
5342
Bram Moolenaar5c736222010-01-06 20:54:52 +01005343 " special core dump handler
5344 if a:fname =~ '/core\(\.\d\+\)\=$'
5345 if exists("g:Netrw_corehandler")
5346 if type(g:Netrw_corehandler) == 2
5347 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005348" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005349 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005350 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005351 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005352" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005353 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005354 if type(Fncref) == 2
5355 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005356 endif
5357 endfor
5358 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005359" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005360 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005361 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005362 let &aw= awkeep
5363" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005364 return
5365 endif
5366 endif
5367
Bram Moolenaar446cb832008-06-24 21:56:24 +00005368 " set up the filename
5369 " (lower case the extension, make a local copy of a remote file)
5370 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005371 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005372 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005373 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005374 if exten =~ "[\\/]"
5375 let exten= ""
5376 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005377" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005378
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005379 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005380 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005381" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005382 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005383 call netrw#NetRead(3,a:fname)
5384 " attempt to rename tempfile
5385 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005386 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005387" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5388" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005389 if s:netrw_tmpfile != newname && newname != ""
5390 if rename(s:netrw_tmpfile,newname) == 0
5391 " renaming succeeded
5392" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5393 let fname= newname
5394 else
5395 " renaming failed
5396" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5397 let fname= s:netrw_tmpfile
5398 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005399 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005400 let fname= s:netrw_tmpfile
5401 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005402 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005403" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005404 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005405 " special ~ handler for local
5406 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005407" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5408 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005409 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005410 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005411" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5412" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005413
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005414 " set up redirection (avoids browser messages)
5415 " by default, g:netrw_suppress_gx_mesg is true
5416 if g:netrw_suppress_gx_mesg
5417 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005418 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005419 let redir= substitute(&srr,"%s","nul","")
5420 else
5421 let redir= substitute(&srr,"%s","/dev/null","")
5422 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005423 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005424 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005425 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005426 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005427 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005428 else
5429 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005430 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005431" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005432
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005433 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005434 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005435" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005436 if g:netrw_browsex_viewer =~ '\s'
5437 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5438 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5439 let oviewer = ''
5440 let cnt = 1
5441 while !executable(viewer) && viewer != oviewer
5442 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5443 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5444 let cnt = cnt + 1
5445 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005446" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005447 endwhile
5448 else
5449 let viewer = g:netrw_browsex_viewer
5450 let viewopt = ""
5451 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005452" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005453 endif
5454
5455 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005456" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005457 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005458" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005459 let ret= netrwFileHandlers#Invoke(exten,fname)
5460
5461 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005462" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005463 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005464 let ret= v:shell_error
5465
Nir Lichtman1e34b952024-05-08 19:19:34 +02005466 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005467" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005468 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005469 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005470 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005471 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005472 else
5473 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5474 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005475 let ret= v:shell_error
5476
Bram Moolenaar97d62492012-11-15 21:28:22 +01005477 elseif has("win32unix")
5478 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005479" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005480 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005481" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005482 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005483 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005484" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005485 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005486 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005487" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005488 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005489 else
5490 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5491 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005492 let ret= v:shell_error
5493
Bram Moolenaar85850f32019-07-19 22:05:51 +02005494 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005495" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5496 if a:fname =~ '^https\=://'
5497 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5498 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005499" call Decho("fname<".fname.">")
5500" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005501 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5502
5503 else
5504 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5505 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005506 let ret= v:shell_error
5507
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005508 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5509" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5510 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5511 let ret= v:shell_error
5512
5513 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5514" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5515 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5516 let ret= v:shell_error
5517
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005518 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005519" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005520 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005521 let ret= v:shell_error
5522
5523 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005524" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005525 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005526 let ret= v:shell_error
5527
5528 else
5529 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005530" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005531 let ret= netrwFileHandlers#Invoke(exten,fname)
5532 endif
5533
5534 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5535 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005536" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005537 let ret= netrwFileHandlers#Invoke(exten,fname)
5538 endif
5539
Bram Moolenaarc236c162008-07-13 17:41:49 +00005540 " restoring redraw! after external file handlers
5541 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005542
5543 " cleanup: remove temporary file,
5544 " delete current buffer if success with handler,
5545 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005546 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005547 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005548" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005549"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005550" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005551" endif
5552
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005553 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005554 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005555 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005556 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005557 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005558 if use_ctrlo
5559 exe "sil! NetrwKeepj norm! \<c-o>"
5560 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005561 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005562" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005563 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005564 let @@ = ykeep
5565 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005566
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005567" call Dret("netrw#BrowseX")
5568endfun
5569
5570" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005571" netrw#GX: gets word under cursor for gx support {{{2
5572" See also: netrw#BrowseXVis
5573" netrw#BrowseX
5574fun! netrw#GX()
5575" call Dfunc("netrw#GX()")
5576 if &ft == "netrw"
5577 let fname= s:NetrwGetWord()
5578 else
5579 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5580 endif
5581" call Dret("netrw#GX <".fname.">")
5582 return fname
5583endfun
5584
5585" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005586" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5587fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005588 let dict={}
5589 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005590 norm! gv"ay
5591 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005592 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005593 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005594endfun
5595
5596" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005597" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5598" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5599" to become an unlisted buffer, so in that case don't bwipe it.
5600fun! s:NetrwBufRename(newname)
5601" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5602" call Dredir("ls!","s:NetrwBufRename (before rename)")
5603 let oldbufname= bufname(bufnr("%"))
5604" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5605
5606 if oldbufname != a:newname
5607" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5608 let b:junk= 1
5609" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5610 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005611" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005612 let oldbufnr= bufnr(oldbufname)
5613" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5614" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5615 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5616" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5617 exe "bwipe! ".oldbufnr
5618" else " Decho
5619" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005620" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5621" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5622" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005623 endif
5624" call Dredir("ls!","s:NetrwBufRename (after rename)")
5625" else " Decho
5626" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5627 endif
5628
5629" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5630endfun
5631
5632" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005633" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005634fun! netrw#CheckIfRemote(...)
5635" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5636 if a:0 > 0
5637 let curfile= a:1
5638 else
5639 let curfile= expand("%")
5640 endif
5641" call Decho("curfile<".curfile.">")
5642 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005643" call Dret("netrw#CheckIfRemote 1")
5644 return 1
5645 else
5646" call Dret("netrw#CheckIfRemote 0")
5647 return 0
5648 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005649endfun
5650
5651" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005652" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5653fun! s:NetrwChgPerm(islocal,curdir)
5654" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005655 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005656 call inputsave()
5657 let newperm= input("Enter new permission: ")
5658 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005659 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5660 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5661" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005662 call system(chgperm)
5663 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005664 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005665 endif
5666 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005667 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005668 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005669 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005670" call Dret("s:NetrwChgPerm")
5671endfun
5672
5673" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005674" s:CheckIfKde: checks if kdeinit is running {{{2
5675" Returns 0: kdeinit not running
5676" 1: kdeinit is running
5677fun! s:CheckIfKde()
5678" call Dfunc("s:CheckIfKde()")
5679 " seems kde systems often have gnome-open due to dependencies, even though
5680 " gnome-open's subsidiary display tools are largely absent. Kde systems
5681 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5682 if !exists("s:haskdeinit")
5683 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005684 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005685 if v:shell_error
5686 let s:haskdeinit = 0
5687 endif
5688 else
5689 let s:haskdeinit= 0
5690 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005691" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005692 endif
5693
5694" call Dret("s:CheckIfKde ".s:haskdeinit)
5695 return s:haskdeinit
5696endfun
5697
5698" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005699" s:NetrwClearExplore: clear explore variables (if any) {{{2
5700fun! s:NetrwClearExplore()
5701" call Dfunc("s:NetrwClearExplore()")
5702 2match none
5703 if exists("s:explore_match") |unlet s:explore_match |endif
5704 if exists("s:explore_indx") |unlet s:explore_indx |endif
5705 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5706 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5707 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5708 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5709 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5710 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5711 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5712" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005713" call Dret("s:NetrwClearExplore")
5714endfun
5715
5716" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005717" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5718fun! s:NetrwEditBuf(bufnum)
5719" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5720 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5721" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5722 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5723 else
5724" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005725 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005726 endif
5727" call Dret("s:NetrwEditBuf")
5728endfun
5729
5730" ---------------------------------------------------------------------
5731" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5732" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5733fun! s:NetrwEditFile(cmd,opt,fname)
5734" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5735 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5736" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5737 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5738 else
5739" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005740 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5741 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5742 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005743 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5744 endif
5745" call Dret("s:NetrwEditFile")
5746endfun
5747
5748" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005749" s:NetrwExploreListUniq: {{{2
5750fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005751" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005752
5753 " this assumes that the list is already sorted
5754 let newexplist= []
5755 for member in a:explist
5756 if !exists("uniqmember") || member != uniqmember
5757 let uniqmember = member
5758 let newexplist = newexplist + [ member ]
5759 endif
5760 endfor
5761
Bram Moolenaar15146672011-10-20 22:22:38 +02005762" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005763 return newexplist
5764endfun
5765
5766" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005767" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5768fun! s:NetrwForceChgDir(islocal,newdir)
5769" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005770 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005771 if a:newdir !~ '/$'
5772 " ok, looks like force is needed to get directory-style treatment
5773 if a:newdir =~ '@$'
5774 let newdir= substitute(a:newdir,'@$','/','')
5775 elseif a:newdir =~ '[*=|\\]$'
5776 let newdir= substitute(a:newdir,'.$','/','')
5777 else
5778 let newdir= a:newdir.'/'
5779 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005780" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005781 else
5782 " should already be getting treatment as a directory
5783 let newdir= a:newdir
5784 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005785 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005786 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005787 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005788" call Dret("s:NetrwForceChgDir")
5789endfun
5790
5791" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005792" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005793" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5794" expr : this is the expression to follow the directory. Will use s:ComposePath()
5795" pare =1: remove the current directory from the resulting glob() filelist
5796" =0: leave the current directory in the resulting glob() filelist
5797fun! s:NetrwGlob(direntry,expr,pare)
5798" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005799 if netrw#CheckIfRemote()
5800 keepalt 1sp
5801 keepalt enew
5802 let keep_liststyle = w:netrw_liststyle
5803 let w:netrw_liststyle = s:THINLIST
5804 if s:NetrwRemoteListing() == 0
5805 keepj keepalt %s@/@@
5806 let filelist= getline(1,$)
5807 q!
5808 else
5809 " remote listing error -- leave treedict unchanged
5810 let filelist= w:netrw_treedict[a:direntry]
5811 endif
5812 let w:netrw_liststyle= keep_liststyle
5813 else
Christian Brabandt14879472024-06-13 21:25:35 +02005814 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005815 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005816 " escape [ so it is not detected as wildcard character, see :h wildcard
5817 let path= substitute(path, '[', '[[]', 'g')
5818 endif
5819 if v:version > 704 || (v:version == 704 && has("patch656"))
5820 let filelist= glob(path,0,1,1)
5821 else
5822 let filelist= glob(path,0,1)
5823 endif
5824 if a:pare
5825 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5826 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005827 endif
5828" call Dret("s:NetrwGlob ".string(filelist))
5829 return filelist
5830endfun
5831
5832" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005833" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5834fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005835" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005836 if a:newfile =~ '[/@*=|\\]$'
5837 let newfile= substitute(a:newfile,'.$','','')
5838 else
5839 let newfile= a:newfile
5840 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005841 if a:islocal
5842 call s:NetrwBrowseChgDir(a:islocal,newfile)
5843 else
5844 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5845 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005846" call Dret("s:NetrwForceFile")
5847endfun
5848
5849" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005850" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5851" and switches the hiding mode. The actual hiding is done by
5852" s:NetrwListHide().
5853" g:netrw_hide= 0: show all
5854" 1: show not-hidden files
5855" 2: show hidden files only
5856fun! s:NetrwHide(islocal)
5857" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005858 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005859 let svpos= winsaveview()
5860" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005861
5862 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005863" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5864" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005865
5866 " hide the files in the markfile list
5867 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005868" 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 +00005869 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5870 " remove fname from hiding list
5871 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5872 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5873 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005874" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005875 else
5876 " append fname to hiding list
5877 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5878 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5879 else
5880 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5881 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005882" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005883 endif
5884 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005885 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005886 let g:netrw_hide= 1
5887
5888 else
5889
5890 " switch between show-all/show-not-hidden/show-hidden
5891 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005892 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005893 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005894 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005895 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005896" call Dret("NetrwHide")
5897 return
5898 endif
5899 endif
5900
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005901 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005902" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5903 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005904 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005905" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005906endfun
5907
5908" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005909" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5910fun! s:NetrwHideEdit(islocal)
5911" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5912
5913 let ykeep= @@
5914 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005915 let svpos= winsaveview()
5916" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005917
5918 " get new hiding list from user
5919 call inputsave()
5920 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5921 call inputrestore()
5922 let g:netrw_list_hide= newhide
5923" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5924
5925 " refresh the listing
5926 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5927
5928 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005929" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5930 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005931 let @@= ykeep
5932
5933" call Dret("NetrwHideEdit")
5934endfun
5935
5936" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005937" s:NetrwHidden: invoked by "gh" {{{2
5938fun! s:NetrwHidden(islocal)
5939" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005940 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005941 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005942 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005943" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005944
5945 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005946 " remove .file pattern from hiding list
5947" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005948 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005949 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005950" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005951 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5952 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005953" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005954 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5955 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005956 if g:netrw_list_hide =~ '^,'
5957 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5958 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005959
5960 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005961 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005962" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5963 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005964 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005965" call Dret("s:NetrwHidden")
5966endfun
5967
5968" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005969" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5970fun! s:NetrwHome()
5971 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005972 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005973 else
5974 " go to vim plugin home
5975 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005976 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005977 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005978 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005979 let home= basehome."/.vim"
5980 break
5981 endif
5982 endfor
5983 if home == ""
5984 " just pick the first directory
5985 let home= substitute(&rtp,',.*$','','')
5986 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005987 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005988 let home= substitute(home,'/','\\','g')
5989 endif
5990 endif
5991 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005992 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005993" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005994 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005995" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005996 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005997 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005998" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005999 call mkdir(home)
6000 endif
6001 endif
6002 let g:netrw_home= home
6003 return home
6004endfun
6005
6006" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006007" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
6008fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006009 if exists("s:netrwdrag")
6010 return
6011 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006012 if &ft != "netrw"
6013 return
6014 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006015" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006016
Bram Moolenaar97d62492012-11-15 21:28:22 +01006017 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006018 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006019 while getchar(0) != 0
6020 "clear the input stream
6021 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006022 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006023 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006024 let mouse_lnum = v:mouse_lnum
6025 let wlastline = line('w$')
6026 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006027" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6028" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006029 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6030 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006031 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006032" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6033 return
6034 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006035 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006036 " 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 +01006037 " without this test when its disabled.
6038 " 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 +01006039" 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 +01006040 if v:mouse_col > virtcol('.')
6041 let @@= ykeep
6042" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6043 return
6044 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006045
Bram Moolenaar446cb832008-06-24 21:56:24 +00006046 if a:islocal
6047 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006048 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006049 endif
6050 else
6051 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006052 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006053 endif
6054 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006055 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006056" call Dret("s:NetrwLeftmouse")
6057endfun
6058
6059" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006060" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6061fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006062 if &ft != "netrw"
6063 return
6064 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006065" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6066 call s:NetrwMarkFileTgt(a:islocal)
6067" call Dret("s:NetrwCLeftmouse")
6068endfun
6069
6070" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006071" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6072" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006073" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006074" a:islocal=2 : <c-r> used, remote
6075" a:islocal=3 : <c-r> used, local
6076fun! s:NetrwServerEdit(islocal,fname)
6077" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6078 let islocal = a:islocal%2 " =0: remote =1: local
6079 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006080" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006081
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006082 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006083 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006084 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006085" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006086 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006087 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006088 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6089 unlet s:netrw_browse_split_{winnr()}
6090 endif
6091 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6092" call Dret("s:NetrwServerEdit")
6093 return
6094 endif
6095
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006096" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006097 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006098" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006099
6100 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006101" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006102 let srvrname = g:netrw_browse_split[0]
6103 let tabnum = g:netrw_browse_split[1]
6104 let winnum = g:netrw_browse_split[2]
6105
6106 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006107" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006108
6109 if !ctrlr
6110 " user must have closed the server window and the user did not use <c-r>, but
6111 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006112" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006113 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006114 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006115 endif
6116 let g:netrw_browse_split= 0
6117 if exists("s:netrw_browse_split_".winnr())
6118 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6119 endif
6120 call s:NetrwBrowseChgDir(islocal,a:fname)
6121" call Dret("s:NetrwServerEdit")
6122 return
6123
6124 elseif has("win32") && executable("start")
6125 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006126" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006127 call system("start gvim --servername ".srvrname)
6128
6129 else
6130 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006131" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006132 call system("gvim --servername ".srvrname)
6133 endif
6134 endif
6135
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006136" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006137 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6138 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006139 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006140
6141 else
6142
6143 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6144
6145 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006146" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006147 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006148 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006149 endif
6150 let g:netrw_browse_split= 0
6151 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6152" call Dret("s:NetrwServerEdit")
6153 return
6154
6155 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006156" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006157 if has("win32") && executable("start")
6158 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006159" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006160 call system("start gvim --servername ".g:netrw_servername)
6161 else
6162 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006163" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006164 call system("gvim --servername ".g:netrw_servername)
6165 endif
6166 endif
6167 endif
6168
6169 while 1
6170 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006171" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6172 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006173 break
6174 catch /^Vim\%((\a\+)\)\=:E241/
6175 sleep 200m
6176 endtry
6177 endwhile
6178
6179 if exists("g:netrw_browse_split")
6180 if type(g:netrw_browse_split) != 3
6181 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6182 endif
6183 unlet g:netrw_browse_split
6184 endif
6185 let g:netrw_browse_split= [g:netrw_servername,1,1]
6186 endif
6187
6188 else
6189 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6190 endif
6191
6192" call Dret("s:NetrwServerEdit")
6193endfun
6194
6195" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006196" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6197fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006198 if &ft != "netrw"
6199 return
6200 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006201" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006202
Bram Moolenaar8d043172014-01-23 14:24:41 +01006203 let s:ngw= s:NetrwGetWord()
6204 call s:NetrwMarkFile(a:islocal,s:ngw)
6205
6206" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006207endfun
6208
6209" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006210" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6211" Used to mark multiple files.
6212fun! s:NetrwSLeftdrag(islocal)
6213" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6214 if !exists("s:netrwdrag")
6215 let s:netrwdrag = winnr()
6216 if a:islocal
6217 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006218 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006219 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006220 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006221 endif
6222 let ngw = s:NetrwGetWord()
6223 if !exists("s:ngw") || s:ngw != ngw
6224 call s:NetrwMarkFile(a:islocal,ngw)
6225 endif
6226 let s:ngw= ngw
6227" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6228endfun
6229
6230" ---------------------------------------------------------------------
6231" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6232fun! s:NetrwSLeftrelease(islocal)
6233" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6234 if exists("s:netrwdrag")
6235 nunmap <s-leftrelease>
6236 let ngw = s:NetrwGetWord()
6237 if !exists("s:ngw") || s:ngw != ngw
6238 call s:NetrwMarkFile(a:islocal,ngw)
6239 endif
6240 if exists("s:ngw")
6241 unlet s:ngw
6242 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006243 unlet s:netrwdrag
6244 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006245" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006246endfun
6247
6248" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006249" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6250" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006251fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006252" 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 +02006253" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006254 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006255
6256 " 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 +02006257 " How-it-works: take the hiding command, convert it into a range.
6258 " Duplicate characters don't matter.
6259 " Remove all such characters from the '/~@#...890' string.
6260 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006261" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006262 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006263 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006264" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006265
6266 while listhide != ""
6267 if listhide =~ ','
6268 let hide = substitute(listhide,',.*$','','e')
6269 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6270 else
6271 let hide = listhide
6272 let listhide = ""
6273 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006274" 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 +01006275 if g:netrw_sort_by =~ '^[ts]'
6276 if hide =~ '^\^'
6277" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6278 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6279 elseif hide =~ '^\\(\^'
6280 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6281 endif
6282" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6283 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006284
6285 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006286" 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 +00006287 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006288" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006289 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006290 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006291" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006292 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006293 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006294" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006295 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006296
Bram Moolenaar446cb832008-06-24 21:56:24 +00006297 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006298 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006299" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006300 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006301" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006302 endif
6303
Bram Moolenaaradc21822011-04-01 18:03:16 +02006304 " remove any blank lines that have somehow remained.
6305 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006306 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006307
Bram Moolenaar97d62492012-11-15 21:28:22 +01006308 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006309" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006310endfun
6311
6312" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006313" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006314" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006315fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006316" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006317
Bram Moolenaar97d62492012-11-15 21:28:22 +01006318 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006319 " get name of new directory from user. A bare <CR> will skip.
6320 " if its currently a directory, also request will be skipped, but with
6321 " a message.
6322 call inputsave()
6323 let newdirname= input("Please give directory name: ")
6324 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006325" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006326
6327 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006328 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006329" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006330 return
6331 endif
6332
6333 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006334" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006335
6336 " Local mkdir:
6337 " sanity checks
6338 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006339" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6340 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006341 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006342 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006343 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006344 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006345" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006346 return
6347 endif
6348 if s:FileReadable(fullnewdir)
6349 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006350 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006351 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006352 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006353" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006354 return
6355 endif
6356
6357 " requested new local directory is neither a pre-existing file or
6358 " directory, so make it!
6359 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006360 if has("unix")
6361 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6362 else
6363 call mkdir(fullnewdir,"p")
6364 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006365 else
6366 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006367 if s:NetrwLcd(b:netrw_curdir)
6368" call Dret("s:NetrwMakeDir : lcd failure")
6369 return
6370 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006371" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006372 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006373 if v:shell_error != 0
6374 let @@= ykeep
6375 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 +01006376" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006377 return
6378 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006379 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006380" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006381 if s:NetrwLcd(netrw_origdir)
6382" call Dret("s:NetrwBrowse : lcd failure")
6383 return
6384 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006385 endif
6386 endif
6387
6388 if v:shell_error == 0
6389 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006390" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006391 let svpos= winsaveview()
6392" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006393 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006394" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6395 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006396 elseif !exists("g:netrw_quiet")
6397 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6398 endif
6399" redraw!
6400
6401 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006402 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006403" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006404 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6405 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006406 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006407 if v:shell_error == 0
6408 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006409 let svpos= winsaveview()
6410" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006411 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006412" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6413 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006414 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006415 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006416 endif
6417" redraw!
6418
6419 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006420 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006421 let svpos= winsaveview()
6422" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006423" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006424 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006425" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006426 let remotepath= b:netrw_fname
6427 else
6428 let remotepath= ""
6429 endif
6430 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006431 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006432" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6433 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006434
Bram Moolenaar446cb832008-06-24 21:56:24 +00006435 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006436 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006437 let svpos= winsaveview()
6438" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006439" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006440 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006441" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006442 let remotepath= b:netrw_fname
6443 else
6444 let remotepath= ""
6445 endif
6446 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006447 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006448" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6449 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006450 endif
6451
Bram Moolenaar97d62492012-11-15 21:28:22 +01006452 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006453" call Dret("s:NetrwMakeDir")
6454endfun
6455
6456" ---------------------------------------------------------------------
6457" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6458fun! s:TreeSqueezeDir(islocal)
6459" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6460 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6461 " its a tree-listing style
6462 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006463 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006464 let depth = strchars(substitute(curdepth,' ','','g'))
6465 let srch = -1
6466" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6467" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006468" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006469" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6470 if depth >= 2
6471 NetrwKeepj norm! 0
6472 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6473 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6474" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6475" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6476 elseif depth == 1
6477 NetrwKeepj norm! 0
6478 let treedepthchr= substitute(s:treedepthstring,' ','','')
6479 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6480" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6481 endif
6482 if srch > 0
6483" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6484 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6485 exe srch
6486 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006487 endif
6488" call Dret("s:TreeSqueezeDir")
6489endfun
6490
6491" ---------------------------------------------------------------------
6492" s:NetrwMaps: {{{2
6493fun! s:NetrwMaps(islocal)
6494" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6495
Bram Moolenaar85850f32019-07-19 22:05:51 +02006496 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006497 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006498" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006499 if !hasmapto("<Plug>NetrwReturn")
6500 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006501" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006502 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6503 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006504" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006505 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6506 endif
6507 endif
6508 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006509" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006510 endif
6511
Bram Moolenaar85850f32019-07-19 22:05:51 +02006512 " generate default <Plug> maps {{{3
6513 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006514 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006515 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6516 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6517 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6518 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6519 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6520 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6521 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6522 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6523 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6524 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6525" ---------------------------------------------------------------------
6526" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6527" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6528" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6529" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6530" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6531" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6532" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6533" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6534" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6535" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6536" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6537" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6538" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6539" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6540" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6541" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6542" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6543" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6544" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6545" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6546" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6547" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6548" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6549" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6550" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6551" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6552" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6553" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6554" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6555" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6556" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6557" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6558" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6559" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6560" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6561" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6562" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6563" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6564" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6565" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6566" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6567" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6568" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6569" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6570" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6571" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6572" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6573
Bram Moolenaara6878372014-03-22 21:02:50 +01006574 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006575" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006576 " local normal-mode maps {{{3
6577 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6578 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6579 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6580 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6581 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6582 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6583 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6584 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6585 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6586 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6587 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6588" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006589 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6590 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6591 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006592 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006593 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006594 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6595 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6596 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6597 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006598 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6599 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6600 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6601 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6602 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6603 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6604 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6605 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6606 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6607 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6608 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6609 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6610 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006611 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006612 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006613 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6614 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6615 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6616 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6617 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006618 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006619 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006620 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6621 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006622 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6623 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6624 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006625 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006626 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006627 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6628 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006629 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006630 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006631 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6632 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6633 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006634 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6635 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006636
6637 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 +01006638 if !hasmapto('<Plug>NetrwHideEdit')
6639 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006640 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006641 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006642 if !hasmapto('<Plug>NetrwRefresh')
6643 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006644 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006645 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 +01006646 if s:didstarstar || !mapcheck("<s-down>","n")
6647 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006648 endif
6649 if s:didstarstar || !mapcheck("<s-up>","n")
6650 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006651 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006652 if !hasmapto('<Plug>NetrwTreeSqueeze')
6653 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006654 endif
6655 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006656 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6657 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006658 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6659 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6660 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6661 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6662 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6663 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6664 imap <buffer> <leftmouse> <Plug>ILeftmouse
6665 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006666 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6667 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6668 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6669 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6670 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006671 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006672 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6673 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006674 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006675 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6676 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6677 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6678 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6679 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6680 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6681 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006682 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6683
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006684 " support user-specified maps
6685 call netrw#UserMaps(1)
6686
Bram Moolenaar85850f32019-07-19 22:05:51 +02006687 else
6688 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006689" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006690 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006691 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6692 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6693 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6694 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6695 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6696 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6697 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6698 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6699 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6700 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6701 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6702" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006703 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6704 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6705 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6706 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6707 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6708 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6709 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6710 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006711 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006712 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006713 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6714 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6715 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6716 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6717 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6718 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6719 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6720 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6721 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6722 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6723 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006724 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006725 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006726 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6727 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6728 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6729 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6730 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006731 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6732 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6733 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6734 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006735 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006736 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6737 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006738 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006739 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 +01006740 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6741 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6742 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6743 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6744 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6745 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6746 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6747 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6748 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006749 if !hasmapto('<Plug>NetrwHideEdit')
6750 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006751 endif
6752 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6753 if !hasmapto('<Plug>NetrwRefresh')
6754 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006755 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006756 if !hasmapto('<Plug>NetrwTreeSqueeze')
6757 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006758 endif
6759 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006760
6761 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006762 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006763
6764 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6765 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006766 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006767 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006768 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006769 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006770 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006771 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006772 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006773 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006774 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006775 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006776 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6777 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6778 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006779 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006780 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006781 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6782 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006783 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006784 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6785 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6786 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6787 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6788 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6789 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6790 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006791 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006792
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006793 " support user-specified maps
6794 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006795 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006796
6797" call Dret("s:NetrwMaps")
6798endfun
6799
6800" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006801" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006802" If -buffer, the command is only available from within netrw buffers
6803" Otherwise, the command is available from any window, so long as netrw
6804" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006805fun! s:NetrwCommands(islocal)
6806" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6807
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006808 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6809 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006810 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 +01006811 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006812 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006813 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006814 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006815 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006816 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006817
6818" call Dret("s:NetrwCommands")
6819endfun
6820
6821" ---------------------------------------------------------------------
6822" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6823" glob()ing only works with local files
6824fun! s:NetrwMarkFiles(islocal,...)
6825" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006826 let curdir = s:NetrwGetCurdir(a:islocal)
6827 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006828 while i <= a:0
6829 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006830 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006831 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006832 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006833 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006834 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006835 else
6836 let mffiles= [a:{i}]
6837 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006838" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006839 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006840" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006841 call s:NetrwMarkFile(a:islocal,mffile)
6842 endfor
6843 let i= i + 1
6844 endwhile
6845" call Dret("s:NetrwMarkFiles")
6846endfun
6847
6848" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006849" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006850fun! s:NetrwMarkTarget(...)
6851" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6852 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006853 let curdir = s:NetrwGetCurdir(1)
6854 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006855 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006856 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6857 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006858 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006859" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006860 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006861 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6862 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006863 let svpos = winsaveview()
6864" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006865 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006866" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6867 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006868" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006869endfun
6870
6871" ---------------------------------------------------------------------
6872" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6873" mark and unmark files. If a markfile list exists,
6874" then the rename and delete functions will use it instead
6875" of whatever may happen to be under the cursor at that
6876" moment. When the mouse and gui are available,
6877" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006878"
6879" Creates two lists
6880" s:netrwmarkfilelist -- holds complete paths to all marked files
6881" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6882"
6883" Creates a marked file match string
6884" s:netrwmarfilemtch_# -- used with 2match to display marked files
6885"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006886" Creates a buffer version of islocal
6887" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006888fun! s:NetrwMarkFile(islocal,fname)
6889" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006890" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006891
6892 " sanity check
6893 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006894" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006895 return
6896 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006897 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006898
Bram Moolenaar97d62492012-11-15 21:28:22 +01006899 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006900 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006901 if a:fname =~ '^\a'
6902 let leader= '\<'
6903 else
6904 let leader= ''
6905 endif
6906 if a:fname =~ '\a$'
6907 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6908 else
6909 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6910 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006911
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006912 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006913 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006914" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6915" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6916" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006917 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006918
6919 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006920 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006921" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006922 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006923 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006924
6925 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006926 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006927" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006928 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6929 if s:netrwmarkfilelist_{curbufnr} == []
6930 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006931" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006932 call s:NetrwUnmarkList(curbufnr,curdir)
6933 else
6934 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006935" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006936 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006937 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006938 for fname in s:netrwmarkfilelist_{curbufnr}
6939 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006940 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006941 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006942 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006943 endif
6944 let first= 0
6945 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006946" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006947 endif
6948 endif
6949
6950 else
6951 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006952" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006953
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006954" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006955 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006956 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6957" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006958
6959 " build initial markfile matching pattern
6960 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006961 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006962 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006963 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006964 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006965" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006966 endif
6967
6968 " handle global markfilelist
6969 if exists("s:netrwmarkfilelist")
6970 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6971 if index(s:netrwmarkfilelist,dname) == -1
6972 " append new filename to global markfilelist
6973 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006974" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006975 else
6976 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006977" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6978" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006979 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006980" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006981 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006982" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006983 unlet s:netrwmarkfilelist
6984 endif
6985 endif
6986 else
6987 " initialize new global-directory markfilelist
6988 let s:netrwmarkfilelist= []
6989 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006990" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006991 endif
6992
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006993 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006994 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6995 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6996" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6997 if exists("g:did_drchip_netrwlist_syntax")
6998 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6999 endif
7000 else
7001" " call Decho("2match none",'~'.expand("<slnum>"))
7002 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01007003 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007004 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007005 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007006" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
7007" 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 +00007008endfun
7009
7010" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007011" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7012" mA: move the argument list to marked file list (tomflist=1)
7013" Uses the global marked file list
7014fun! s:NetrwMarkFileArgList(islocal,tomflist)
7015" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7016
7017 let svpos = winsaveview()
7018" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7019 let curdir = s:NetrwGetCurdir(a:islocal)
7020 let curbufnr = bufnr("%")
7021
7022 if a:tomflist
7023 " mA: move argument list to marked file list
7024 while argc()
7025 let fname= argv(0)
7026" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7027 exe "argdel ".fnameescape(fname)
7028 call s:NetrwMarkFile(a:islocal,fname)
7029 endwhile
7030
7031 else
7032 " ma: move marked file list to argument list
7033 if exists("s:netrwmarkfilelist")
7034
7035 " for every filename in the marked list
7036 for fname in s:netrwmarkfilelist
7037" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7038 exe "argadd ".fnameescape(fname)
7039 endfor " for every file in the marked list
7040
7041 " unmark list and refresh
7042 call s:NetrwUnmarkList(curbufnr,curdir)
7043 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7044" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7045 NetrwKeepj call winrestview(svpos)
7046 endif
7047 endif
7048
7049" call Dret("s:NetrwMarkFileArgList")
7050endfun
7051
7052" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007053" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7054" compress/decompress files using the programs
7055" in g:netrw_compress and g:netrw_uncompress,
7056" using g:netrw_compress_suffix to know which to
7057" do. By default:
7058" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007059" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007060fun! s:NetrwMarkFileCompress(islocal)
7061" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007062 let svpos = winsaveview()
7063" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007064 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007065 let curbufnr = bufnr("%")
7066
Bram Moolenaarff034192013-04-24 18:51:19 +02007067 " sanity check
7068 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007069 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007070" call Dret("s:NetrwMarkFileCompress")
7071 return
7072 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007073" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007074
Bram Moolenaar446cb832008-06-24 21:56:24 +00007075 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007076
7077 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007078 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007079 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007080" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007081 if exists("g:netrw_decompress['".sfx."']")
7082 " fname has a suffix indicating that its compressed; apply associated decompression routine
7083 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007084" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007085 let exe= netrw#WinPath(exe)
7086 if a:islocal
7087 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007088 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007089 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007090 call system(exe." ".fname)
7091 if v:shell_error
7092 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007093 endif
7094 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007095 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7096 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007097 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007098
Bram Moolenaarff034192013-04-24 18:51:19 +02007099 endif
7100 unlet sfx
7101
Bram Moolenaar446cb832008-06-24 21:56:24 +00007102 if exists("exe")
7103 unlet exe
7104 elseif a:islocal
7105 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007106 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007107 if v:shell_error
7108 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7109 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007110 else
7111 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007112 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007113 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007114 endfor " for every file in the marked list
7115
Bram Moolenaar446cb832008-06-24 21:56:24 +00007116 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007117 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007118" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7119 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007120 endif
7121" call Dret("s:NetrwMarkFileCompress")
7122endfun
7123
7124" ---------------------------------------------------------------------
7125" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7126" If no marked files, then set up directory as the
7127" target. Currently does not support copying entire
7128" directories. Uses the local-buffer marked file list.
7129" Returns 1=success (used by NetrwMarkFileMove())
7130" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007131fun! s:NetrwMarkFileCopy(islocal,...)
7132" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7133
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007134 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007135 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007136 if b:netrw_curdir !~ '/$'
7137 if !exists("b:netrw_curdir")
7138 let b:netrw_curdir= curdir
7139 endif
7140 let b:netrw_curdir= b:netrw_curdir."/"
7141 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007142
Bram Moolenaarff034192013-04-24 18:51:19 +02007143 " sanity check
7144 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007145 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007146" call Dret("s:NetrwMarkFileCopy")
7147 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007148 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007149" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007150
Bram Moolenaar446cb832008-06-24 21:56:24 +00007151 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007152 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007153" call Dret("s:NetrwMarkFileCopy 0")
7154 return 0
7155 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007156" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007157
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007158 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007159 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007160" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007161 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007162 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7163" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7164 return
7165 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007166
7167 " copy marked files while within the same directory (ie. allow renaming)
7168 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7169 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7170 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007171" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007172 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007173 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7174 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007175" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007176 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007177 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007178 let oldname = a:1
7179 else
7180 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007181" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007182 let s:recursive= 1
7183 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7184 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7185 if ret == 0
7186 break
7187 endif
7188 endfor
7189 unlet s:recursive
7190 call s:NetrwUnmarkList(curbufnr,curdir)
7191" call Dret("s:NetrwMarkFileCopy ".ret)
7192 return ret
7193 endif
7194
7195 call inputsave()
7196 let newname= input("Copy ".oldname." to : ",oldname,"file")
7197 call inputrestore()
7198 if newname == ""
7199" call Dret("s:NetrwMarkFileCopy 0")
7200 return 0
7201 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007202 let args= s:ShellEscape(oldname)
7203 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007204 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007205 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7206 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007207 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007208 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007209 let args= substitute(args,'/','\\','g')
7210 let tgt = substitute(tgt, '/','\\','g')
7211 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007212 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7213 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7214 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7215 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7216" call Decho("args <".args.">",'~'.expand("<slnum>"))
7217" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007218 if isdirectory(s:NetrwFile(args))
7219" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007220 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007221" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007222 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007223 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7224 " contents to a target. One must append the source directory name to the target to get xcopy to
7225 " do the right thing.
7226 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007227" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007228 endif
7229 else
7230 let copycmd= g:netrw_localcopycmd
7231 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007232 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007233 let copycmd = substitute(copycmd,'\s.*$','','')
7234 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007235 let copycmd = netrw#WinPath(copycmd).copycmdargs
7236 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007237 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007238 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007239" call Decho("args <".args.">",'~'.expand("<slnum>"))
7240" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7241" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7242" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007243 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007244 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007245 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007246 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 +01007247 else
7248 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7249 endif
7250" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007251 return 0
7252 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007253
7254 elseif a:islocal && !s:netrwmftgt_islocal
7255 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007256" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007257 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007258
7259 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007260 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007261" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007262 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007263
7264 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007265 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007266" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007267 let curdir = getcwd()
7268 let tmpdir = s:GetTempfile("")
7269 if tmpdir !~ '/'
7270 let tmpdir= curdir."/".tmpdir
7271 endif
7272 if exists("*mkdir")
7273 call mkdir(tmpdir)
7274 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007275 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007276 if v:shell_error != 0
7277 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 +01007278" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007279 return
7280 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007281 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007282 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007283 if s:NetrwLcd(tmpdir)
7284" call Dret("s:NetrwMarkFileCopy : lcd failure")
7285 return
7286 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007287 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007288 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007289 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007290 if getcwd() == tmpdir
7291 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007292 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007293 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007294 if s:NetrwLcd(curdir)
7295" call Dret("s:NetrwMarkFileCopy : lcd failure")
7296 return
7297 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007298 if delete(tmpdir,"d")
7299 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007300 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007301 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007302 if s:NetrwLcd(curdir)
7303" call Dret("s:NetrwMarkFileCopy : lcd failure")
7304 return
7305 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007306 endif
7307 endif
7308 endif
7309
7310 " -------
7311 " cleanup
7312 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007313" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007314 " remove markings from local buffer
7315 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007316" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7317" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7318" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7319" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7320" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7321" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7322 if exists("s:recursive")
7323" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7324 else
7325" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007326 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007327 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007328 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007329 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007330 else
7331 " refresh local and targets for fast browsing
7332 if !exists("s:recursive")
7333 " remove markings from local buffer
7334" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7335 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7336 endif
7337
7338 " refresh buffers
7339 if s:netrwmftgt_islocal
7340" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7341 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7342 endif
7343 if a:islocal && s:netrwmftgt != curdir
7344" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7345 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7346 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007347 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007348
Bram Moolenaar446cb832008-06-24 21:56:24 +00007349" call Dret("s:NetrwMarkFileCopy 1")
7350 return 1
7351endfun
7352
7353" ---------------------------------------------------------------------
7354" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7355" invoke vim's diff mode on the marked files.
7356" Either two or three files can be so handled.
7357" Uses the global marked file list.
7358fun! s:NetrwMarkFileDiff(islocal)
7359" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7360 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361
Bram Moolenaarff034192013-04-24 18:51:19 +02007362 " sanity check
7363 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007364 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007365" call Dret("s:NetrwMarkFileDiff")
7366 return
7367 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007368 let curdir= s:NetrwGetCurdir(a:islocal)
7369" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007370
Bram Moolenaara6878372014-03-22 21:02:50 +01007371 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007372 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007373 for fname in s:netrwmarkfilelist
7374 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007375 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007376" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007377 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007378 diffthis
7379 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007380 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007381" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007382 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007383 diffthis
7384 else
7385 break
7386 endif
7387 endfor
7388 call s:NetrwUnmarkList(curbufnr,curdir)
7389 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007390
Bram Moolenaar446cb832008-06-24 21:56:24 +00007391" call Dret("s:NetrwMarkFileDiff")
7392endfun
7393
7394" ---------------------------------------------------------------------
7395" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7396" Uses global markfilelist
7397fun! s:NetrwMarkFileEdit(islocal)
7398" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7399
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007400 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007401 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007402
7403 " sanity check
7404 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007405 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007406" call Dret("s:NetrwMarkFileEdit")
7407 return
7408 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007409" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007410
Bram Moolenaar446cb832008-06-24 21:56:24 +00007411 if exists("s:netrwmarkfilelist_{curbufnr}")
7412 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007413 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007414 " unmark markedfile list
7415" call s:NetrwUnmarkList(curbufnr,curdir)
7416 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007417" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007418 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007419 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007420 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007421
Bram Moolenaar446cb832008-06-24 21:56:24 +00007422" call Dret("s:NetrwMarkFileEdit")
7423endfun
7424
7425" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007426" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007427fun! s:NetrwMarkFileQFEL(islocal,qfel)
7428" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7429 call s:NetrwUnmarkAll()
7430 let curbufnr= bufnr("%")
7431
7432 if !empty(a:qfel)
7433 for entry in a:qfel
7434 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007435" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007436 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007437" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007438 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7439 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7440 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7441 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007442" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007443 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7444 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007445" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007446 endif
7447 endfor
7448 echo "(use me to edit marked files)"
7449 else
7450 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7451 endif
7452
7453" call Dret("s:NetrwMarkFileQFEL")
7454endfun
7455
7456" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007457" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7458" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7459" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7460fun! s:NetrwMarkFileExe(islocal,enbloc)
7461" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007462 let svpos = winsaveview()
7463" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007464 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007465 let curbufnr = bufnr("%")
7466
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007467 if a:enbloc == 0
7468 " individually apply command to files, one at a time
7469 " sanity check
7470 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7471 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7472" call Dret("s:NetrwMarkFileExe")
7473 return
7474 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007475" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007476
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007477 if exists("s:netrwmarkfilelist_{curbufnr}")
7478 " get the command
7479 call inputsave()
7480 let cmd= input("Enter command: ","","file")
7481 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007482" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483 if cmd == ""
7484" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7485 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007486 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007487
7488 " apply command to marked files, individually. Substitute: filename -> %
7489 " If no %, then append a space and the filename to the command
7490 for fname in s:netrwmarkfilelist_{curbufnr}
7491 if a:islocal
7492 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007493 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007494 endif
7495 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007496 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007497 endif
7498 if cmd =~ '%'
7499 let xcmd= substitute(cmd,'%',fname,'g')
7500 else
7501 let xcmd= cmd.' '.fname
7502 endif
7503 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007504" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007505 let ret= system(xcmd)
7506 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007507" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007508 let ret= s:RemoteSystem(xcmd)
7509 endif
7510 if v:shell_error < 0
7511 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7512 break
7513 else
7514 echo ret
7515 endif
7516 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007517
7518 " unmark marked file list
7519 call s:NetrwUnmarkList(curbufnr,curdir)
7520
7521 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007522 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007523" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7524 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007525 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007526 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007527 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007528
7529 else " apply command to global list of files, en bloc
7530
7531 call inputsave()
7532 let cmd= input("Enter command: ","","file")
7533 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007534" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007535 if cmd == ""
7536" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7537 return
7538 endif
7539 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007540 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007541 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007542 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007543 endif
7544 if a:islocal
7545 call system(cmd)
7546 if v:shell_error < 0
7547 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7548 endif
7549 else
7550 let ret= s:RemoteSystem(cmd)
7551 endif
7552 call s:NetrwUnmarkAll()
7553
7554 " refresh the listing
7555 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007556" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7557 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007558
7559 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007560
Bram Moolenaar446cb832008-06-24 21:56:24 +00007561" call Dret("s:NetrwMarkFileExe")
7562endfun
7563
7564" ---------------------------------------------------------------------
7565" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7566" as the marked file(s) (toggles suffix presence)
7567" Uses the local marked file list.
7568fun! s:NetrwMarkHideSfx(islocal)
7569" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007570 let svpos = winsaveview()
7571" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007572 let curbufnr = bufnr("%")
7573
7574 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7575 if exists("s:netrwmarkfilelist_{curbufnr}")
7576
7577 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007578" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007579 " construct suffix pattern
7580 if fname =~ '\.'
7581 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7582 else
7583 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7584 endif
7585 " determine if its in the hiding list or not
7586 let inhidelist= 0
7587 if g:netrw_list_hide != ""
7588 let itemnum = 0
7589 let hidelist= split(g:netrw_list_hide,',')
7590 for hidepat in hidelist
7591 if sfxpat == hidepat
7592 let inhidelist= 1
7593 break
7594 endif
7595 let itemnum= itemnum + 1
7596 endfor
7597 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007598" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007599 if inhidelist
7600 " remove sfxpat from list
7601 call remove(hidelist,itemnum)
7602 let g:netrw_list_hide= join(hidelist,",")
7603 elseif g:netrw_list_hide != ""
7604 " append sfxpat to non-empty list
7605 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7606 else
7607 " set hiding list to sfxpat
7608 let g:netrw_list_hide= sfxpat
7609 endif
7610 endfor
7611
7612 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007613 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007614" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7615 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007616 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007617 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007618 endif
7619
7620" call Dret("s:NetrwMarkHideSfx")
7621endfun
7622
7623" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007624" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007625" Uses the local marked-file list.
7626fun! s:NetrwMarkFileVimCmd(islocal)
7627" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007628 let svpos = winsaveview()
7629" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007630 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007631 let curbufnr = bufnr("%")
7632
Bram Moolenaarff034192013-04-24 18:51:19 +02007633 " sanity check
7634 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007635 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007636" call Dret("s:NetrwMarkFileVimCmd")
7637 return
7638 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007639" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007640
Bram Moolenaar15146672011-10-20 22:22:38 +02007641 if exists("s:netrwmarkfilelist_{curbufnr}")
7642 " get the command
7643 call inputsave()
7644 let cmd= input("Enter vim command: ","","file")
7645 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007646" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007647 if cmd == ""
7648" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7649 return
7650 endif
7651
7652 " apply command to marked files. Substitute: filename -> %
7653 " If no %, then append a space and the filename to the command
7654 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007655" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007656 if a:islocal
7657 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007658 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007659" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007660 exe cmd
7661 exe "sil! keepalt wq!"
7662 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007663" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007664 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007665 endif
7666 endfor
7667
7668 " unmark marked file list
7669 call s:NetrwUnmarkList(curbufnr,curdir)
7670
7671 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007672 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007673" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7674 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007675 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007676 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007677 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007678
Bram Moolenaar15146672011-10-20 22:22:38 +02007679" call Dret("s:NetrwMarkFileVimCmd")
7680endfun
7681
7682" ---------------------------------------------------------------------
7683" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7684" as the marked file(s) (toggles suffix presence)
7685" Uses the local marked file list.
7686fun! s:NetrwMarkHideSfx(islocal)
7687" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007688 let svpos = winsaveview()
7689" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007690 let curbufnr = bufnr("%")
7691
7692 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7693 if exists("s:netrwmarkfilelist_{curbufnr}")
7694
7695 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007696" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007697 " construct suffix pattern
7698 if fname =~ '\.'
7699 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7700 else
7701 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7702 endif
7703 " determine if its in the hiding list or not
7704 let inhidelist= 0
7705 if g:netrw_list_hide != ""
7706 let itemnum = 0
7707 let hidelist= split(g:netrw_list_hide,',')
7708 for hidepat in hidelist
7709 if sfxpat == hidepat
7710 let inhidelist= 1
7711 break
7712 endif
7713 let itemnum= itemnum + 1
7714 endfor
7715 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007716" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007717 if inhidelist
7718 " remove sfxpat from list
7719 call remove(hidelist,itemnum)
7720 let g:netrw_list_hide= join(hidelist,",")
7721 elseif g:netrw_list_hide != ""
7722 " append sfxpat to non-empty list
7723 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7724 else
7725 " set hiding list to sfxpat
7726 let g:netrw_list_hide= sfxpat
7727 endif
7728 endfor
7729
7730 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007731 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007732" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7733 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007734 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007735 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007736 endif
7737
7738" call Dret("s:NetrwMarkHideSfx")
7739endfun
7740
7741" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007742" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7743" Uses the global markfilelist
7744fun! s:NetrwMarkFileGrep(islocal)
7745" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007746 let svpos = winsaveview()
7747" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007748 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007749 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007750
7751 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007752" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007753 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007754" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007755 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007756 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007757" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007758 let netrwmarkfilelist= "*"
7759 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007760
Bram Moolenaarff034192013-04-24 18:51:19 +02007761 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007762" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007763 call inputsave()
7764 let pat= input("Enter pattern: ","")
7765 call inputrestore()
7766 let patbang = ""
7767 if pat =~ '^!'
7768 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007769 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007770 endif
7771 if pat =~ '^\i'
7772 let pat = escape(pat,'/')
7773 let pat = '/'.pat.'/'
7774 else
7775 let nonisi = pat[0]
7776 endif
7777
7778 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007779" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007780 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007781 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007782 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007783 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007784" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7785 return
7786 endtry
7787 echo "(use :cn, :cp to navigate, :Rex to return)"
7788
7789 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007790" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7791 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007792
7793 if exists("nonisi")
7794 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007795" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007796 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007797 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007798 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007799 endif
7800
7801" call Dret("s:NetrwMarkFileGrep")
7802endfun
7803
7804" ---------------------------------------------------------------------
7805" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7806" uses the global marked file list
7807" s:netrwmfloc= 0: target directory is remote
7808" = 1: target directory is local
7809fun! s:NetrwMarkFileMove(islocal)
7810" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007811 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007812 let curbufnr = bufnr("%")
7813
7814 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007815 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007816 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817" call Dret("s:NetrwMarkFileMove")
7818 return
7819 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007820" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007821
Bram Moolenaar446cb832008-06-24 21:56:24 +00007822 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007823 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007824" call Dret("s:NetrwMarkFileCopy 0")
7825 return 0
7826 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007827" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007828
7829 if a:islocal && s:netrwmftgt_islocal
7830 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007831" call Decho("move from local to local",'~'.expand("<slnum>"))
7832" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007833 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007834 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7835" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7836 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007837 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007838 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007839" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007840 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007841 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007842" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007843 if g:netrw_localmovecmd =~ '\s'
7844 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7845 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7846 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007847" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007848 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007849 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007850" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007851 endif
7852 else
7853 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007854" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007855 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007856 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007857 if g:netrw_keepdir
7858 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7859 let fname= b:netrw_curdir."/".fname
7860 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007861 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007862 let fname= substitute(fname,'/','\\','g')
7863 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007864" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007865 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007866 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007867 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007868 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 +01007869 else
7870 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7871 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007872 break
7873 endif
7874 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007875
7876 elseif a:islocal && !s:netrwmftgt_islocal
7877 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007878" call Decho("move from local to remote",'~'.expand("<slnum>"))
7879" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007880 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007881 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007882" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007883 for fname in mflist
7884 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7885 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7886 endfor
7887 unlet mflist
7888
7889 elseif !a:islocal && s:netrwmftgt_islocal
7890 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007891" call Decho("move from remote to local",'~'.expand("<slnum>"))
7892" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007893 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007894 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007895" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007896 for fname in mflist
7897 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7898 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7899 endfor
7900 unlet mflist
7901
7902 elseif !a:islocal && !s:netrwmftgt_islocal
7903 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007904" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7905" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007906 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007907 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007908" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007909 for fname in mflist
7910 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7911 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7912 endfor
7913 unlet mflist
7914 endif
7915
7916 " -------
7917 " cleanup
7918 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007919" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007920
7921 " remove markings from local buffer
7922 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7923
7924 " refresh buffers
7925 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007926" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007927 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007928 endif
7929 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007930" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007931 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007932 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007933 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007934" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007935 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007936 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007937
Bram Moolenaar446cb832008-06-24 21:56:24 +00007938" call Dret("s:NetrwMarkFileMove")
7939endfun
7940
7941" ---------------------------------------------------------------------
7942" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7943" using the hardcopy command. Local marked-file list only.
7944fun! s:NetrwMarkFilePrint(islocal)
7945" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7946 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007947
7948 " sanity check
7949 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007950 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007951" call Dret("s:NetrwMarkFilePrint")
7952 return
7953 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007954" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7955 let curdir= s:NetrwGetCurdir(a:islocal)
7956
Bram Moolenaar446cb832008-06-24 21:56:24 +00007957 if exists("s:netrwmarkfilelist_{curbufnr}")
7958 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007959 call s:NetrwUnmarkList(curbufnr,curdir)
7960 for fname in netrwmarkfilelist
7961 if a:islocal
7962 if g:netrw_keepdir
7963 let fname= s:ComposePath(curdir,fname)
7964 endif
7965 else
7966 let fname= curdir.fname
7967 endif
7968 1split
7969 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007970" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007971 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007972" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007973 hardcopy
7974 q
7975 endfor
7976 2match none
7977 endif
7978" call Dret("s:NetrwMarkFilePrint")
7979endfun
7980
7981" ---------------------------------------------------------------------
7982" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7983" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007984" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007985fun! s:NetrwMarkFileRegexp(islocal)
7986" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7987
7988 " get the regular expression
7989 call inputsave()
7990 let regexp= input("Enter regexp: ","","file")
7991 call inputrestore()
7992
7993 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007994 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007995" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007996 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007997" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007998 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007999 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008000 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008001 else
8002 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008003 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008004 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008005" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006
8007 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008008 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02008009 if fname =~ '^'.fnameescape(curdir)
8010" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8011 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8012 else
8013" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8014 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8015 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008016 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008017
8018 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008019" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008020
8021 " convert displayed listing into a filelist
8022 let eikeep = &ei
8023 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008024 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008025 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008026" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008028 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008029 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008030 sil NetrwKeepj norm! "ap
8031 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008032 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008033 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008034 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008035 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008036 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008037 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008038 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008039 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008040 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008041 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008042 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8043 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008044 call histdel("/",-1)
8045 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008046 endif
8047 " convert regexp into the more usual glob-style format
8048 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008049" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008050 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008051 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008052 let filelist= getline(1,line("$"))
8053 q!
8054 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008055 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008056 endfor
8057 unlet filelist
8058 let @a = areg
8059 let &ei = eikeep
8060 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008061 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008062
8063" call Dret("s:NetrwMarkFileRegexp")
8064endfun
8065
8066" ---------------------------------------------------------------------
8067" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8068" Uses the local marked file list.
8069fun! s:NetrwMarkFileSource(islocal)
8070" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8071 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008072
8073 " sanity check
8074 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008075 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008076" call Dret("s:NetrwMarkFileSource")
8077 return
8078 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008079" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8080 let curdir= s:NetrwGetCurdir(a:islocal)
8081
Bram Moolenaar446cb832008-06-24 21:56:24 +00008082 if exists("s:netrwmarkfilelist_{curbufnr}")
8083 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008084 call s:NetrwUnmarkList(curbufnr,curdir)
8085 for fname in netrwmarkfilelist
8086 if a:islocal
8087 if g:netrw_keepdir
8088 let fname= s:ComposePath(curdir,fname)
8089 endif
8090 else
8091 let fname= curdir.fname
8092 endif
8093 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008094" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008095 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008096 endfor
8097 2match none
8098 endif
8099" call Dret("s:NetrwMarkFileSource")
8100endfun
8101
8102" ---------------------------------------------------------------------
8103" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8104" Uses the global markfilelist
8105fun! s:NetrwMarkFileTag(islocal)
8106" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008107 let svpos = winsaveview()
8108" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008109 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008110 let curbufnr = bufnr("%")
8111
Bram Moolenaarff034192013-04-24 18:51:19 +02008112 " sanity check
8113 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008114 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008115" call Dret("s:NetrwMarkFileTag")
8116 return
8117 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008118" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008119
Bram Moolenaar446cb832008-06-24 21:56:24 +00008120 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008121" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8122 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008123 call s:NetrwUnmarkAll()
8124
8125 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008126
8127" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8128 call system(g:netrw_ctags." ".netrwmarkfilelist)
8129 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008130 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8131 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008132
Bram Moolenaar446cb832008-06-24 21:56:24 +00008133 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008134 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008135 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008136 let curdir= b:netrw_curdir
8137 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008138 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008139 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008140" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008141 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008142 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008143 wq!
8144 endif
8145 2match none
8146 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008147" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8148 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149 endif
8150
8151" call Dret("s:NetrwMarkFileTag")
8152endfun
8153
8154" ---------------------------------------------------------------------
8155" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008156" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008157" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008158" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008159" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008160fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008161" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8162 let svpos = winsaveview()
8163" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008164 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008165 let hadtgt = exists("s:netrwmftgt")
8166 if !exists("w:netrw_bannercnt")
8167 let w:netrw_bannercnt= b:netrw_bannercnt
8168 endif
8169
8170 " set up target
8171 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008172" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008173 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8174 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008175" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008176 unlet s:netrwmftgt s:netrwmftgt_islocal
8177 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008178 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008179 endif
8180 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008181" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8182 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008183" call Dret("s:NetrwMarkFileTgt : removed target")
8184 return
8185 else
8186 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008187" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008188 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008189
8190 else
8191 " get word under cursor.
8192 " * If directory, use it for the target.
8193 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008194" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008195 let curword= s:NetrwGetWord()
8196 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008197 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008198 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008199" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008200 elseif !a:islocal && tgtdir =~ '/$'
8201 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008202" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008203 else
8204 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008205" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008206 endif
8207 endif
8208 if a:islocal
8209 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8210 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008211" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008212 endif
8213 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008214 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008215 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8216 endif
8217 let s:netrwmftgt_islocal= a:islocal
8218
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008219 " need to do refresh so that the banner will be updated
8220 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008221 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008222" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008223 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008224 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008225" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008226 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008227 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8228 else
8229 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8230 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008231" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8232 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008233 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008234 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008235 endif
8236
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008237" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8238" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008239" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8240endfun
8241
8242" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008243" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8244fun! s:NetrwGetCurdir(islocal)
8245" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8246
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008247 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008248 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8249" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8250 elseif !exists("b:netrw_curdir")
8251 let b:netrw_curdir= getcwd()
8252" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8253 endif
8254
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008255" 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 +01008256 if b:netrw_curdir !~ '\<\a\{3,}://'
8257 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008258" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008259 if g:netrw_keepdir == 0
8260 call s:NetrwLcd(curdir)
8261 endif
8262 endif
8263
8264" call Dret("s:NetrwGetCurdir <".curdir.">")
8265 return b:netrw_curdir
8266endfun
8267
8268" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008269" s:NetrwOpenFile: query user for a filename and open it {{{2
8270fun! s:NetrwOpenFile(islocal)
8271" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008272 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008273 call inputsave()
8274 let fname= input("Enter filename: ")
8275 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008276" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8277
8278 " determine if Lexplore is in use
8279 if exists("t:netrw_lexbufnr")
8280 " check if t:netrw_lexbufnr refers to a netrw window
8281" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8282 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8283 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8284" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8285 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8286 exe "NetrwKeepj e ".fnameescape(fname)
8287 let @@= ykeep
8288" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8289 endif
8290 endif
8291
8292 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008293 if fname !~ '[/\\]'
8294 if exists("b:netrw_curdir")
8295 if exists("g:netrw_quiet")
8296 let netrw_quiet_keep = g:netrw_quiet
8297 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008298 let g:netrw_quiet = 1
8299 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008300 let s:rexposn_{bufnr("%")}= winsaveview()
8301" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008302 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008303 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008304 else
8305 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8306 endif
8307 if exists("netrw_quiet_keep")
8308 let g:netrw_quiet= netrw_quiet_keep
8309 else
8310 unlet g:netrw_quiet
8311 endif
8312 endif
8313 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008314 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008315 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008316 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008317" call Dret("s:NetrwOpenFile")
8318endfun
8319
8320" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008321" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8322" For the mapping to this function be made via
8323" netrwPlugin, you'll need to have had
8324" g:netrw_usetab set to non-zero.
8325fun! netrw#Shrink()
8326" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8327 let curwin = winnr()
8328 let wiwkeep = &wiw
8329 set wiw=1
8330
8331 if &ft == "netrw"
8332 if winwidth(0) > g:netrw_wiw
8333 let t:netrw_winwidth= winwidth(0)
8334 exe "vert resize ".g:netrw_wiw
8335 wincmd l
8336 if winnr() == curwin
8337 wincmd h
8338 endif
8339" call Decho("vert resize 0",'~'.expand("<slnum>"))
8340 else
8341 exe "vert resize ".t:netrw_winwidth
8342" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8343 endif
8344
8345 elseif exists("t:netrw_lexbufnr")
8346 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8347 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8348 let t:netrw_winwidth= winwidth(0)
8349 exe "vert resize ".g:netrw_wiw
8350 wincmd l
8351 if winnr() == curwin
8352 wincmd h
8353 endif
8354" call Decho("vert resize 0",'~'.expand("<slnum>"))
8355 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8356 exe "vert resize ".t:netrw_winwidth
8357" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8358 else
8359 call netrw#Lexplore(0,0)
8360 endif
8361
8362 else
8363 call netrw#Lexplore(0,0)
8364 endif
8365 let wiw= wiwkeep
8366
8367" call Dret("netrw#Shrink")
8368endfun
8369
8370" ---------------------------------------------------------------------
8371" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8372fun! s:NetSortSequence(islocal)
8373" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8374
8375 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008376 let svpos= winsaveview()
8377" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008378 call inputsave()
8379 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8380 call inputrestore()
8381
8382 " refresh the listing
8383 let g:netrw_sort_sequence= newsortseq
8384 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008385" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8386 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008387 let @@= ykeep
8388
8389" call Dret("NetSortSequence")
8390endfun
8391
8392" ---------------------------------------------------------------------
8393" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8394" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008395" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008396fun! s:NetrwUnmarkList(curbufnr,curdir)
8397" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8398
8399 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008400 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008401 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8402 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8403 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8404 call remove(s:netrwmarkfilelist,idx) " remove from global list
8405 endfor
8406 if s:netrwmarkfilelist == []
8407 unlet s:netrwmarkfilelist
8408 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008409
Bram Moolenaar446cb832008-06-24 21:56:24 +00008410 " getting rid of the local marked-file lists is easy
8411 unlet s:netrwmarkfilelist_{a:curbufnr}
8412 endif
8413 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8414 unlet s:netrwmarkfilemtch_{a:curbufnr}
8415 endif
8416 2match none
8417" call Dret("s:NetrwUnmarkList")
8418endfun
8419
8420" ---------------------------------------------------------------------
8421" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8422fun! s:NetrwUnmarkAll()
8423" call Dfunc("s:NetrwUnmarkAll()")
8424 if exists("s:netrwmarkfilelist")
8425 unlet s:netrwmarkfilelist
8426 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008427 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008428 2match none
8429" call Dret("s:NetrwUnmarkAll")
8430endfun
8431
8432" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008433" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008434fun! s:NetrwUnmarkAll2()
8435" call Dfunc("s:NetrwUnmarkAll2()")
8436 redir => netrwmarkfilelist_let
8437 let
8438 redir END
8439 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008440 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008441 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8442 for flist in netrwmarkfilelist_list
8443 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8444 unlet s:netrwmarkfilelist_{curbufnr}
8445 unlet s:netrwmarkfilemtch_{curbufnr}
8446 endfor
8447" call Dret("s:NetrwUnmarkAll2")
8448endfun
8449
8450" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008451" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8452"
8453" Marked files are in two types of lists:
8454" s:netrwmarkfilelist -- holds complete paths to all marked files
8455" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8456"
8457" Marked files suitable for use with 2match are in:
8458" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008459fun! s:NetrwUnMarkFile(islocal)
8460" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008461 let svpos = winsaveview()
8462" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008463 let curbufnr = bufnr("%")
8464
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008465 " unmark marked file list
8466 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8467 if exists("s:netrwmarkfilelist")
8468" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008469 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008470 endif
8471
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008472 let ibuf= 1
8473 while ibuf < bufnr("$")
8474 if exists("s:netrwmarkfilelist_".ibuf)
8475 unlet s:netrwmarkfilelist_{ibuf}
8476 unlet s:netrwmarkfilemtch_{ibuf}
8477 endif
8478 let ibuf = ibuf + 1
8479 endwhile
8480 2match none
8481
Bram Moolenaar446cb832008-06-24 21:56:24 +00008482" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008483"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8484call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008485" call Dret("s:NetrwUnMarkFile")
8486endfun
8487
8488" ---------------------------------------------------------------------
8489" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8490fun! s:NetrwMenu(domenu)
8491
8492 if !exists("g:NetrwMenuPriority")
8493 let g:NetrwMenuPriority= 80
8494 endif
8495
Bram Moolenaaradc21822011-04-01 18:03:16 +02008496 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008497" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8498
8499 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008500" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008501 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008502 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8506 if g:netrw_dirhistmax > 0
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8511 else
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8513 endif
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8528 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 +01008529 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 +02008530 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8552 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8553 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8555 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8556 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8558 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8559 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>'
8560 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>'
8561 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>'
8562 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8563 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>'
8564 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>'
8565 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 +01008566 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 +02008567 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8568 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008569 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008570 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8571 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008572
8573 elseif !a:domenu
8574 let s:netrwcnt = 0
8575 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008576 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008577 exe curwin."wincmd w"
8578
8579 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008580" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008581 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008582" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008583 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008584 endif
8585 endif
8586" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008587 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008588 endif
8589
8590endfun
8591
8592" ---------------------------------------------------------------------
8593" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8594" Used by the O maps (as <SID>NetrwObtain())
8595fun! s:NetrwObtain(islocal)
8596" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8597
Bram Moolenaar97d62492012-11-15 21:28:22 +01008598 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008599 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008600 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008601 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008602 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8603 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008604 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008605 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008606 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607
8608" call Dret("NetrwObtain")
8609endfun
8610
8611" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8613" If there's only one window, then the window will first be split.
8614" Returns:
8615" choice = 0 : didn't have to choose
8616" choice = 1 : saved modified file in window first
8617" choice = 2 : didn't save modified file, opened window
8618" choice = 3 : cancel open
8619fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008620" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008621
Bram Moolenaar97d62492012-11-15 21:28:22 +01008622 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008623 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008624 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008625" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008626
8627 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008628 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008629 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008630" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8631" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8632 let curword = s:NetrwGetWord()
8633 let choice = 0
8634 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8635" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008636 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008637" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008638 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008639" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008640" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008641" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008642
Bram Moolenaar8d043172014-01-23 14:24:41 +01008643 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008644 if lastwinnr == 1
8645 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008646" 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 +02008647 " g:netrw_preview=0: preview window shown in a horizontally split window
8648 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008649 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008650 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008651 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008652" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008653 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008654 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008655 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008656 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008657" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008658 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008659 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008660 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008661" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008662
8663 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008664" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008665 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008666" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008667 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008668" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008669 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008670" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008671 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008672" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008673" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008674" call Decho("COMBAK#12: mod=".&mod)
8675
8676 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8677 " whoops -- user trying to open file in the Lexplore window.
8678 " Use Lexplore's opening-file window instead.
8679" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8680" exe g:netrw_chgwin."wincmd w"
8681 wincmd p
8682 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8683 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008684
8685 " prevwinnr: the window number of the "prev" window
8686 " prevbufnr: the buffer number of the buffer in the "prev" window
8687 " bnrcnt : the qty of windows open on the "prev" buffer
8688 let prevwinnr = winnr()
8689 let prevbufnr = bufnr("%")
8690 let prevbufname = bufname("%")
8691 let prevmod = &mod
8692 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008693" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008694 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008695" 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 +01008696" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008697
8698 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008699 " and it doesn't appear in any other extant window, then ask the
8700 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008701 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008702" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008703 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008704" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008705 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008706" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008707
8708 if bnrcnt == 1 && &hidden == 0
8709 " only one copy of the modified buffer in a window, and
8710 " hidden not set, so overwriting will lose the modified file. Ask first...
8711 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008712" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008713 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008714" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008715
8716 if choice == 1
8717 " Yes -- write file & then browse
8718 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008719 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008720 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008721 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008722 exe origwin."wincmd w"
8723 let &ei = eikeep
8724 let @@ = ykeep
8725" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008726 return choice
8727 endif
8728
8729 elseif choice == 2
8730 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008731" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008732 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008733
8734 else
8735 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008736" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008737 exe origwin."wincmd w"
8738 let &ei= eikeep
8739 let @@ = ykeep
8740" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008741 return choice
8742 endif
8743 endif
8744 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008745 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008746 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008747" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008748
8749 " restore b:netrw_curdir (window split/enew may have lost it)
8750 let b:netrw_curdir= curdir
8751 if a:islocal < 2
8752 if a:islocal
8753 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8754 else
8755 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8756 endif
8757 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008758 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008759" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008760 return choice
8761endfun
8762
8763" ---------------------------------------------------------------------
8764" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8765" Always assumed to be local -> remote
8766" call s:NetrwUpload(filename, target)
8767" call s:NetrwUpload(filename, target, fromdirectory)
8768fun! s:NetrwUpload(fname,tgt,...)
8769" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8770
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008771 if a:tgt =~ '^\a\{3,}://'
8772 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008773 else
8774 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8775 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008776" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008777
8778 if a:0 > 0
8779 let fromdir= a:1
8780 else
8781 let fromdir= getcwd()
8782 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008784
8785 if type(a:fname) == 1
8786 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008787" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008788 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008789" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8790 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8791" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792 if a:tgt =~ '/$'
8793 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008794" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008795 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008796 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008797" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008798 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008799" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008800 endif
8801 q!
8802
8803 elseif type(a:fname) == 3
8804 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008805" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008806 let curdir= getcwd()
8807 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008808 if s:NetrwLcd(fromdir)
8809" call Dret("s:NetrwUpload : lcd failure")
8810 return
8811 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008812 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008813 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008814 if exists("g:netrw_port") && g:netrw_port != ""
8815 let useport= " ".g:netrw_scpport." ".g:netrw_port
8816 else
8817 let useport= ""
8818 endif
8819 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8820 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008821 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 +02008822 if s:NetrwLcd(curdir)
8823" call Dret("s:NetrwUpload : lcd failure")
8824 return
8825 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008826
8827 elseif a:tgt =~ '^ftp:'
8828 call s:NetrwMethod(a:tgt)
8829
8830 if b:netrw_method == 2
8831 " handle uploading a list of files via ftp+.netrc
8832 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008833 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008834" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008835
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008836 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008837" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008838
8839 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008840 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008841" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008842 endif
8843
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008844 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008845" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008846
Bram Moolenaaradc21822011-04-01 18:03:16 +02008847 if tgtdir == ""
8848 let tgtdir= '/'
8849 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008850 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008851" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008852
8853 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008854 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8855" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856 endfor
8857
8858 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008859 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 +00008860 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008861" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8862 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008863 endif
8864 " 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 +01008865 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008866 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008867 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8868 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8869 else
8870 bw!|q
8871 endif
8872
8873 elseif b:netrw_method == 3
8874 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8875 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008876 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008877 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008878 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008879
8880 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008881 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008882" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008883 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008884 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008885" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008886 endif
8887
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008888 if exists("g:netrw_uid") && g:netrw_uid != ""
8889 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008890 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008891" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008892 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008893 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008894 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008895" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008896 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008897 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008898" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008899 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008900 endif
8901
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008902 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008903" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008904
8905 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008906 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008907" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008908 endif
8909
8910 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008911 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008912" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008913 endif
8914
8915 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008916 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008917" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008918 endfor
8919
8920 " perform ftp:
8921 " -i : turns off interactive prompting from ftp
8922 " -n unix : DON'T use <.netrc>, even though it exists
8923 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008924 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008925 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008926 " 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 +01008927 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008928 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008929 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8930 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008931 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008932 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8933 let &debug = debugkeep
8934 let mod = 1
8935 else
8936 bw!|q
8937 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008938 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008939" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008940 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008941 endif
8942 else
8943 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8944 endif
8945 endif
8946
8947" call Dret("s:NetrwUpload")
8948endfun
8949
8950" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008951" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008952fun! s:NetrwPreview(path) range
8953" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008954" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8955" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008956 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008957 NetrwKeepj call s:NetrwOptionsSave("s:")
8958 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8959 NetrwKeepj call s:NetrwOptionsSafe(1)
8960 else
8961 NetrwKeepj call s:NetrwOptionsSafe(0)
8962 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008963 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008964" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008965 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008966" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8967 if g:netrw_preview
8968 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008969 let pvhkeep = &pvh
8970 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8971 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008972" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8973 else
8974 " horizontal split
8975 let pvhkeep = &pvh
8976 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8977 let &pvh = winheight(0) - winsz
8978" 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 +02008979 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008980 " g:netrw_preview g:netrw_alto
8981 " 1 : vert 1: top -- preview window is vertically split off and on the left
8982 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8983 " 0 : 1: top -- preview window is horizontally split off and on the top
8984 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8985 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008986 " 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 +02008987 " the BufEnter event set up in netrwPlugin.vim
8988" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8989 let eikeep = &ei
8990 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008991 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008992 let &ei= eikeep
8993" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008994 if exists("pvhkeep")
8995 let &pvh= pvhkeep
8996 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008997 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008998 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008999 endif
9000 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009001 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 +00009002 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009003 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009004 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009005" call Dret("NetrwPreview")
9006endfun
9007
9008" ---------------------------------------------------------------------
9009" s:NetrwRefresh: {{{2
9010fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009011" 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 +00009012 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009013 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009014" call Decho("setl ma noro",'~'.expand("<slnum>"))
9015" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009016 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009017 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9018 if !exists("w:netrw_treetop")
9019 if exists("b:netrw_curdir")
9020 let w:netrw_treetop= b:netrw_curdir
9021 else
9022 let w:netrw_treetop= getcwd()
9023 endif
9024 endif
9025 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9026 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009027
9028 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009029 let screenposn = winsaveview()
9030" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009031
9032" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9033" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9034 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009035 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009036 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009037 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009038 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009039 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009040
9041 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009042" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9043 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009044
9045 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009046 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9047 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9048" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9049 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9050 else
9051" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9052 2match none
9053 endif
9054 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009055
Bram Moolenaar97d62492012-11-15 21:28:22 +01009056" restore
9057 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009058" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009059endfun
9060
9061" ---------------------------------------------------------------------
9062" s:NetrwRefreshDir: refreshes a directory by name {{{2
9063" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009064" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009065fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009066" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009067 if g:netrw_fastbrowse == 0
9068 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009069" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009070 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009071" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009072
9073 if tgtwin > 0
9074 " tgtwin is being displayed, so refresh it
9075 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009076" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009077 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009078 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079 exe curwin."wincmd w"
9080
9081 elseif bufnr(a:dirname) > 0
9082 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009083" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9084 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009085 endif
9086
9087 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009088" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009089 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009090 endif
9091" call Dret("s:NetrwRefreshDir")
9092endfun
9093
9094" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009095" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9096" window number to do its editing in.
9097" Supports [count]C where the count, if present, is used to specify
9098" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009099fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009100" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009101 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009102" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009103 if a:1 == "" " :NetrwC win#
9104 let g:netrw_chgwin= winnr()
9105 else " :NetrwC
9106 let g:netrw_chgwin= a:1
9107 endif
9108 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009109 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009110 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009111 let g:netrw_chgwin= winnr()
9112 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009113 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009114" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009115endfun
9116
9117" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009118" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9119" What this function does is to compute a priority for the patterns
9120" in the g:netrw_sort_sequence. It applies a substitute to any
9121" "files" that satisfy each pattern, putting the priority / in
9122" front. An "*" pattern handles the default priority.
9123fun! s:NetrwSetSort()
9124" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009125 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009126 if w:netrw_liststyle == s:LONGLIST
9127 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9128 else
9129 let seqlist = g:netrw_sort_sequence
9130 endif
9131 " sanity check -- insure that * appears somewhere
9132 if seqlist == ""
9133 let seqlist= '*'
9134 elseif seqlist !~ '\*'
9135 let seqlist= seqlist.',*'
9136 endif
9137 let priority = 1
9138 while seqlist != ""
9139 if seqlist =~ ','
9140 let seq = substitute(seqlist,',.*$','','e')
9141 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9142 else
9143 let seq = seqlist
9144 let seqlist = ""
9145 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009146 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009147 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009148 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009149 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009150 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009151 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009152 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009153" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009154
9155 " sanity check
9156 if w:netrw_bannercnt > line("$")
9157 " apparently no files were left after a Hiding pattern was used
9158" call Dret("SetSort : no files left after hiding")
9159 return
9160 endif
9161 if seq == '*'
9162 let starpriority= spriority
9163 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009164 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009165 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009166 " sometimes multiple sorting patterns will match the same file or directory.
9167 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009168 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9169 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009170 endif
9171 let priority = priority + 1
9172 endwhile
9173 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009174 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9175 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009176 endif
9177
9178 " Following line associated with priority -- items that satisfy a priority
9179 " pattern get prefixed by ###/ which permits easy sorting by priority.
9180 " Sometimes files can satisfy multiple priority patterns -- only the latest
9181 " priority pattern needs to be retained. So, at this point, these excess
9182 " priority prefixes need to be removed, but not directories that happen to
9183 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009184 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9185 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009186 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009187
9188" call Dret("SetSort")
9189endfun
9190
Bram Moolenaarff034192013-04-24 18:51:19 +02009191" ---------------------------------------------------------------------
9192" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9193" Implements [count]Tb (bookhist<b>)
9194" [count]Th (bookhist<h>)
9195" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009196fun! s:NetrwSetTgt(islocal,bookhist,choice)
9197" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009198
9199 if a:bookhist == 'b'
9200 " supports choosing a bookmark as a target using a qb-generated list
9201 let choice= a:choice - 1
9202 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009203 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009204 else
9205 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9206 endif
9207
9208 elseif a:bookhist == 'h'
9209 " supports choosing a history stack entry as a target using a qb-generated list
9210 let choice= (a:choice % g:netrw_dirhistmax) + 1
9211 if exists("g:netrw_dirhist_".choice)
9212 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009213 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009214 else
9215 echomsg "Sorry, history#".a:choice." not available!"
9216 endif
9217 endif
9218
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009219 " refresh the display
9220 if !exists("b:netrw_curdir")
9221 let b:netrw_curdir= getcwd()
9222 endif
9223 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9224
Bram Moolenaarff034192013-04-24 18:51:19 +02009225" call Dret("s:NetrwSetTgt")
9226endfun
9227
Bram Moolenaar446cb832008-06-24 21:56:24 +00009228" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009229" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009230fun! s:NetrwSortStyle(islocal)
9231" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009232 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009233 let svpos= winsaveview()
9234" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009235
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009236 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 +01009237 NetrwKeepj norm! 0
9238 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009239" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9240 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009241
9242" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9243endfun
9244
9245" ---------------------------------------------------------------------
9246" s:NetrwSplit: mode {{{2
9247" =0 : net and o
9248" =1 : net and t
9249" =2 : net and v
9250" =3 : local and o
9251" =4 : local and t
9252" =5 : local and v
9253fun! s:NetrwSplit(mode)
9254" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9255
Bram Moolenaar97d62492012-11-15 21:28:22 +01009256 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009257 call s:SaveWinVars()
9258
9259 if a:mode == 0
9260 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009261 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009262 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009263" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009264 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009265 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009266 NetrwKeepj call s:RestoreWinVars()
9267 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009268 unlet s:didsplit
9269
9270 elseif a:mode == 1
9271 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009272 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009273" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009274 tabnew
9275 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009276 NetrwKeepj call s:RestoreWinVars()
9277 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278 unlet s:didsplit
9279
9280 elseif a:mode == 2
9281 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009282 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(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_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009285 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
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 s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009289 unlet s:didsplit
9290
9291 elseif a:mode == 3
9292 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009293 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009294 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009295" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009296 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009297 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009298 NetrwKeepj call s:RestoreWinVars()
9299 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009300 unlet s:didsplit
9301
9302 elseif a:mode == 4
9303 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009304 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009305 let eikeep = &ei
9306 let netrw_winnr = winnr()
9307 let netrw_line = line(".")
9308 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009309 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009310 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009311 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009312 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9313 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009314 let &ei = eikeep
9315 let netrw_curdir = s:NetrwTreeDir(0)
9316" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009317 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009318 let b:netrw_curdir = netrw_curdir
9319 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009320 NetrwKeepj call s:RestoreWinVars()
9321 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009322 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009323 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009324 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9325 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009326 let &ei= eikeep
9327 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009328 unlet s:didsplit
9329
9330 elseif a:mode == 5
9331 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009332 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009333 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009334" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009335 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009336 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009337 NetrwKeepj call s:RestoreWinVars()
9338 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009339 unlet s:didsplit
9340
9341 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009342 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009343 endif
9344
Bram Moolenaar97d62492012-11-15 21:28:22 +01009345 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009346" call Dret("s:NetrwSplit")
9347endfun
9348
9349" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009350" s:NetrwTgtMenu: {{{2
9351fun! s:NetrwTgtMenu()
9352 if !exists("s:netrw_menucnt")
9353 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009354 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009355" call Dfunc("s:NetrwTgtMenu()")
9356
9357 " the following test assures that gvim is running, has menus available, and has menus enabled.
9358 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9359 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009360" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009361 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9362 endif
9363 if !exists("s:netrw_initbookhist")
9364 call s:NetrwBookHistRead()
9365 endif
9366
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009367 " try to cull duplicate entries
9368 let tgtdict={}
9369
Bram Moolenaarff034192013-04-24 18:51:19 +02009370 " target bookmarked places
9371 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009372" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009373 let cnt= 1
9374 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009375 if has_key(tgtdict,bmd)
9376 let cnt= cnt + 1
9377 continue
9378 endif
9379 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009380 let ebmd= escape(bmd,g:netrw_menu_escape)
9381 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009382" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009383 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 +02009384 let cnt= cnt + 1
9385 endfor
9386 endif
9387
9388 " target directory browsing history
9389 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009390" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009391 let histcnt = 1
9392 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009393 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009394 if exists("g:netrw_dirhist_{histcnt}")
9395 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009396 if has_key(tgtdict,histentry)
9397 let histcnt = histcnt + 1
9398 continue
9399 endif
9400 let tgtdict[histentry] = histcnt
9401 let ehistentry = escape(histentry,g:netrw_menu_escape)
9402" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009403 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 +02009404 endif
9405 let histcnt = histcnt + 1
9406 endwhile
9407 endif
9408 endif
9409" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009410endfun
9411
9412" ---------------------------------------------------------------------
9413" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9414" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009415fun! s:NetrwTreeDir(islocal)
9416" 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 +02009417" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009418" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9419" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9420" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009421" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009422
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009423 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009424 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009425" 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 +01009426 let treedir= s:treedir
9427 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009428 unlet s:prevwinopen
9429" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009430 return treedir
9431 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009432 if exists("s:prevwinopen")
9433 unlet s:prevwinopen
9434 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009435" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009436
Bram Moolenaar8d043172014-01-23 14:24:41 +01009437 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9438 let b:netrw_curdir= getcwd()
9439 endif
9440 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009441" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009442" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009443
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009444 let s:treecurpos= winsaveview()
9445" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009446" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009447
9448 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009449" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9450" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009451" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009452
9453 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009454 let curline= substitute(getline('.'),"\t -->.*$",'','')
9455 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009456" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009457 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009458" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9459 elseif curline =~ '@$'
9460" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009461 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009462" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009463 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009464" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009465 let treedir= ""
9466 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009467" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009468
9469 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009470" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9471" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009472" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009473 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009474" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009475 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009476" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9477 sil! NetrwKeepj %d _
9478" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009479 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009480" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009481" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009482 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009483" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009484
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009485" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009486" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009487" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009488
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009489 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9490" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9491" let newdir = w:netrw_treetop.'/'.potentialdir
9492" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9493" let treedir = s:NetrwTreePath(newdir)
9494" let w:netrw_treetop = newdir
9495" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9496" else
9497" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009498 if a:islocal && curline =~ '@$'
9499 if isdirectory(s:NetrwFile(potentialdir))
9500 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9501 let w:netrw_treetop = treedir
9502 endif
9503 else
9504 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9505 let treedir = s:NetrwTreePath(w:netrw_treetop)
9506 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009507 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009508" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009509
9510 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009511 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009512" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009513" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009514
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009515" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009516 return treedir
9517endfun
9518
9519" ---------------------------------------------------------------------
9520" s:NetrwTreeDisplay: recursive tree display {{{2
9521fun! s:NetrwTreeDisplay(dir,depth)
9522" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9523
9524 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009525 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009526
9527 " install ../ and shortdir
9528 if a:depth == ""
9529 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009530" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009531 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009532 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009533 if a:dir == w:netrw_treetop
9534 let shortdir= a:dir
9535 else
9536 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9537 endif
9538 call setline(line("$")+1,a:depth.shortdir)
9539 else
9540 let shortdir= substitute(a:dir,'^.*/','','e')
9541 call setline(line("$")+1,a:depth.shortdir.'/')
9542 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009543" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009544 " append a / to dir if its missing one
9545 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009546
9547 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009548 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009549" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009550
Bram Moolenaar85850f32019-07-19 22:05:51 +02009551 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9552 if g:netrw_hide == 1
9553 " hide given patterns
9554 let listhide= split(g:netrw_list_hide,',')
9555" call Decho("listhide=".string(listhide))
9556 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009557 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009558 endfor
9559
9560 elseif g:netrw_hide == 2
9561 " show given patterns (only)
9562 let listhide= split(g:netrw_list_hide,',')
9563" call Decho("listhide=".string(listhide))
9564 let entries=[]
9565 for entry in w:netrw_treedict[dir]
9566 for pat in listhide
9567 if entry =~ pat
9568 call add(entries,entry)
9569 break
9570 endif
9571 endfor
9572 endfor
9573 let w:netrw_treedict[dir]= entries
9574 endif
9575 if depth != ""
9576 " always remove "." and ".." entries when there's depth
9577 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9578 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9579 endif
9580
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009581" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009582 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009583 if dir =~ '/$'
9584 let direntry= substitute(dir.entry,'[@/]$','','e')
9585 else
9586 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9587 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009588" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009589 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009590" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009591 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009592 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009593" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9594 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9595 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9596" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009597 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009598 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009599" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009600 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009601 endif
9602 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009603" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009604
Bram Moolenaar446cb832008-06-24 21:56:24 +00009605" call Dret("NetrwTreeDisplay")
9606endfun
9607
9608" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009609" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9610fun! s:NetrwRefreshTreeDict(dir)
9611" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009612 if !exists("w:netrw_treedict")
9613" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9614 return
9615 endif
9616
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009617 for entry in w:netrw_treedict[a:dir]
9618 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9619" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9620
9621 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9622" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9623 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009624 let liststar = s:NetrwGlob(direntry,'*',1)
9625 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009626 let w:netrw_treedict[direntry] = liststar + listdotstar
9627" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9628
9629 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9630" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9631 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009632 let liststar = s:NetrwGlob(direntry.'/','*',1)
9633 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009634 let w:netrw_treedict[direntry]= liststar + listdotstar
9635" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9636
9637 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9638" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9639 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009640 let liststar = s:NetrwGlob(direntry.'/','*',1)
9641 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009642" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9643
9644 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009645" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009646 endif
9647 endfor
9648" call Dret("s:NetrwRefreshTreeDict")
9649endfun
9650
9651" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009652" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009653" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009654fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009655 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009656" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009657" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9658" 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>"))
9659" 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 +00009660
9661 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009662 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009663" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009664 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009665 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009666" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009667 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 +02009668" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009669 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009670 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009671" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009672 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009673 if exists("w:netrw_treetop")
9674 let s:netrw_treetop= w:netrw_treetop
9675 else
9676 let w:netrw_treetop= getcwd()
9677 let s:netrw_treetop= w:netrw_treetop
9678 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679
Bram Moolenaar446cb832008-06-24 21:56:24 +00009680 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009681 " insure that we have a treedict, albeit empty
9682" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009683 let w:netrw_treedict= {}
9684 endif
9685
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009686 " update the dictionary for the current directory
9687" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009688" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009689 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009690 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009691" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009692 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009693
9694 " if past banner, record word
9695 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9696 let fname= expand("<cword>")
9697 else
9698 let fname= ""
9699 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009700" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9701" 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 +00009702
9703 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009704" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009705 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009706" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009707
9708 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9709 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009710" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009711 1d
9712 endwhile
9713
Bram Moolenaar13600302014-05-22 18:26:40 +02009714 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009715
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009716" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009717 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009718 endif
9719endfun
9720
9721" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009722" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009723" Normally, treetop is w:netrw_treetop, but a
9724" user of the function ( netrw#SetTreetop() )
9725" wipes that out prior to calling this function
9726fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009727" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9728 if line(".") < w:netrw_bannercnt + 2
9729 let treedir= a:treetop
9730 if treedir !~ '/$'
9731 let treedir= treedir.'/'
9732 endif
9733" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9734 return treedir
9735 endif
9736
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009737 let svpos = winsaveview()
9738" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009739 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009740" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009741 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009742" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9743 let curline= getline('.')
9744" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9745 if curline =~ '/$'
9746" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9747 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9748" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9749 elseif curline =~ '@\s\+-->'
9750" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9751 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9752 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9753" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009754 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009755" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009756 let treedir= ""
9757 endif
9758 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009759" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9760" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009761 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9762 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9763 let treedir= dirname.treedir
9764 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009765" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009766 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009767" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009768 if a:treetop =~ '/$'
9769 let treedir= a:treetop.treedir
9770 else
9771 let treedir= a:treetop.'/'.treedir
9772 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009773" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009774 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009775" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009776" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9777 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009778" call Dret("s:NetrwTreePath <".treedir.">")
9779 return treedir
9780endfun
9781
9782" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009783" s:NetrwWideListing: {{{2
9784fun! s:NetrwWideListing()
9785
9786 if w:netrw_liststyle == s:WIDELIST
9787" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9788 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009789 " cpf: characters per filename
9790 " fpl: filenames per line
9791 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009792 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009793 let dict={}
9794 " save the unnamed register and register 0-9 and a
9795 let dict.a=[getreg('a'), getregtype('a')]
9796 for i in range(0, 9)
9797 let dict[i] = [getreg(i), getregtype(i)]
9798 endfor
9799 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009800" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009801 let b:netrw_cpf= 0
9802 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009803 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009804 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9805 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009806 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009807 " restore stored registers
9808 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009809" call Dret("NetrwWideListing")
9810 return
9811 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009812 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009813 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009814" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009815
9816 " determine qty files per line (fpl)
9817 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9818 if w:netrw_fpl <= 0
9819 let w:netrw_fpl= 1
9820 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009821" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009822
9823 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009824 " fpc: files per column of wide listing
9825 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009826 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009827 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9828 let newcolstart = w:netrw_bannercnt + fpc
9829 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009830" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009831 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009832" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009833 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009834 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009835 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009836 while line("$") >= newcolstart
9837 if newcolend > line("$") | let newcolend= line("$") | endif
9838 let newcolqty= newcolend - newcolstart
9839 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009840 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009841 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009842 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009843 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009844 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009845 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009846 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009847 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009848 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009849 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009850" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009851 if @* != keepregstar | sil! let @* = keepregstar | endif
9852 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009853 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009854 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9855 NetrwKeepj call histdel("/",-1)
9856 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9857 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009858" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009859 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009860 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009861" 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 +00009862" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009863 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009864 else
9865 if hasmapto("w","n")
9866 sil! nunmap <buffer> w
9867 endif
9868 if hasmapto("b","n")
9869 sil! nunmap <buffer> b
9870 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009871 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009872endfun
9873
9874" ---------------------------------------------------------------------
9875" s:PerformListing: {{{2
9876fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009877" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9878" 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 +02009879" 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>"))
9880 sil! NetrwKeepj %d _
9881" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009882
Bram Moolenaar15146672011-10-20 22:22:38 +02009883 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009884" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009885 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009886
Bram Moolenaar85850f32019-07-19 22:05:51 +02009887 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009888 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009889" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009890
9891" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009892" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009893" endif " Decho
9894
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009895" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009896 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9897 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009898" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9899 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009900 endif
9901
9902 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009903 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009904
9905 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009906 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009907" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009908 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009909 if exists("g:netrw_pchk")
9910 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9911 " failure detections.
9912 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009913 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009914 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9915 endif
9916 if exists("g:netrw_pchk")
9917 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9918 else
9919 let curdir= b:netrw_curdir
9920 endif
9921 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9922 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9923 else
9924 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009925 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009926 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009927 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009928 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009929" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009930 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009931 let w:netrw_bannercnt= 1
9932 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009933" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9934" 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 +00009935
Bram Moolenaar85850f32019-07-19 22:05:51 +02009936 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009937 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009938 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009939 let sortby= sortby." reversed"
9940 endif
9941
9942 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009943 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009944" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009945 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009946" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009947 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009948 NetrwKeepj put ='\" Sorted by '.sortby
9949 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009950 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9951 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009952" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009953 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009954 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009955 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9956 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009957 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009958" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009959" 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 +00009960 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009961
Bram Moolenaar85850f32019-07-19 22:05:51 +02009962 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009963 if g:netrw_banner
9964 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009965" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009966 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009967 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009968 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009969 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009970 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009971 endif
9972 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009973 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009974" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009975 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009976 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009977 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009978
9979 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009980 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009981" 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 +01009982 if g:netrw_list_hide != "" && g:netrw_hide
9983 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009984 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009985 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009986 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009987 endif
9988 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009989 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009990 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009991
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009992" 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 +01009993 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009994" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009995 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" 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 +01009997 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009998 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009999" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010000" 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 +000010001 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010002
10003 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +010010004 if g:netrw_banner
10005 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010006 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010007" 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 +010010008" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010009" 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 +010010010 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010011
Bram Moolenaar446cb832008-06-24 21:56:24 +000010012 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010013" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010014 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010015 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010016 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010017 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010018 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010019" 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 +010010020" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10021 return
10022 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010023 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010024
10025 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010026 if !exists("w:netrw_bannercnt")
10027 let w:netrw_bannercnt= 0
10028 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010029" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10030" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10031" 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 +010010032
Bram Moolenaar5c736222010-01-06 20:54:52 +010010033 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010034" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010035" 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 +000010036 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010037 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010038 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010039 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010040" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010041
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010042 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010043 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010044" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010045 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010046
Bram Moolenaar5c736222010-01-06 20:54:52 +010010047 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010048" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010049 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010050 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010051 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010052 else
10053 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010054 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010055 endif
10056 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010057
Bram Moolenaar446cb832008-06-24 21:56:24 +000010058 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010059" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010060 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10061 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010062
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010063 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010064 " exten: sort by extension
10065 " The histdel(...,-1) calls remove the last search from the search history
10066" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010067 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10068 NetrwKeepj call histdel("/",-1)
10069 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10070 NetrwKeepj call histdel("/",-1)
10071 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10072 NetrwKeepj call histdel("/",-1)
10073 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10074" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010075 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010076 " normal direction sorting
10077 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10078 else
10079 " reverse direction sorting
10080 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10081 endif
10082 endif
10083 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10084 NetrwKeepj call histdel("/",-1)
10085
Bram Moolenaar446cb832008-06-24 21:56:24 +000010086 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010087 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010088" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010089 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010090" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010091 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010092 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010093" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010094 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010095 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010096" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010097 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10098 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010099 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010100 endif
10101
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010102 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010103" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010104 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010105 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010106 call histdel("/",-1)
10107 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010108 endif
10109 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010110" 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 +000010111
10112 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010113" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10114" 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 +010010115 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010116" 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 +010010117 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010118" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#3)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010119
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010120 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010121 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010122" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010123 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010124 endif
10125
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010126 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010127 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010128" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10129 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010130 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010131" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10132 else
10133" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10134" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10135" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10136" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010137 endif
10138
10139 " record previous current directory
10140 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010141" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010142
10143 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010144" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10145" 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 +010010146 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010147" 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 +020010148 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010149" 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 +000010150
10151 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010152" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010153 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010154" 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 +010010155 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010156" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010157 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10158 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010159" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010160" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010161
Bram Moolenaar8d043172014-01-23 14:24:41 +010010162 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010163" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10164" 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 +010010165" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10166 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010167 unlet s:treecurpos
10168 endif
10169
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010170" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (return)",'~'.expand("<slnum>"))
10171" 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 +000010172" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10173endfun
10174
10175" ---------------------------------------------------------------------
10176" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010177fun! s:SetupNetrwStatusLine(statline)
10178" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10179
10180 if !exists("s:netrw_setup_statline")
10181 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010182" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010183
10184 if !exists("s:netrw_users_stl")
10185 let s:netrw_users_stl= &stl
10186 endif
10187 if !exists("s:netrw_users_ls")
10188 let s:netrw_users_ls= &laststatus
10189 endif
10190
10191 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010192 let dict={}
10193 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010194 redir @a
10195 try
10196 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010197 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010198 if &bg == "dark"
10199 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10200 else
10201 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10202 endif
10203 endtry
10204 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010205 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010206 endif
10207
10208 " set up status line (may use User9 highlighting)
10209 " insure that windows have a statusline
10210 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010211 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010212 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010213" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010214 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010215
10216" call Dret("SetupNetrwStatusLine : stl=".&stl)
10217endfun
10218
Bram Moolenaar85850f32019-07-19 22:05:51 +020010219" =========================================
10220" Remote Directory Browsing Support: {{{1
10221" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010222
10223" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010224" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10225" This function assumes that a long listing will be received. Size, time,
10226" and reverse sorts will be requested of the server but not otherwise
10227" enforced here.
10228fun! s:NetrwRemoteFtpCmd(path,listcmd)
10229" 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 +010010230" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010231 " sanity check: {{{3
10232 if !exists("w:netrw_method")
10233 if exists("b:netrw_method")
10234 let w:netrw_method= b:netrw_method
10235 else
10236 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10237" call Dret("NetrwRemoteFtpCmd")
10238 return
10239 endif
10240 endif
10241
10242 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10243 let ffkeep= &ff
10244 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010245" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010246
10247 " clear off any older non-banner lines " {{{3
10248 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010249" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10250 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010251
10252 ".........................................
10253 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10254 " ftp + <.netrc>: Method #2
10255 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010256 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010257 endif
10258 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010259 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010260" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010261 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010262 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010263" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010264 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010265" 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>"))
10266 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 +010010267 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010268" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10269 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 +010010270 endif
10271
10272 ".........................................
10273 elseif w:netrw_method == 3 " {{{3
10274 " ftp + machine,id,passwd,filename: Method #3
10275 setl ff=unix
10276 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010277 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010278 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010279 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010280 endif
10281
10282 " handle userid and password
10283 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010284" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010285 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10286 call NetUserPass("ftp:".host)
10287 endif
10288 if exists("g:netrw_uid") && g:netrw_uid != ""
10289 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010290 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010291 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010292 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010293 endif
10294 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010295 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010296 endif
10297 endif
10298
10299 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010300 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010301 endif
10302 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010303 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010304" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010305 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010306 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010307
10308 " perform ftp:
10309 " -i : turns off interactive prompting from ftp
10310 " -n unix : DON'T use <.netrc>, even though it exists
10311 " -n win32: quit being obnoxious about password
10312 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010313" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010314 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010315" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010316" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10317" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010318 endif
10319
10320 ".........................................
10321 elseif w:netrw_method == 9 " {{{3
10322 " sftp username@machine: Method #9
10323 " s:netrw_sftp_cmd
10324 setl ff=unix
10325
10326 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010327 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010328" call Dret("NetrwRemoteFtpCmd")
10329 return
10330
10331 ".........................................
10332 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010333 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010334 endif
10335
10336 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010337 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010338 sil! NetrwKeepj %s/\r$//e
10339 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010340 endif
10341 if a:listcmd == "dir"
10342 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010343 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10344 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10345 NetrwKeepj call histdel("/",-1)
10346 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010347 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 +010010348 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10349 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010350 endif
10351 endif
10352
10353 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10354 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010355 exe 'NetrwKeepj '.w:netrw_bannercnt
10356 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010357 endif
10358 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010359 exe 'NetrwKeepj '.w:netrw_bannercnt
10360 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010361 endif
10362
10363 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010364 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010365" call Dret("NetrwRemoteFtpCmd")
10366endfun
10367
10368" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010369" s:NetrwRemoteListing: {{{2
10370fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010371" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010372
Bram Moolenaara6878372014-03-22 21:02:50 +010010373 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10374 let w:netrw_bannercnt= s:bannercnt
10375 endif
10376 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010377 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010378 endif
10379
Bram Moolenaar446cb832008-06-24 21:56:24 +000010380 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010381
Bram Moolenaar446cb832008-06-24 21:56:24 +000010382 " sanity check:
10383 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010384" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010385 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010386" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010387 if !exists("g:netrw_quiet")
10388 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10389 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010390 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010391" call Dret("s:NetrwRemoteListing -1")
10392 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010393 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010394
Bram Moolenaar8d043172014-01-23 14:24:41 +010010395 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010396" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010398 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010399 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 +000010400 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010401 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 +000010402 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010403 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010404
Bram Moolenaar85850f32019-07-19 22:05:51 +020010405 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010406" call Dret("s:NetrwRemoteListing -1")
10407 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010408 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010409" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010410
Bram Moolenaar446cb832008-06-24 21:56:24 +000010411 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010412" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010413 let w:netrw_method= b:netrw_method
10414 endif
10415
Bram Moolenaar13600302014-05-22 18:26:40 +020010416 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010417 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010418" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010419 let s:method = "ftp"
10420 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010421 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010422 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010423 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010424 let listcmd= g:netrw_ftp_sizelist_cmd
10425 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010426" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010427 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010428" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010429
Bram Moolenaara6878372014-03-22 21:02:50 +010010430 " report on missing file or directory messages
10431 if search('[Nn]o such file or directory\|Failed to change directory')
10432 let mesg= getline(".")
10433 if exists("w:netrw_bannercnt")
10434 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010435 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010436 setl noma
10437 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010438 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010439 call netrw#ErrorMsg(s:WARNING,mesg,96)
10440" call Dret("s:NetrwRemoteListing : -1")
10441 return -1
10442 endif
10443
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010444 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 +000010445 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010446" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010447 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010448
10449 " cleanup
10450 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010451 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10452 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010453 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010454 sil! NetrwKeepj %s/\r$//e
10455 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010456
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010457 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010458 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010459 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010460 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010461" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010462 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010463" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010464 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010465 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010466 exe "sil! NetrwKeepj ".line1
10467 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010468
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010469" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010470 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010471" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010472 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10473 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010474 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010475" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010476 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10477 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10478 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10479 NetrwKeepj call histdel("/",-1)
10480 NetrwKeepj call histdel("/",-1)
10481 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010482 endif
10483 endif
10484
Bram Moolenaar13600302014-05-22 18:26:40 +020010485 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010486 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010487" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010488 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010489" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010490 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010491" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10492 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010493 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010494 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10495 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10496 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10497 NetrwKeepj call histdel("/",-1)
10498 NetrwKeepj call histdel("/",-1)
10499 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010500 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010501 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10502 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010503 endif
10504 else
10505 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010506" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010507 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010508 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010509" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10510 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10511" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010512 endif
10513 endif
10514
10515 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010516 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010517" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010518 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10519 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010520 endif
10521 endif
10522
10523 if w:netrw_liststyle == s:LONGLIST
10524 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010525" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010526
10527 if s:method == "ftp"
10528 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010529 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010530 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010531 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010532 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010533 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010534 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010535 sil! NetrwKeepj 1
10536 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010537 let line2= line(".")
10538 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010539 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010540 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010541 endif
10542 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010543 exe "sil! NetrwKeepj ".line1
10544 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010545 endif
10546
10547 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010548" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010549 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 +000010550 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010551" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010552 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010553 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010554 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10555 NetrwKeepj call histdel("/",-1)
10556 NetrwKeepj call histdel("/",-1)
10557 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010558 endif
10559 endif
10560
10561" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010562" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010563" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010564
10565" call Dret("s:NetrwRemoteListing 0")
10566 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010567endfun
10568
Bram Moolenaar446cb832008-06-24 21:56:24 +000010569" ---------------------------------------------------------------------
10570" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10571fun! s:NetrwRemoteRm(usrhost,path) range
10572" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010573" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010574 let svpos= winsaveview()
10575" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010576
10577 let all= 0
10578 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10579 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010580" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010581 for fname in s:netrwmarkfilelist_{bufnr("%")}
10582 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010583 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010584 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010585 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010586 let all= 1
10587 endif
10588 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010589 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010590
10591 else
10592 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010593" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010594
10595 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010596 let keepsol = &l:sol
10597 setl nosol
10598 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010599
10600 " remove multiple files and directories
10601 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010602 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010603 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010604 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010605 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010606 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010607 let all= 1
10608 endif
10609 let ctr= ctr + 1
10610 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010611 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010612 endif
10613
10614 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010615" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010616 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010617" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10618 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010619
10620" call Dret("s:NetrwRemoteRm")
10621endfun
10622
10623" ---------------------------------------------------------------------
10624" s:NetrwRemoteRmFile: {{{2
10625fun! s:NetrwRemoteRmFile(path,rmfile,all)
10626" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10627
10628 let all= a:all
10629 let ok = ""
10630
10631 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10632 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010633" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010634 if !all
10635 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010636" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010637 call inputsave()
10638 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10639 call inputrestore()
10640 echohl NONE
10641 if ok == ""
10642 let ok="no"
10643 endif
10644 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010645 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010646 let all= 1
10647 endif
10648 endif
10649
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010650 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010651" 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 +000010652 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010653" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010654 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010655 if path =~ '^\a\{3,}://'
10656 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010657 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010658 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010659 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10660 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010661" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010662 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010663" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010664 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010665 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010666 let ok="q"
10667 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010668 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010669" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10670" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10671" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010672 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010673 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010674 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010675 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010676 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010677" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010678 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010679 if v:shell_error != 0
10680 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010681 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 +010010682 else
10683 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10684 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010685 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010686 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010687 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010688" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010689 endif
10690 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010691 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010692" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010693 endif
10694
10695 else
10696 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010697" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010698 if !all
10699 call inputsave()
10700 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10701 call inputrestore()
10702 if ok == ""
10703 let ok="no"
10704 endif
10705 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010706 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010707 let all= 1
10708 endif
10709 endif
10710
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010711 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010712 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010713 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010714 else
10715 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010716 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10717" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010718 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010719" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010720
10721 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010722" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10723 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10724" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010725 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010726" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010727
10728 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010729 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010730 endif
10731 endif
10732 endif
10733
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010734 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010735" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010736 endif
10737 endif
10738
10739" call Dret("s:NetrwRemoteRmFile ".ok)
10740 return ok
10741endfun
10742
10743" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010744" s:NetrwRemoteRename: rename a remote file or directory {{{2
10745fun! s:NetrwRemoteRename(usrhost,path) range
10746" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10747
10748 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010749 let svpos = winsaveview()
10750" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010751 let ctr = a:firstline
10752 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10753
10754 " rename files given by the markfilelist
10755 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10756 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010757" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010758 if exists("subfrom")
10759 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010760" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010761 else
10762 call inputsave()
10763 let newname= input("Moving ".oldname." to : ",oldname)
10764 call inputrestore()
10765 if newname =~ '^s/'
10766 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10767 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10768 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010769" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010770 endif
10771 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010772
Bram Moolenaar446cb832008-06-24 21:56:24 +000010773 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010774 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010775 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010776 let oldname= s:ShellEscape(a:path.oldname)
10777 let newname= s:ShellEscape(a:path.newname)
10778" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010779 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010780 endif
10781
10782 endfor
10783 call s:NetrwUnMarkFile(1)
10784
10785 else
10786
10787 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010788 let keepsol= &l:sol
10789 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010790 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010791 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010792
10793 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010794" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010795
10796 call inputsave()
10797 let newname= input("Moving ".oldname." to : ",oldname)
10798 call inputrestore()
10799
10800 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10801 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10802 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010803 let oldname= s:ShellEscape(a:path.oldname)
10804 let newname= s:ShellEscape(a:path.newname)
10805" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010806 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010807 endif
10808
10809 let ctr= ctr + 1
10810 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010811 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010812 endif
10813
10814 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010815 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010816" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10817 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010818
10819" call Dret("NetrwRemoteRename")
10820endfun
10821
Bram Moolenaar85850f32019-07-19 22:05:51 +020010822" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010823" Local Directory Browsing Support: {{{1
10824" ==========================================
10825
10826" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010827" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010828" Should accept: file://localhost/etc/fstab
10829" file:///etc/fstab
10830" file:///c:/WINDOWS/clock.avi
10831" file:///c|/WINDOWS/clock.avi
10832" file://localhost/c:/WINDOWS/clock.avi
10833" file://localhost/c|/WINDOWS/clock.avi
10834" file://c:/foo.txt
10835" file:///c:/foo.txt
10836" 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 +020010837fun! netrw#FileUrlEdit(fname)
10838" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010839 let fname = a:fname
10840 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010841" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010842 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010843" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010844 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010845 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010846 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010847" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010848 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010849" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010850 endif
10851 endif
10852 let fname2396 = netrw#RFC2396(fname)
10853 let fname2396e= fnameescape(fname2396)
10854 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010855 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010856" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010857 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010858" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010859 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10860 endif
10861 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010862
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010863" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10864" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010865 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010866 exe 'NetrwKeepj keepalt edit '.plainfname
10867 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10868
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010869" 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 +020010870" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010871 exe "sil doau BufReadPost ".fname2396e
10872endfun
10873
10874" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010875" netrw#LocalBrowseCheck: {{{2
10876fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010877 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010878 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10879 "
10880 " unfortunate interaction -- split window debugging can't be used here, must use
10881 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10882 " another call to LocalBrowseCheck() when attempts to write
10883 " to the DBG buffer are made.
10884 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010885 " The &ft == "netrw" test was installed because the BufEnter event
10886 " would hit when re-entering netrw windows, creating unexpected
10887 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010888" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010889" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010890" 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 +010010891 " getting E930: Cannot use :redir inside execute
10892"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010893" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10894" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010895
Bram Moolenaar97d62492012-11-15 21:28:22 +010010896 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010897 if isdirectory(s:NetrwFile(a:dirname))
10898" 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 +010010899
Bram Moolenaar97d62492012-11-15 21:28:22 +010010900 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010901" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10902" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010903 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010904
Bram Moolenaar446cb832008-06-24 21:56:24 +000010905 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010906" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010907 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010908
Bram Moolenaar5c736222010-01-06 20:54:52 +010010909 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010910" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010911 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010912 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010913 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010914" 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 +010010915" call Dret("netrw#LocalBrowseCheck")
10916 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010917 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010918
Bram Moolenaar85850f32019-07-19 22:05:51 +020010919 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010920 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10921 " AND IF the listing style is not a tree listing
10922 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010923" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010924 let ibuf = 1
10925 let buflast = bufnr("$")
10926 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010927 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10928 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010929 endif
10930 let ibuf= ibuf + 1
10931 endwhile
10932 endif
10933 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010934" 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>"))
10935" 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 +000010936 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010937" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010938endfun
10939
10940" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010941" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010942" performed any shell command. The idea is to cause all local-browsing
10943" buffers to be refreshed after a user has executed some shell command,
10944" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010945fun! s:LocalBrowseRefresh()
10946" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010947" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10948" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010949
Bram Moolenaar446cb832008-06-24 21:56:24 +000010950 " determine which buffers currently reside in a tab
10951 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010952" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010953 return
10954 endif
10955 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010956" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010957 return
10958 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010959 if !empty(getcmdwintype())
10960 " cannot move away from cmdline window, see :h E11
10961 return
10962 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010963 if exists("s:netrw_events") && s:netrw_events == 1
10964 " s:LocalFastBrowser gets called (indirectly) from a
10965 let s:netrw_events= 2
10966" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10967 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010968 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010969 let itab = 1
10970 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010971 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010972 while itab <= tabpagenr("$")
10973 let buftablist = buftablist + tabpagebuflist()
10974 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010975 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010976 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010977" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10978" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010979 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10980 " | refresh any netrw window
10981 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010982 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010983 let ibl = 0
10984 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010985" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010986 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10987 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010988 " (ibuf not shown in a current window AND
10989 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010990" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10991 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010992 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010993" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010994 continue
10995 elseif index(tabpagebuflist(),ibuf) != -1
10996 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010997" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010998 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010999 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010011000 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
11001 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
11002 let g:netrw_quickhelp= g:netrw_quickhelp - 1
11003 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011004" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011005 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
11006 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11007 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011008 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011009 endif
11010 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011011" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011012 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011013" call Decho("restore window: win_gotoid(".curwinid.")")
11014 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011015 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011016
Bram Moolenaara6878372014-03-22 21:02:50 +010011017" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011018endfun
11019
11020" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011021" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11022"
11023" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011024" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011025" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11026" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011027" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011028"
11029" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11030" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011031" (re-using a buffer may not be as accurate)
11032"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011033" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011034" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11035" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11036" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11037" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011038fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011039" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11040" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11041" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11042" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011043
11044 " initialize browselist, a list of buffer numbers that the local browser has used
11045 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011046" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011047 let s:netrw_browselist= []
11048 endif
11049
11050 " append current buffer to fastbrowse list
11051 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011052" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011053 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011054" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011055 endif
11056
11057 " enable autocmd events to handle refreshing/removing local browser buffers
11058 " If local browse buffer is currently showing: refresh it
11059 " If local browse buffer is currently hidden : wipe it
11060 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11061 " =1 : medium speed, re-use directory listing for remote only
11062 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011063 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11064 let s:netrw_events= 1
11065 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011066 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011067 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011068" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011069 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011070 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011071" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011072 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011073 endif
11074 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011075
11076 " user must have changed fastbrowse to its fast setting, so remove
11077 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011078 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011079" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011080 unlet s:netrw_events
11081 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011082 au!
11083 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011084 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011085 endif
11086
Bram Moolenaar85850f32019-07-19 22:05:51 +020011087" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011088endfun
11089
11090" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011091" s:LocalListing: does the job of "ls" for local directories {{{2
11092fun! s:LocalListing()
11093" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011094" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11095" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11096" 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 +010011097
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011098" 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
11099" 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
11100" 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 +010011101
11102 " get the list of files contained in the current directory
11103 let dirname = b:netrw_curdir
11104 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011105 let filelist = s:NetrwGlob(dirname,"*",0)
11106 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011107" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011108
Nir Lichtman1e34b952024-05-08 19:19:34 +020011109 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011110" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011111 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11112 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011113" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011114 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011115" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011116 endif
11117
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011118" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011119" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011120" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011121
11122 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11123 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11124 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011125" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11126" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011127 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011128" 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 +010011129
11130 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011131" call Decho(" ",'~'.expand("<slnum>"))
11132" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011133
11134 if getftype(filename) == "link"
11135 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011136" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011137 let pfile= filename."@"
11138
11139 elseif getftype(filename) == "socket"
11140 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011141" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011142 let pfile= filename."="
11143
11144 elseif getftype(filename) == "fifo"
11145 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011146" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011147 let pfile= filename."|"
11148
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011149 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011150 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011151" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011152 let pfile= filename."/"
11153
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011154 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011155 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011156 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11157 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011158" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011159 let pfile= filename."*"
11160 else
11161 " normal file
11162 let pfile= filename
11163 endif
11164 elseif executable(filename)
11165 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011166" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011167 let pfile= filename."*"
11168 else
11169 " normal file
11170 let pfile= filename
11171 endif
11172
11173 else
11174 " normal file
11175 let pfile= filename
11176 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011177" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011178
11179 if pfile =~ '//$'
11180 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011181" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011182 endif
11183 let pfile= strpart(pfile,dirnamelen)
11184 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011185" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11186" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011187
11188 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011189 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11190 let sz = getfsize(filename)
11191 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11192 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011193
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011194 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011195 let sz= s:NetrwHumanReadable(sz)
11196 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011197 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011198 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011199" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011200 endif
11201
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011202 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011203 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011204 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011205" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011206" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011207 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011208 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011209" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011210 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011211 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011212
11213 elseif g:netrw_sort_by =~ "^s"
11214 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011215" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011216" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011217 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011218 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011219" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011220 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011221 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011222
11223 else
11224 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011225" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011226" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011227 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011228 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011229" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011230 endfor
11231
11232 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011233 sil! NetrwKeepj g/^$/d
11234 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011235 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011236" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011237 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11238
11239" call Dret("s:LocalListing")
11240endfun
11241
11242" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011243" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11244fun! s:NetrwLocalExecute(cmd)
11245" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11246 let ykeep= @@
11247 " sanity check
11248 if !executable(a:cmd)
11249 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11250 let @@= ykeep
11251" call Dret("s:NetrwLocalExecute")
11252 return
11253 endif
11254
11255 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011256" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011257 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011258" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011259
11260 " strip any ansi escape sequences off
11261 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11262
11263 " show user the result(s)
11264 echomsg result
11265 let @@= ykeep
11266
11267" call Dret("s:NetrwLocalExecute")
11268endfun
11269
11270" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011271" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011272fun! s:NetrwLocalRename(path) range
11273" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11274
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011275 if !exists("w:netrw_bannercnt")
11276 let w:netrw_bannercnt= b:netrw_bannercnt
11277 endif
11278
Bram Moolenaar97d62492012-11-15 21:28:22 +010011279 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011280 let ykeep = @@
11281 let ctr = a:firstline
11282 let svpos = winsaveview()
11283 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011284" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011285
11286 " rename files given by the markfilelist
11287 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11288 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011289" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011290 if exists("subfrom")
11291 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011292" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011293 else
11294 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011295 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011296 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011297 if newname =~ ''
11298 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11299 let newname = substitute(newname,'^.*','','')
11300 elseif newname =~ ''
11301 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11302 let newname = substitute(newname,'[^/]*','','')
11303 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011304 if newname =~ '^s/'
11305 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11306 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011307" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011308 let newname = substitute(oldname,subfrom,subto,'')
11309 endif
11310 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011311 if !all && filereadable(newname)
11312 call inputsave()
11313 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11314 call inputrestore()
11315 if response == "all"
11316 let all= 1
11317 elseif response != "y" && response != "yes"
11318 " refresh the directory
11319" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11320 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11321" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11322 NetrwKeepj call winrestview(svpos)
11323 let @@= ykeep
11324" call Dret("NetrwLocalRename")
11325 return
11326 endif
11327 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011328 call rename(oldname,newname)
11329 endfor
11330 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011331
Bram Moolenaar97d62492012-11-15 21:28:22 +010011332 else
11333
11334 " attempt to rename files/directories
11335 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011336 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011337
11338 " sanity checks
11339 if line(".") < w:netrw_bannercnt
11340 let ctr= ctr + 1
11341 continue
11342 endif
11343 let curword= s:NetrwGetWord()
11344 if curword == "./" || curword == "../"
11345 let ctr= ctr + 1
11346 continue
11347 endif
11348
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011349 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011350 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011351" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011352
11353 call inputsave()
11354 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11355 call inputrestore()
11356
11357 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011358" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011359
11360 let ctr= ctr + 1
11361 endwhile
11362 endif
11363
11364 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011365" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011366 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011367" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11368 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011369 let @@= ykeep
11370
11371" call Dret("NetrwLocalRename")
11372endfun
11373
11374" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011375" s:NetrwLocalRm: {{{2
11376fun! s:NetrwLocalRm(path) range
11377" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011378" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011379
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011380 if !exists("w:netrw_bannercnt")
11381 let w:netrw_bannercnt= b:netrw_bannercnt
11382 endif
11383
Bram Moolenaar446cb832008-06-24 21:56:24 +000011384 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011385 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011386 let ret = 0
11387 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011388 let svpos = winsaveview()
11389" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011390
11391 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11392 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011393" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011394 for fname in s:netrwmarkfilelist_{bufnr("%")}
11395 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011396 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011397 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011398 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011399 let all= 1
11400 endif
11401 endfor
11402 call s:NetrwUnMarkFile(1)
11403
11404 else
11405 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011406" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011407
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011408 let keepsol= &l:sol
11409 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011410 let ctr = a:firstline
11411 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011412 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011413
11414 " sanity checks
11415 if line(".") < w:netrw_bannercnt
11416 let ctr= ctr + 1
11417 continue
11418 endif
11419 let curword= s:NetrwGetWord()
11420 if curword == "./" || curword == "../"
11421 let ctr= ctr + 1
11422 continue
11423 endif
11424 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011425 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011426 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011427 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011428 let all= 1
11429 endif
11430 let ctr= ctr + 1
11431 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011432 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011433 endif
11434
11435 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011436" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011437 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011438 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011439" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11440 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011441 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011442 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011443
11444" call Dret("s:NetrwLocalRm")
11445endfun
11446
11447" ---------------------------------------------------------------------
11448" s:NetrwLocalRmFile: remove file fname given the path {{{2
11449" Give confirmation prompt unless all==1
11450fun! s:NetrwLocalRmFile(path,fname,all)
11451" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011452
Bram Moolenaar446cb832008-06-24 21:56:24 +000011453 let all= a:all
11454 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011455 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011456 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011457" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011458
11459 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11460 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011461" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011462 if !all
11463 echohl Statement
11464 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011465 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011466 call inputrestore()
11467 echohl NONE
11468 if ok == ""
11469 let ok="no"
11470 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011471" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011472 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011473" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011474 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011475 let all= 1
11476 endif
11477 endif
11478
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011479 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011480 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011481" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011482 endif
11483
11484 else
11485 " attempt to remove directory
11486 if !all
11487 echohl Statement
11488 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011489 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011490 call inputrestore()
11491 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11492 if ok == ""
11493 let ok="no"
11494 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011495 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011496 let all= 1
11497 endif
11498 endif
11499 let rmfile= substitute(rmfile,'[\/]$','','e')
11500
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011501 if all || ok =~# 'y\%[es]' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011502 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011503 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011504 endif
11505 endif
11506 endif
11507
11508" call Dret("s:NetrwLocalRmFile ".ok)
11509 return ok
11510endfun
11511
Bram Moolenaar85850f32019-07-19 22:05:51 +020011512" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011513" Support Functions: {{{1
11514
Bram Moolenaar488c6512005-08-11 20:09:58 +000011515" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011516" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11517" 0: marked file list of current buffer
11518" 1: marked file target
11519fun! netrw#Access(ilist)
11520 if a:ilist == 0
11521 if exists("s:netrwmarkfilelist_".bufnr('%'))
11522 return s:netrwmarkfilelist_{bufnr('%')}
11523 else
11524 return "no-list-buf#".bufnr('%')
11525 endif
11526 elseif a:ilist == 1
11527 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011528 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011529endfun
11530
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011531" ---------------------------------------------------------------------
11532" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11533fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011534 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011535endfun
11536
Bram Moolenaara6878372014-03-22 21:02:50 +010011537" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011538" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11539" I expect this function to be used in
11540" :PChkAssert netrw#Expose("netrwmarkfilelist")
11541" for example.
11542fun! netrw#Expose(varname)
11543" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011544 if exists("s:".a:varname)
11545 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011546" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011547 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011548" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011549 if type(retval) == 3
11550 let retval = copy(retval)
11551 let i = 0
11552 while i < len(retval)
11553 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11554 let i = i + 1
11555 endwhile
11556 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011557" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011558 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011559 else
11560" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011561 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011562 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011563" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011564 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011565 endif
11566
11567" call Dret("netrw#Expose ".string(retval))
11568 return retval
11569endfun
11570
11571" ---------------------------------------------------------------------
11572" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11573fun! netrw#Modify(varname,newvalue)
11574" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11575 exe "let s:".a:varname."= ".string(a:newvalue)
11576" call Dret("netrw#Modify")
11577endfun
11578
11579" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011580" netrw#RFC2396: converts %xx into characters {{{2
11581fun! netrw#RFC2396(fname)
11582" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011583 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011584" call Dret("netrw#RFC2396 ".fname)
11585 return fname
11586endfun
11587
11588" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011589" netrw#UserMaps: supports user-specified maps {{{2
11590" see :help function()
11591"
11592" g:Netrw_UserMaps is a List with members such as:
11593" [[keymap sequence, function reference],...]
11594"
11595" The referenced function may return a string,
11596" refresh : refresh the display
11597" -other- : this string will be executed
11598" or it may return a List of strings.
11599"
11600" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011601" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011602" Related functions:
11603" netrw#Expose(varname) -- see s:varname variables
11604" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11605" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11606fun! netrw#UserMaps(islocal)
11607" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11608" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11609
11610 " set up usermaplist
11611 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11612" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11613 for umap in g:Netrw_UserMaps
11614" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11615" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11616 " if umap[0] is a string and umap[1] is a string holding a function name
11617 if type(umap[0]) == 1 && type(umap[1]) == 1
11618" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11619 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11620 else
11621 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11622 endif
11623 endfor
11624 endif
11625" call Dret("netrw#UserMaps")
11626endfun
11627
11628" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011629" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11630fun! netrw#WinPath(path)
11631" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011632 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011633 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011634 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011635 " remove trailing slash (Win95)
11636 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11637 " remove escaped spaces
11638 let path = substitute(path, '\ ', ' ', 'g')
11639 " convert slashes to backslashes
11640 let path = substitute(path, '/', '\', 'g')
11641 else
11642 let path= a:path
11643 endif
11644" call Dret("netrw#WinPath <".path.">")
11645 return path
11646endfun
11647
11648" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011649" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11650" cb : bl2mf=0 add marked files to buffer list
11651" cB : bl2mf=1 use bufferlist to mark files
11652" (mnemonic: cb = copy (marked files) to buffer list)
11653fun! s:NetrwBadd(islocal,bl2mf)
11654" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11655 if a:bl2mf
11656 " cB: add buffer list to marked files
11657 redir => bufl
11658 ls
11659 redir END
11660 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11661 for fname in bufl
11662 call s:NetrwMarkFile(a:islocal,fname)
11663 endfor
11664 else
11665 " cb: add marked files to buffer list
11666 for fname in s:netrwmarkfilelist_{bufnr("%")}
11667" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11668 exe "badd ".fnameescape(fname)
11669 endfor
11670 let curbufnr = bufnr("%")
11671 let curdir = s:NetrwGetCurdir(a:islocal)
11672 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11673 endif
11674" call Dret("s:NetrwBadd")
11675endfun
11676
11677" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011678" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11679fun! s:ComposePath(base,subdir)
11680" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11681
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011682 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011683" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011684 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011685 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011686 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011687 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011688 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011689 endif
11690
Bram Moolenaar85850f32019-07-19 22:05:51 +020011691 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011692 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011693" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011694 let ret= a:subdir
11695
Nir Lichtman1e34b952024-05-08 19:19:34 +020011696 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011697" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011698 if a:base =~ '[/\\]$'
11699 let ret= a:base.a:subdir
11700 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011701 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011702 endif
11703
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011704 elseif a:base =~ '^\a\{3,}://'
11705" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011706 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11707 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11708 if a:subdir == '../'
11709 if curpath =~ '[^/]/[^/]\+/$'
11710 let curpath= substitute(curpath,'[^/]\+/$','','')
11711 else
11712 let curpath=""
11713 endif
11714 let ret= urlbase.curpath
11715 else
11716 let ret= urlbase.curpath.a:subdir
11717 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011718" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11719" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11720" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011721
11722 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011723" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011724 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11725 if a:base =~ '^//'
11726 " keeping initial '//' for the benefit of network share listing support
11727 let ret= '/'.ret
11728 endif
11729 let ret= simplify(ret)
11730 endif
11731
11732" call Dret("s:ComposePath ".ret)
11733 return ret
11734endfun
11735
11736" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011737" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11738" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11739fun! s:DeleteBookmark(fname)
11740" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11741 call s:MergeBookmarks()
11742
11743 if exists("g:netrw_bookmarklist")
11744 let indx= index(g:netrw_bookmarklist,a:fname)
11745 if indx == -1
11746 let indx= 0
11747 while indx < len(g:netrw_bookmarklist)
11748 if g:netrw_bookmarklist[indx] =~ a:fname
11749 call remove(g:netrw_bookmarklist,indx)
11750 let indx= indx - 1
11751 endif
11752 let indx= indx + 1
11753 endwhile
11754 else
11755 " remove exact match
11756 call remove(g:netrw_bookmarklist,indx)
11757 endif
11758 endif
11759
11760" call Dret("s:DeleteBookmark")
11761endfun
11762
11763" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011764" s:FileReadable: o/s independent filereadable {{{2
11765fun! s:FileReadable(fname)
11766" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11767
11768 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011769 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011770 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011771 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011772 endif
11773
11774" call Dret("s:FileReadable ".ret)
11775 return ret
11776endfun
11777
11778" ---------------------------------------------------------------------
11779" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11780" Places correct suffix on end of temporary filename,
11781" using the suffix provided with fname
11782fun! s:GetTempfile(fname)
11783" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11784
11785 if !exists("b:netrw_tmpfile")
11786 " get a brand new temporary filename
11787 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011788" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011789
Bram Moolenaarc236c162008-07-13 17:41:49 +000011790 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011791" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011792
Bram Moolenaar9964e462007-05-05 17:54:07 +000011793 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011794 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11795" 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 +010011796 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011797" call Dret("s:GetTempfile getcwd<".getcwd().">")
11798 return ""
11799 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011800
Bram Moolenaar9964e462007-05-05 17:54:07 +000011801 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011802 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011803" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011804
Bram Moolenaar9964e462007-05-05 17:54:07 +000011805 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011806 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011807 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011808 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011809 if !exists("+shellslash") || !&ssl
11810 let tmpfile = substitute(tmpfile,'/','\','g')
11811 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011812 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011813 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011814 endif
11815 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011816" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011817 else
11818 " re-use temporary filename
11819 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011820" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011821 endif
11822
11823 " use fname's suffix for the temporary file
11824 if a:fname != ""
11825 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011826" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011827 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011828 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011829 elseif a:fname =~ '.txz$'
11830 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011831 else
11832 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11833 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011834" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011835 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011836" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011837 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011838" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011839 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11840 endif
11841 endif
11842
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011843" 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 +000011844" call Dret("s:GetTempfile <".tmpfile.">")
11845 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011846endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011847
11848" ---------------------------------------------------------------------
11849" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011850" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011851fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011852" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011853 if s:user == ""
11854 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11855 else
11856 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11857 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011858 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011859 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011860 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011861 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011862 else
11863 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11864 endif
11865" call Dret("s:MakeSshCmd <".sshcmd.">")
11866 return sshcmd
11867endfun
11868
11869" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011870" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11871fun! s:MakeBookmark(fname)
11872" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11873
11874 if !exists("g:netrw_bookmarklist")
11875 let g:netrw_bookmarklist= []
11876 endif
11877
11878 if index(g:netrw_bookmarklist,a:fname) == -1
11879 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011880 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011881 call add(g:netrw_bookmarklist,a:fname.'/')
11882 elseif a:fname !~ '/'
11883 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11884 else
11885 call add(g:netrw_bookmarklist,a:fname)
11886 endif
11887 call sort(g:netrw_bookmarklist)
11888 endif
11889
11890" call Dret("s:MakeBookmark")
11891endfun
11892
11893" ---------------------------------------------------------------------
11894" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11895fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011896" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011897 " get bookmarks from .netrwbook file
11898 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011899 if filereadable(s:NetrwFile(savefile))
11900" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011901 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011902" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011903 NetrwKeepj call delete(savefile)
11904 endif
11905" call Dret("s:MergeBookmarks")
11906endfun
11907
11908" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011909" s:NetrwBMShow: {{{2
11910fun! s:NetrwBMShow()
11911" call Dfunc("s:NetrwBMShow()")
11912 redir => bmshowraw
11913 menu
11914 redir END
11915 let bmshowlist = split(bmshowraw,'\n')
11916 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011917 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011918 if bmshowfuncs != []
11919 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011920 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011921 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011922 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011923 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011924 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011925" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11926endfun
11927
11928" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011929" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011930fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011931 if !exists("w:netrw_liststyle")
11932 let w:netrw_liststyle= g:netrw_liststyle
11933 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011934" 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 +020011935
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011936" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11937
Bram Moolenaaradc21822011-04-01 18:03:16 +020011938 if &ft != "netrw"
11939 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11940 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011941" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011942
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011943 elseif g:netrw_cursor == 8
11944 if w:netrw_liststyle == s:WIDELIST
11945 setl cursorline
11946 setl cursorcolumn
11947 else
11948 setl cursorline
11949 endif
11950 elseif g:netrw_cursor == 7
11951 setl cursorline
11952 elseif g:netrw_cursor == 6
11953 if w:netrw_liststyle == s:WIDELIST
11954 setl cursorline
11955 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011956 elseif g:netrw_cursor == 4
11957 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011958" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011959 setl cursorline
11960 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011961
11962 elseif g:netrw_cursor == 3
11963 " thin-long-tree: cursorline, user's cursorcolumn
11964 " wide : cursorline, cursorcolumn
11965 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011966" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011967 setl cursorline
11968 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011969 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011970" 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 +020011971 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011972 endif
11973
11974 elseif g:netrw_cursor == 2
11975 " thin-long-tree: cursorline, user's cursorcolumn
11976 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011977" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011978 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011979
11980 elseif g:netrw_cursor == 1
11981 " thin-long-tree: user's cursorline, user's cursorcolumn
11982 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011983 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011984" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011985 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011986 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011987" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011988 endif
11989
11990 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011991 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011992" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011993 let &l:cursorline = s:netrw_usercul
11994 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011995 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011996
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011997" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011998" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011999endfun
12000
12001" ---------------------------------------------------------------------
12002" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
12003fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012004" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012005 if exists("s:netrw_usercul")
12006 let &l:cursorline = s:netrw_usercul
12007 endif
12008 if exists("s:netrw_usercuc")
12009 let &l:cursorcolumn = s:netrw_usercuc
12010 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012011" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012012" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12013endfun
12014
Christian Brabandt62f7b552024-06-23 20:23:40 +020012015" s:RestoreRegister: restores all registers given in the dict {{{2
12016fun! s:RestoreRegister(dict)
12017 for [key, val] in items(a:dict)
12018 if key == 'unnamed'
12019 let key = ''
12020 endif
12021 call setreg(key, val[0], val[1])
12022 endfor
12023endfun
12024
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012025" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012026" s:NetrwDelete: Deletes a file. {{{2
12027" Uses Steve Hall's idea to insure that Windows paths stay
12028" acceptable. No effect on Unix paths.
12029" Examples of use: let result= s:NetrwDelete(path)
12030fun! s:NetrwDelete(path)
12031" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12032
Bram Moolenaar5c736222010-01-06 20:54:52 +010012033 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012034 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012035 if exists("+shellslash")
12036 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012037 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012038 let result = delete(path)
12039 let &shellslash = sskeep
12040 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012041" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012042 let result= delete(path)
12043 endif
12044 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012045" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012046 let result= delete(path)
12047 endif
12048 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012049 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012050 endif
12051
12052" call Dret("s:NetrwDelete ".result)
12053 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012054endfun
12055
12056" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012057" s:NetrwBufRemover: removes a buffer that: {{{2s
12058" has buffer-id > 1
12059" is unlisted
12060" is unnamed
12061" does not appear in any window
12062fun! s:NetrwBufRemover(bufid)
12063" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12064" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12065" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12066" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12067" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12068
yasuda4dbb2662023-10-04 20:50:35 +020012069 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012070" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012071 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012072 endif
12073
12074" call Dret("s:NetrwBufRemover")
12075endfun
12076
12077" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012078" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012079fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012080" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012081" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012082
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012083 " Clean out the last buffer:
12084 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12085 " If so, delete it.
12086 call s:NetrwBufRemover(bufnr("$"))
12087
Bram Moolenaar446cb832008-06-24 21:56:24 +000012088 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012089" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012090 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12091 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12092 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12093 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12094 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12095 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12096 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12097 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12098 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12099 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12100 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12101 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12102 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12103 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12104 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12105 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12106
Bram Moolenaar85850f32019-07-19 22:05:51 +020012107 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012108" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012109 " when tree listing uses file TreeListing... a new buffer is made.
12110 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012111 " COMBAK: this causes a problem, see P43
12112" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012113 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012114 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012115 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012116" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012117 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012118
Bram Moolenaar446cb832008-06-24 21:56:24 +000012119 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012120" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012121 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12122 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12123 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12124 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12125 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12126 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12127 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12128 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12129 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12130 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12131 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12132 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12133 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12134 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12135 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12136 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12137
Bram Moolenaar5c736222010-01-06 20:54:52 +010012138 if a:0 > 0
12139 let b:netrw_curdir= a:1
12140 if b:netrw_curdir =~ '/$'
12141 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012142 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012143 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012144 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012145 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12146 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012147 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012148 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012149 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012150 endif
12151 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012152 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12153 let &l:bexpr = "netrw#BalloonHelp()"
12154 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012155
Bram Moolenaar8d043172014-01-23 14:24:41 +010012156" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012157endfun
12158
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012159" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012160" s:NetrwExe: executes a string using "!" {{{2
12161fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012162" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012163 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012164" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012165 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12166 set shell& shellcmdflag& shellxquote& shellxescape&
12167 set shellquote& shellpipe& shellredir& shellslash&
12168 exe a:cmd
12169 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12170 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012171" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012172 exe a:cmd
12173 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012174 if v:shell_error
12175 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12176 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012177" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012178endfun
12179
12180" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012181" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12182fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012183 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012184" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012185 let curbuf = bufnr("%")
12186 let curwin = winnr()
12187 let iwin = 1
12188 while iwin <= winnr("$")
12189 exe iwin."wincmd w"
12190 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12191 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12192 let winvars= w:
12193 break
12194 endif
12195 let iwin= iwin + 1
12196 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012197 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012198 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012199" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012200 for k in keys(winvars)
12201 let w:{k}= winvars[k]
12202 endfor
12203 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012204" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012205 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012206endfun
12207
Bram Moolenaara6878372014-03-22 21:02:50 +010012208" ---------------------------------------------------------------------
12209" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012210" Returns: 0=success
12211" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012212fun! s:NetrwLcd(newdir)
12213" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012214" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012215
Bram Moolenaar85850f32019-07-19 22:05:51 +020012216 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012217 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012218 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012219 catch /^Vim\%((\a\+)\)\=:E344/
12220 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12221 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012222 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012223 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12224 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012225 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012226 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12227 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012228 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012229 endif
12230 endif
12231 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012232 let err472= 1
12233 endtry
12234
12235 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012236 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12237 if exists("w:netrw_prvdir")
12238 let a:newdir= w:netrw_prvdir
12239 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012240 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012241" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012242 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012243" 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 +010012244 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012245 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012246" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12247 return -1
12248 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012249
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012250" call Decho("getcwd <".getcwd().">")
12251" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012252" call Dret("s:NetrwLcd 0")
12253 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012254endfun
12255
Bram Moolenaar9964e462007-05-05 17:54:07 +000012256" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012257" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12258" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12259fun! s:NetrwSaveWordPosn()
12260" call Dfunc("NetrwSaveWordPosn()")
12261 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12262" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12263endfun
12264
12265" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012266" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12267" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12268fun! s:NetrwHumanReadable(sz)
12269" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12270
12271 if g:netrw_sizestyle == 'h'
12272 if a:sz >= 1000000000
12273 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12274 elseif a:sz >= 10000000
12275 let sz = printf("%d",a:sz/1000000)."m"
12276 elseif a:sz >= 1000000
12277 let sz = printf("%.1f",a:sz/1000000.0)."m"
12278 elseif a:sz >= 10000
12279 let sz = printf("%d",a:sz/1000)."k"
12280 elseif a:sz >= 1000
12281 let sz = printf("%.1f",a:sz/1000.0)."k"
12282 else
12283 let sz= a:sz
12284 endif
12285
12286 elseif g:netrw_sizestyle == 'H'
12287 if a:sz >= 1073741824
12288 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12289 elseif a:sz >= 10485760
12290 let sz = printf("%d",a:sz/1048576)."M"
12291 elseif a:sz >= 1048576
12292 let sz = printf("%.1f",a:sz/1048576.0)."M"
12293 elseif a:sz >= 10240
12294 let sz = printf("%d",a:sz/1024)."K"
12295 elseif a:sz >= 1024
12296 let sz = printf("%.1f",a:sz/1024.0)."K"
12297 else
12298 let sz= a:sz
12299 endif
12300
12301 else
12302 let sz= a:sz
12303 endif
12304
12305" call Dret("s:NetrwHumanReadable ".sz)
12306 return sz
12307endfun
12308
12309" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012310" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12311" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12312fun! s:NetrwRestoreWordPosn()
12313" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012314 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012315" call Dret("NetrwRestoreWordPosn")
12316endfun
12317
12318" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012319" s:RestoreBufVars: {{{2
12320fun! s:RestoreBufVars()
12321" call Dfunc("s:RestoreBufVars()")
12322
12323 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12324 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12325 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12326 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12327 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12328 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12329
12330" call Dret("s:RestoreBufVars")
12331endfun
12332
12333" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012334" s:RemotePathAnalysis: {{{2
12335fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012336" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012337
Bram Moolenaara6878372014-03-22 21:02:50 +010012338 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012339 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012340 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012341 let s:user = substitute(a:dirname,dirpat,'\3','')
12342 let s:machine = substitute(a:dirname,dirpat,'\4','')
12343 let s:port = substitute(a:dirname,dirpat,'\5','')
12344 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012345 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012346 if s:machine =~ '@'
12347 let dirpat = '^\(.*\)@\(.\{-}\)$'
12348 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12349 let s:machine = substitute(s:machine,dirpat,'\2','')
12350 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012351
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012352" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12353" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12354" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12355" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12356" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12357" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012358
12359" call Dret("s:RemotePathAnalysis")
12360endfun
12361
12362" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012363" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12364" Returns status
12365" Runs system() on
12366" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012367" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012368fun! s:RemoteSystem(cmd)
12369" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12370 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012371 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 +000012372 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012373 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012374 else
12375 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12376 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12377 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012378 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012379 else
12380 let cmd= cmd.' '
12381 endif
12382 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012383" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012384 let ret= system(cmd)
12385 endif
12386" call Dret("s:RemoteSystem ".ret)
12387 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012388endfun
12389
12390" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012391" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012392fun! s:RestoreWinVars()
12393" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012394 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012395 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12396 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12397 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12398 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12399 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12400 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12401 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12402 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12403 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12404 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12405 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12406 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012407 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12408 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012409 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12410 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12411 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12412" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012413endfun
12414
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012415" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012416" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12417"
12418" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12419" is true) and a command, :Rexplore, which call this function.
12420"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012421" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012422"
12423" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012424fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012425 if exists("s:netrwdrag")
12426 return
12427 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012428" 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 +010012429" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12430" 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 +010012431
12432 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012433 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012434" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012435 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012436 unlet w:netrw_rexfile
12437" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012438 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012439" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012440" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12441" 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 +020012442 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012443
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012444 " ---------------------------
12445 " :Rex issued while in a file
12446 " ---------------------------
12447
Bram Moolenaara6878372014-03-22 21:02:50 +010012448 " record current file so :Rex can return to it from netrw
12449 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012450" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012451
12452 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012453" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012454 return
12455 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012456" 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 +020012457 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012458 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012459 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012460 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012461 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012462 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012463 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012464 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012465 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012466" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12467 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012468" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12469 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012470 if exists("s:rexposn_".bufnr('%'))
12471 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012472 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012473 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012474" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012475 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012476
Bram Moolenaar85850f32019-07-19 22:05:51 +020012477 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12478 if exists("s:explore_match")
12479 exe "2match netrwMarkFile /".s:explore_match."/"
12480 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012481 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012482
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012483" 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 +010012484" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012485endfun
12486
12487" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012488" s:SaveBufVars: save selected b: variables to s: variables {{{2
12489" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012490fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012491" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012492
12493 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12494 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12495 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12496 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12497 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12498 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12499
12500" call Dret("s:SaveBufVars")
12501endfun
12502
12503" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012504" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12505fun! s:SavePosn(posndict)
12506" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12507
Bram Moolenaar85850f32019-07-19 22:05:51 +020012508 if !exists("a:posndict[bufnr('%')]")
12509 let a:posndict[bufnr("%")]= []
12510 endif
12511" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12512 call add(a:posndict[bufnr("%")],winsaveview())
12513" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012514
12515" call Dret("s:SavePosn posndict")
12516 return a:posndict
12517endfun
12518
12519" ---------------------------------------------------------------------
12520" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12521fun! s:RestorePosn(posndict)
12522" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012523 if exists("a:posndict")
12524 if has_key(a:posndict,bufnr("%"))
12525" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12526 let posnlen= len(a:posndict[bufnr("%")])
12527 if posnlen > 0
12528 let posnlen= posnlen - 1
12529" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12530 call winrestview(a:posndict[bufnr("%")][posnlen])
12531 call remove(a:posndict[bufnr("%")],posnlen)
12532" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12533 endif
12534 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012535 endif
12536" call Dret("s:RestorePosn")
12537endfun
12538
12539" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012540" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012541fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012542" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012543 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12544 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12545 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12546 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12547 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12548 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12549 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12550 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12551 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12552 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12553 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12554 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12555 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12556 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12557 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12558 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12559 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12560 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12561" call Dret("s:SaveWinVars")
12562endfun
12563
12564" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012565" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012566" To allow separate windows to have their own activities, such as
12567" Explore **/pattern, several variables have been made window-oriented.
12568" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012569" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012570" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012571fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012572" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012573 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12574 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12575 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12576 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12577 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12578 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12579 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12580 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12581 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12582 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12583" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012584endfun
12585
12586" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012587" s:SetRexDir: set directory for :Rexplore {{{2
12588fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012589" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012590 let w:netrw_rexdir = a:dirname
12591 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012592 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012593" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12594" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012595" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012596" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012597" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012598endfun
12599
12600" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012601" s:ShowLink: used to modify thin and tree listings to show links {{{2
12602fun! s:ShowLink()
12603" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012604" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12605" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012606 if exists("b:netrw_curdir")
12607 norm! $?\a
12608 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12609 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012610" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12611" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12612" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12613 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012614 let dirlen = strlen(b:netrw_curdir)
12615 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012616" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012617 endif
12618 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012619" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12620" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012621 setl noro ma
12622 call setline(".",modline)
12623 setl ro noma nomod
12624 endif
12625" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12626endfun
12627
12628" ---------------------------------------------------------------------
12629" s:ShowStyle: {{{2
12630fun! s:ShowStyle()
12631 if !exists("w:netrw_liststyle")
12632 let liststyle= g:netrw_liststyle
12633 else
12634 let liststyle= w:netrw_liststyle
12635 endif
12636 if liststyle == s:THINLIST
12637 return s:THINLIST.":thin"
12638 elseif liststyle == s:LONGLIST
12639 return s:LONGLIST.":long"
12640 elseif liststyle == s:WIDELIST
12641 return s:WIDELIST.":wide"
12642 elseif liststyle == s:TREELIST
12643 return s:TREELIST.":tree"
12644 else
12645 return 'n/a'
12646 endif
12647endfun
12648
12649" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012650" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12651" Solution from Nicolai Weibull, vim docs (:help strlen()),
12652" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012653fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012654" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12655
12656 if v:version >= 703 && exists("*strdisplaywidth")
12657 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012658
Bram Moolenaar8d043172014-01-23 14:24:41 +010012659 elseif type(g:Align_xstrlen) == 1
12660 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12661 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012662
Bram Moolenaar8d043172014-01-23 14:24:41 +010012663 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012664 " number of codepoints (Latin a + combining circumflex is two codepoints)
12665 " (comment from TM, solution from NW)
12666 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012667
Bram Moolenaar8d043172014-01-23 14:24:41 +010012668 elseif g:Align_xstrlen == 2
12669 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012670 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12671 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012672 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012673
Bram Moolenaar8d043172014-01-23 14:24:41 +010012674 elseif g:Align_xstrlen == 3
12675 " virtual length (counting, for instance, tabs as anything between 1 and
12676 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012677 " preceded by lam, one otherwise, etc.)
12678 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012679 let modkeep= &l:mod
12680 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012681 call setline(line("."),a:x)
12682 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012683 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012684 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012685 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012686
Bram Moolenaar446cb832008-06-24 21:56:24 +000012687 else
12688 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012689 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012690 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012691" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012692 return ret
12693endfun
12694
12695" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012696" s:ShellEscape: shellescape(), or special windows handling {{{2
12697fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012698 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012699 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12700 endif
12701 let f = a:0 > 0 ? a:1 : 0
12702 return shellescape(a:s, f)
12703endfun
12704
12705" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012706" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012707fun! s:TreeListMove(dir)
12708" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012709 let curline = getline('.')
12710 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12711 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12712 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12713 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12714 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12715 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12716" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12717" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12718" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12719" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12720" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12721 " COMBAK : need to handle when on a directory
12722 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012723 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012724 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012725 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012726 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012727" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012728 elseif a:dir == '[]' && nxtline != ''
12729 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012730" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012731 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12732 if nl != 0
12733 NetrwKeepj norm! k
12734 else
12735 NetrwKeepj norm! G
12736 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012737" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012738 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012739 endif
12740
12741" call Dret("s:TreeListMove")
12742endfun
12743
12744" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012745" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12746" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12747" can't be called except via emenu. But due to locale, that menu line may not be called
12748" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12749fun! s:UpdateBuffersMenu()
12750" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012751 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012752 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012753 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012754 catch /^Vim\%((\a\+)\)\=:E/
12755 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012756 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012757 endtry
12758 endif
12759" call Dret("s:UpdateBuffersMenu")
12760endfun
12761
12762" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012763" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012764" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012765fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012766" call Dfunc("s:UseBufWinVars()")
12767 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012768 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12769 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12770 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12771 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12772 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12773 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12774 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12775 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12776 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 +000012777" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012778endfun
12779
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012780" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012781" s:UserMaps: supports user-defined UserMaps {{{2
12782" * calls a user-supplied funcref(islocal,curdir)
12783" * interprets result
12784" See netrw#UserMaps()
12785fun! s:UserMaps(islocal,funcname)
12786" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12787
12788 if !exists("b:netrw_curdir")
12789 let b:netrw_curdir= getcwd()
12790 endif
12791 let Funcref = function(a:funcname)
12792 let result = Funcref(a:islocal)
12793
12794 if type(result) == 1
12795 " if result from user's funcref is a string...
12796" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12797 if result == "refresh"
12798" call Decho("refreshing display",'~'.expand("<slnum>"))
12799 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12800 elseif result != ""
12801" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12802 exe result
12803 endif
12804
12805 elseif type(result) == 3
12806 " if result from user's funcref is a List...
12807" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12808 for action in result
12809 if action == "refresh"
12810" call Decho("refreshing display",'~'.expand("<slnum>"))
12811 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12812 elseif action != ""
12813" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12814 exe action
12815 endif
12816 endfor
12817 endif
12818
12819" call Dret("s:UserMaps")
12820endfun
12821
Bram Moolenaar85850f32019-07-19 22:05:51 +020012822" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012823" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012824" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012825let &cpo= s:keepcpo
12826unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012827
Bram Moolenaar85850f32019-07-19 22:05:51 +020012828" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012829" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012830" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012831" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012832" doing autoload/netrw.vim version v172g ~57
12833" varname<g:netrw_dirhistcnt> value=0 ~1
12834" varname<s:THINLIST> value=0 ~1
12835" varname<s:LONGLIST> value=1 ~1
12836" varname<s:WIDELIST> value=2 ~1
12837" varname<s:TREELIST> value=3 ~1
12838" varname<s:MAXLIST> value=4 ~1
12839" varname<g:netrw_use_errorwindow> value=2 ~1
12840" varname<g:netrw_http_xcmd> value=-q -O ~1
12841" varname<g:netrw_http_put_cmd> value=curl -T ~1
12842" varname<g:netrw_keepj> value=keepj ~1
12843" varname<g:netrw_rcp_cmd> value=rcp ~1
12844" varname<g:netrw_rsync_cmd> value=rsync ~1
12845" varname<g:netrw_rsync_sep> value=/ ~1
12846" varname<g:netrw_scp_cmd> value=scp -q ~1
12847" varname<g:netrw_sftp_cmd> value=sftp ~1
12848" varname<g:netrw_ssh_cmd> value=ssh ~1
12849" varname<g:netrw_alto> value=0 ~1
12850" varname<g:netrw_altv> value=1 ~1
12851" varname<g:netrw_banner> value=1 ~1
12852" varname<g:netrw_browse_split> value=0 ~1
12853" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12854" varname<g:netrw_chgwin> value=-1 ~1
12855" varname<g:netrw_clipboard> value=1 ~1
12856" varname<g:netrw_compress> value=gzip ~1
12857" varname<g:netrw_ctags> value=ctags ~1
12858" varname<g:netrw_cursor> value=2 ~1
12859" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12860" varname<g:netrw_cygdrive> value=/cygdrive ~1
12861" varname<s:didstarstar> value=0 ~1
12862" varname<g:netrw_dirhistcnt> value=0 ~1
12863" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12864" varname<g:netrw_dirhistmax> value=10 ~1
12865" varname<g:netrw_errorlvl> value=0 ~1
12866" varname<g:netrw_fastbrowse> value=1 ~1
12867" 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
12868" varname<g:netrw_ftpmode> value=binary ~1
12869" varname<g:netrw_hide> value=1 ~1
12870" varname<g:netrw_keepdir> value=1 ~1
12871" varname<g:netrw_list_hide> value= ~1
12872" varname<g:netrw_localmkdir> value=mkdir ~1
12873" varname<g:netrw_remote_mkdir> value=mkdir ~1
12874" varname<g:netrw_liststyle> value=0 ~1
12875" varname<g:netrw_markfileesc> value=*./[\~ ~1
12876" varname<g:netrw_maxfilenamelen> value=32 ~1
12877" varname<g:netrw_menu> value=1 ~1
12878" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12879" varname<g:netrw_mousemaps> value=1 ~1
12880" varname<g:netrw_retmap> value=0 ~1
12881" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12882" varname<g:netrw_preview> value=0 ~1