blob: 4c95d2c715a8b12ad094f3420a24345048866db9 [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 Brabandtf9ca1392024-02-19 20:37:11 +010015" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000016" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010017" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000018" Permission is hereby granted to use and distribute this code,
19" with or without modifications, provided that this copyright
20" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000021" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000022" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000023" expressed or implied. By using this plugin, you agree that
24" in no event will the copyright holder be liable for any damages
25" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010026"
27" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
28" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
29"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020030"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000031"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000032" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000033" (James 1:22 RSV)
34" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000035" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000036if &cp || exists("g:loaded_netrw")
37 finish
38endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020039
40" Check that vim has patches that netrw requires.
41" Patches needed for v7.4: 1557, and 213.
42" (netrw will benefit from vim's having patch#656, too)
43let s:needspatches=[1557,213]
44if exists("s:needspatches")
45 for ptch in s:needspatches
46 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
47 if !exists("s:needpatch{ptch}")
48 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
49 endif
50 let s:needpatch{ptch}= 1
51 finish
52 endif
53 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020054endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020055
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010056let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000057if !exists("s:NOTE")
58 let s:NOTE = 0
59 let s:WARNING = 1
60 let s:ERROR = 2
61endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000062
Bram Moolenaar1afcace2005-11-25 19:54:28 +000063let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010064setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020065"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010066"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010067"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000068
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000069" ======================
70" Netrw Variables: {{{1
71" ======================
72
Bram Moolenaar071d4272004-06-13 20:20:40 +000073" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020074" netrw#ErrorMsg: {{{2
75" 0=note = s:NOTE
76" 1=warning = s:WARNING
77" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010078" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
79" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
80" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010081" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020082fun! netrw#ErrorMsg(level,msg,errnum)
83" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
84
85 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020086" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020087 return
88 endif
89
90 if a:level == 1
91 let level= "**warning** (netrw) "
92 elseif a:level == 2
93 let level= "**error** (netrw) "
94 else
95 let level= "**note** (netrw) "
96 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010097" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020098
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020099 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
100 " use popup window
101 if type(a:msg) == 3
102 let msg = [level]+a:msg
103 else
104 let msg= level.a:msg
105 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200106 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200107 let s:popuperr_text= ""
108 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200109 " (default) netrw creates a one-line window to show error/warning
110 " messages (reliably displayed)
111
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100112 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200113 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100114" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200115
116 " getting messages out reliably is just plain difficult!
117 " This attempt splits the current window, creating a one line window.
118 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100119" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200120 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100121" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200122 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100123 if type(a:msg) == 3
124 for msg in a:msg
125 NetrwKeepj call setline(line("$")+1,level.msg)
126 endfor
127 else
128 NetrwKeepj call setline(line("$")+1,level.a:msg)
129 endif
130 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200131 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100132" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200133 bo 1split
134 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200135 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200136 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100137 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100138" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200139 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100140 if type(a:msg) == 3
141 for msg in a:msg
142 NetrwKeepj call setline(line("$")+1,level.msg)
143 endfor
144 else
145 NetrwKeepj call setline(line("$"),level.a:msg)
146 endif
147 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200148 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100149" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200150 if &fo !~ '[ta]'
151 syn clear
152 syn match netrwMesgNote "^\*\*note\*\*"
153 syn match netrwMesgWarning "^\*\*warning\*\*"
154 syn match netrwMesgError "^\*\*error\*\*"
155 hi link netrwMesgWarning WarningMsg
156 hi link netrwMesgError Error
157 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100158" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200159 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200160
161 else
162 " (optional) netrw will show messages using echomsg. Even if the
163 " message doesn't appear, at least it'll be recallable via :messages
164" redraw!
165 if a:level == s:WARNING
166 echohl WarningMsg
167 elseif a:level == s:ERROR
168 echohl Error
169 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100170
171 if type(a:msg) == 3
172 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100173 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100174 endfor
175 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100176 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100177 endif
178
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100179" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200180 echohl None
181 endif
182
183" call Dret("netrw#ErrorMsg")
184endfun
185
186" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100187" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100188" Loosely, varname = value.
189fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100190" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100191 if !exists(a:varname)
192 if type(a:value) == 0
193 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200194 elseif type(a:value) == 1 && a:value =~ '^[{[]'
195 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100196 elseif type(a:value) == 1
197 exe "let ".a:varname."="."'".a:value."'"
198 else
199 exe "let ".a:varname."=".a:value
200 endif
201 endif
202endfun
203
204" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000205" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200206call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000207if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100208 call s:NetrwInit("s:THINLIST",0)
209 call s:NetrwInit("s:LONGLIST",1)
210 call s:NetrwInit("s:WIDELIST",2)
211 call s:NetrwInit("s:TREELIST",3)
212 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000213endif
214
215" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200216" Default option values: {{{2
217let g:netrw_localcopycmdopt = ""
218let g:netrw_localcopydircmdopt = ""
219let g:netrw_localmkdiropt = ""
220let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200221
222" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000223" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200224if (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")
225 call s:NetrwInit("g:netrw_use_errorwindow",2)
226else
227 call s:NetrwInit("g:netrw_use_errorwindow",1)
228endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200229
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000230if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100231 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000232 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100233 elseif executable("curl")
234 let g:netrw_dav_cmd = "curl"
235 else
236 let g:netrw_dav_cmd = ""
237 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000238endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000239if !exists("g:netrw_fetch_cmd")
240 if executable("fetch")
241 let g:netrw_fetch_cmd = "fetch -o"
242 else
243 let g:netrw_fetch_cmd = ""
244 endif
245endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100246if !exists("g:netrw_file_cmd")
247 if executable("elinks")
248 call s:NetrwInit("g:netrw_file_cmd","elinks")
249 elseif executable("links")
250 call s:NetrwInit("g:netrw_file_cmd","links")
251 endif
252endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000253if !exists("g:netrw_ftp_cmd")
254 let g:netrw_ftp_cmd = "ftp"
255endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200256let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200257if !exists("g:netrw_ftp_options")
258 let g:netrw_ftp_options= "-i -n"
259endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000260if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100261 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100262 let g:netrw_http_cmd = "wget"
263 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100264 elseif executable("curl")
265 let g:netrw_http_cmd = "curl"
266 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200267 elseif executable("elinks")
268 let g:netrw_http_cmd = "elinks"
269 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000270 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100271 let g:netrw_http_cmd = "fetch"
272 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200273 elseif executable("links")
274 let g:netrw_http_cmd = "links"
275 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000276 else
277 let g:netrw_http_cmd = ""
278 endif
279endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100280call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100281call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100282call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
283call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200284call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200285if !exists("g:netrw_scp_cmd")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200286 if executable("pscp")
287 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200288 else
289 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
290 endif
291endif
292
Bram Moolenaar5c736222010-01-06 20:54:52 +0100293call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
294call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000295
Nir Lichtman1e34b952024-05-08 19:19:34 +0200296if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000297 \ && exists("g:netrw_use_nt_rcp")
298 \ && g:netrw_use_nt_rcp
299 \ && executable( $SystemRoot .'/system32/rcp.exe')
300 let s:netrw_has_nt_rcp = 1
301 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000302else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000303 let s:netrw_has_nt_rcp = 0
304 let s:netrw_rcpmode = ''
305endif
306
307" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000308" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000309" Cygwin Detection ------- {{{3
310if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200311 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
312 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000313 else
314 let g:netrw_cygwin= 0
315 endif
316endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000317" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100318call s:NetrwInit("g:netrw_alto" , &sb)
319call s:NetrwInit("g:netrw_altv" , &spr)
320call s:NetrwInit("g:netrw_banner" , 1)
321call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200322call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100323call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200324call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100325call s:NetrwInit("g:netrw_compress" , "gzip")
326call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200327if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
328 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
329 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000330endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200331call s:NetrwInit("g:netrw_cursor" , 2)
332let s:netrw_usercul = &cursorline
333let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200334"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100335call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000336" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200337call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200338call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200339call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100340call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200341call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100342call s:NetrwInit("g:netrw_fastbrowse" , 1)
343call 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 +0000344if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000345 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
346 let g:netrw_ftp_list_cmd = "ls -lF"
347 let g:netrw_ftp_timelist_cmd = "ls -tlF"
348 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000349 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000350 let g:netrw_ftp_list_cmd = "dir"
351 let g:netrw_ftp_timelist_cmd = "dir"
352 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000353 endif
354endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100355call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000356" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100357call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000358if !exists("g:netrw_ignorenetrc")
359 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
360 let g:netrw_ignorenetrc= 1
361 else
362 let g:netrw_ignorenetrc= 0
363 endif
364endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100365call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000366if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000367 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100368 if exists("g:netrw_list_cmd_options")
369 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
370 else
371 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
372 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000373 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200374 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100375 if exists("g:netrw_list_cmd_options")
376 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
377 else
378 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
379 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000380 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100381" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000382 let g:netrw_list_cmd= ""
383 endif
384endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100385call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000386" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200387if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200388 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200389 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
390endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100391if !exists("g:netrw_localcmdshell")
392 let g:netrw_localcmdshell= ""
393endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000394if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200395 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000396 if g:netrw_cygwin
397 let g:netrw_localcopycmd= "cp"
398 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000399 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200400 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000401 endif
402 elseif has("unix") || has("macunix")
403 let g:netrw_localcopycmd= "cp"
404 else
405 let g:netrw_localcopycmd= ""
406 endif
407endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100408if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200409 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100410 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200411 let g:netrw_localcopydircmd = "cp"
412 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100413 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000414 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200415 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100416 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200417 elseif has("unix")
418 let g:netrw_localcopydircmd = "cp"
419 let g:netrw_localcopydircmdopt= " -R"
420 elseif has("macunix")
421 let g:netrw_localcopydircmd = "cp"
422 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100423 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200424 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100425 endif
426endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200427if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100428 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200429 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
430endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200431if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200432 if g:netrw_cygwin
433 call s:NetrwInit("g:netrw_localmkdir","mkdir")
434 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000435 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200436 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200437 endif
438else
439 call s:NetrwInit("g:netrw_localmkdir","mkdir")
440endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200441call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200442if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200443 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200444 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
445endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000446if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200447 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000448 if g:netrw_cygwin
449 let g:netrw_localmovecmd= "mv"
450 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000451 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200452 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000453 endif
454 elseif has("unix") || has("macunix")
455 let g:netrw_localmovecmd= "mv"
456 else
457 let g:netrw_localmovecmd= ""
458 endif
459endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100460" following serves as an example for how to insert a version&patch specific test
461"if v:version < 704 || (v:version == 704 && !has("patch1107"))
462"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100463call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
464" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000465if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000466 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000467endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000468if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000469 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
470endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000471" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100472call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
473call s:NetrwInit("g:netrw_maxfilenamelen", 32)
474call s:NetrwInit("g:netrw_menu" , 1)
475call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200476call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100477call s:NetrwInit("g:netrw_retmap" , 0)
478if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
479 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200480elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100481 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
482else
483 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000484endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100485call s:NetrwInit("g:netrw_preview" , 0)
486call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100487call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100488call s:NetrwInit("g:netrw_sshport" , "-p")
489call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
490call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
491call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100492call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
493" Default values - q-s ---------- {{{3
494call s:NetrwInit("g:netrw_quickhelp",0)
495let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100496 \ "(create new) %:file d:directory",
497 \ "(windows split&open) o:horz v:vert p:preview",
498 \ "i:style qf:file info O:obtain r:reverse",
499 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
500 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
501 \ "(history) qb:list u:go up U:go down",
502 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100503" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
504call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100505if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
506 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
507else
508 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
509endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100510call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
511call s:NetrwInit("g:netrw_sort_options" , "")
512call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000513if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100514 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200515 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100516 else
517 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000518 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000519endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100520call s:NetrwInit("g:netrw_special_syntax" , 0)
521call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200522call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100523call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100524call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000525" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100526call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200527if !exists("g:netrw_xstrlen")
528 if exists("g:Align_xstrlen")
529 let g:netrw_xstrlen= g:Align_xstrlen
530 elseif exists("g:drawit_xstrlen")
531 let g:netrw_xstrlen= g:drawit_xstrlen
532 elseif &enc == "latin1" || !has("multi_byte")
533 let g:netrw_xstrlen= 0
534 else
535 let g:netrw_xstrlen= 1
536 endif
537endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100538call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200539call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100540call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200541if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000542" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000543" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100544call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200545if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200546 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200547else
Bram Moolenaarff034192013-04-24 18:51:19 +0200548 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200549endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200550call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100551call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
552call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100553if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100554 let s:treedepthstring= "│ "
555else
556 let s:treedepthstring= "| "
557endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200558call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000559
560" BufEnter event ignored by decho when following variable is true
561" Has a side effect that doau BufReadPost doesn't work, so
562" files read by network transfer aren't appropriately highlighted.
563"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564
Bram Moolenaaradc21822011-04-01 18:03:16 +0200565" ======================
566" Netrw Initialization: {{{1
567" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200568if 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 +0100569" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100570 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200571" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100572 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100573 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
574 au VimEnter * let s:initbeval= &beval
575"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100576" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
577" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
578" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
579" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
580" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
581" 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 +0200582endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200583au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200584
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200585if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100586 com! -nargs=* NetrwKeepj keepj <args>
587else
588 let g:netrw_keepj= ""
589 com! -nargs=* NetrwKeepj <args>
590endif
591
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000592" ==============================
593" Netrw Utility Functions: {{{1
594" ==============================
595
Bram Moolenaaradc21822011-04-01 18:03:16 +0200596" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100597" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100598if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100599" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100600 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100601 if &ft != "netrw"
602 return ""
603 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200604 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
605 " popup error window is still showing
606 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
607 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
608 " text under mouse hasn't changed; only close window when it changes
609 call popup_close(s:popuperr_id)
610 unlet s:popuperr_text
611 else
612 let s:popuperr_text= v:beval_text
613 endif
614 let mesg= ""
615 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 +0100616 let mesg= ""
617 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
618 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
619 elseif getline(v:beval_lnum) =~ '^"\s*/'
620 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
621 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100622 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100623 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
624 let mesg = "S: edit sorting sequence"
625 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
626 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
627 elseif v:beval_text == "Quick" || v:beval_text == "Help"
628 let mesg = "Help: press <F1>"
629 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
630 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
631 else
632 let mesg= ""
633 endif
634 return mesg
635 endfun
636"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100637" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
638" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
639" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
640" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
641" 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 +0200642endif
643
Bram Moolenaar071d4272004-06-13 20:20:40 +0000644" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200645" netrw#Explore: launch the local browser in the directory of the current file {{{2
646" indx: == -1: Nexplore
647" == -2: Pexplore
648" == +: this is overloaded:
649" * If Nexplore/Pexplore is in use, then this refers to the
650" indx'th item in the w:netrw_explore_list[] of items which
651" matched the */pattern **/pattern *//pattern **//pattern
652" * If Hexplore or Vexplore, then this will override
653" g:netrw_winsize to specify the qty of rows or columns the
654" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100655" 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 +0200656" dosplit==1: the window will be split before running the local browser
657" style == 0: Explore style == 1: Explore!
658" == 2: Hexplore style == 3: Hexplore!
659" == 4: Vexplore style == 5: Vexplore!
660" == 6: Texplore
661fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100662" 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 +0100663" 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 +0200664 if !exists("b:netrw_curdir")
665 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100666" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200667 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100668
669 " record current file for Rexplore's benefit
670 if &ft != "netrw"
671 let w:netrw_rexfile= expand("%:p")
672 endif
673
674 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200675 let curdir = simplify(b:netrw_curdir)
676 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200677 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200678 let curdir= substitute(curdir,'\','/','g')
679 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100680" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100681
682 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
683 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
684 " try Explore again.
685 if a:0 > 0
686" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100687 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
688 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
689 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
690 \ '~'.expand("<slnum>"))
691 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
692" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100693 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
694" call Dret("netrw#Explore : returning from retry")
695 return
696" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100697" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100698 endif
699 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200700
701 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200702 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100703" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100704 sil! let keepregstar = @*
705 sil! let keepregplus = @+
706 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200707 sil! let keepregslash= @/
708
Bram Moolenaar8d043172014-01-23 14:24:41 +0100709 " if dosplit
710 " -or- file has been modified AND file not hidden when abandoned
711 " -or- Texplore used
712 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100713" 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 +0200714 call s:SaveWinVars()
715 let winsz= g:netrw_winsize
716 if a:indx > 0
717 let winsz= a:indx
718 endif
719
720 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100721" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200722 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200723 if winsz == 0|let winsz= ""|endif
724 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100725" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200726
727 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100728" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200729 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200730 if winsz == 0|let winsz= ""|endif
731 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100732" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200733
734 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100735" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200736 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200737 if winsz == 0|let winsz= ""|endif
738 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100739" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200740
741 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100742" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200743 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200744 if winsz == 0|let winsz= ""|endif
745 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100746" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200747
748 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100749" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200750 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200751 if winsz == 0|let winsz= ""|endif
752 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100753" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200754
755 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100756" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200757 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200758 if winsz == 0|let winsz= ""|endif
759 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100760" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200761
762 elseif a:style == 6 " Texplore
763 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100764" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200765 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100766" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200767 call s:RestoreBufVars()
768 endif
769 call s:RestoreWinVars()
770" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100771" 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 +0200772 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100773 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200774
775 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100776" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100778" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200779 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100780" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200781 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100782" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
784 if dirname !~ '/$'
785 let dirname= dirname."/"
786 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100787" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200788 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100789" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200790 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100791" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200792 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100793" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200794 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 let dirname= a:1
799 endif
800 else
801 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100802" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200803 call s:NetrwClearExplore()
804" call Dret("netrw#Explore : cleared list")
805 return
806 endif
807
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100808" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200809 if dirname =~ '\.\./\=$'
810 let dirname= simplify(fnamemodify(dirname,':p:h'))
811 elseif dirname =~ '\.\.' || dirname == '.'
812 let dirname= simplify(fnamemodify(dirname,':p'))
813 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100814" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200815
816 if dirname =~ '^\*//'
817 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100818" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200819 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
820 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100821" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200822 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
823
824 elseif dirname =~ '^\*\*//'
825 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100826" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200827 let pattern= substitute(dirname,'^\*\*//','','')
828 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100829" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200830
831 elseif dirname =~ '/\*\*/'
832 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100833" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200834 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200835 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200836 let b:netrw_curdir = prefixdir
837 else
838 let b:netrw_curdir= getcwd().'/'.prefixdir
839 endif
840 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
841 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100842" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
843" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200844
845 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200846 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200847 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100848" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200849
850 elseif dirname=~ '^\*\*/'
851 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
852 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100853" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200854
855 else
856 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100857" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200858 endif
859
860 if starpat == 0 && a:indx >= 0
861 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100862" 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 +0200863 if dirname == ""
864 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100865" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200866 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200867 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200868 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200869 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200870 if dirname == ""
871 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200872 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100873 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100874 " depending on whether backslashes have been converted to forward slashes by earlier code).
875 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200876 let dirname= b:netrw_curdir."/".dirname
877 endif
878 elseif dirname !~ '^/'
879 let dirname= b:netrw_curdir."/".dirname
880 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100881" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200882 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100883" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
884" 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 +0200885 endif
886 if exists("w:netrw_bannercnt")
887 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
888 " If one wants to return the same place in the netrw window, use :Rex instead.
889 exe w:netrw_bannercnt
890 endif
891
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100892" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200893 " ---------------------------------------------------------------------
894 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
895" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100896" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200897" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100898" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200899" endif
900 " ---------------------------------------------------------------------
901
902 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
903 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
904 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
905 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
906 elseif a:indx <= 0
907 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100908" 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 +0200909 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100910" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200911 let s:didstarstar= 1
912 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
913 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
914 endif
915
916 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100917" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200918 if !exists("w:netrw_explore_indx")
919 let w:netrw_explore_indx= 0
920 endif
921
922 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100923" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200924
925 if indx == -1
926 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100927" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200928 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100929 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 +0200930 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100931" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100932 if @* != keepregstar | sil! let @* = keepregstar | endif
933 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100934 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200935 sil! let @/ = keepregslash
936" call Dret("netrw#Explore")
937 return
938 endif
939 let indx= w:netrw_explore_indx
940 if indx < 0 | let indx= 0 | endif
941 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
942 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100943" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200944 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
945 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100946" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200947 endwhile
948 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100949" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200950
951 elseif indx == -2
952 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100953" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200954 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100955 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 +0200956 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100957" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100958 if @* != keepregstar | sil! let @* = keepregstar | endif
959 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100960 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200961 sil! let @/ = keepregslash
962" call Dret("netrw#Explore")
963 return
964 endif
965 let indx= w:netrw_explore_indx
966 if indx < 0 | let indx= 0 | endif
967 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
968 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100969" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200970 while indx >= 0 && curfile == w:netrw_explore_list[indx]
971 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100972" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200973 endwhile
974 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100975" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200976
977 else
978 " Explore -- initialize
979 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100980" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100981 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200982 let w:netrw_explore_indx= 0
983 if !exists("b:netrw_curdir")
984 let b:netrw_curdir= getcwd()
985 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100986" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200987
988 " switch on starpat to build the w:netrw_explore_list of files
989 if starpat == 1
990 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100991" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
992" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200993 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100994 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200995 catch /^Vim\%((\a\+)\)\=:E480/
996 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
997" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
998 return
999 endtry
1000 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1001 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1002
1003 elseif starpat == 2
1004 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001005" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1006" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001007 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001008 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001009 catch /^Vim\%((\a\+)\)\=:E480/
1010 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1011 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001012 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001013" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001014 if @* != keepregstar | sil! let @* = keepregstar | endif
1015 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001016 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001017 sil! let @/ = keepregslash
1018" call Dret("netrw#Explore : no files matched pattern")
1019 return
1020 endtry
1021 let s:netrw_curdir = b:netrw_curdir
1022 let w:netrw_explore_list = getqflist()
1023 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1024 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1025
1026 elseif starpat == 3
1027 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001028" 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 +02001029 let filepat= substitute(dirname,'^\*/','','')
1030 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001031" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1032" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001033 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1034 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1035
1036 elseif starpat == 4
1037 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001038" 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 +02001039 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1040 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1041 endif " switch on starpat to build w:netrw_explore_list
1042
1043 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001044" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1045" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001046
1047 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001048 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001049 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001050" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001051 if @* != keepregstar | sil! let @* = keepregstar | endif
1052 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001053 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001054 sil! let @/ = keepregslash
1055" call Dret("netrw#Explore : no files matched")
1056 return
1057 endif
1058 endif " if indx ... endif
1059
1060 " NetrwStatusLine support - for exploring support
1061 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001062" 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 +02001063
1064 " wrap the indx around, but issue a note
1065 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001066" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001067 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1068 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001069 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001070 endif
1071
1072 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001073" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001074 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001075" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001076
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001077" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001078 call netrw#LocalBrowseCheck(newdir)
1079 if !exists("w:netrw_liststyle")
1080 let w:netrw_liststyle= g:netrw_liststyle
1081 endif
1082 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001083 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001084 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001085 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001086 endif
1087 let w:netrw_explore_mtchcnt = indx + 1
1088 let w:netrw_explore_bufnr = bufnr("%")
1089 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001090 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001091" 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 +02001092
1093 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001094" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001095 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001096 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 +02001097 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001098 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001099" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001100 if @* != keepregstar | sil! let @* = keepregstar | endif
1101 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001102 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001103 sil! let @/ = keepregslash
1104" call Dret("netrw#Explore : missing +path_extra")
1105 return
1106 endif
1107
1108 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001109" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001110 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1111 sil! unlet w:netrw_treedict
1112 sil! unlet w:netrw_treetop
1113 endif
1114 let newdir= dirname
1115 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001116 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001117 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001118 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001119 endif
1120 endif
1121
1122 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001123" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1124" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001125 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001126" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001127 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001128 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001129" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001130 let s:explore_prvdir = b:netrw_curdir
1131 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001132 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001133 if b:netrw_curdir !~ '/$'
1134 let dirlen= dirlen + 1
1135 endif
1136 let prvfname= ""
1137 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001138" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001139 if fname =~ '^'.b:netrw_curdir
1140 if s:explore_match == ""
1141 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1142 else
1143 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1144 endif
1145 elseif fname !~ '^/' && fname != prvfname
1146 if s:explore_match == ""
1147 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1148 else
1149 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1150 endif
1151 endif
1152 let prvfname= fname
1153 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001154" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001155 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1156 exe "2match netrwMarkFile /".s:explore_match."/"
1157 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001158 endif
1159 echo "<s-up>==Pexplore <s-down>==Nexplore"
1160 else
1161 2match none
1162 if exists("s:explore_match") | unlet s:explore_match | endif
1163 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001164" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001165 endif
1166
Bram Moolenaara6878372014-03-22 21:02:50 +01001167 " since Explore may be used to initialize netrw's browser,
1168 " there's no danger of a late FocusGained event on initialization.
1169 " Consequently, set s:netrw_events to 2.
1170 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001171 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001172" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001173 if @* != keepregstar | sil! let @* = keepregstar | endif
1174 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001175 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001176 sil! let @/ = keepregslash
1177" call Dret("netrw#Explore : @/<".@/.">")
1178endfun
1179
1180" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001181" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001182" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1183" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1184" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1185" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1186" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001187fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001188" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001189 let curwin= winnr()
1190
Bram Moolenaara6878372014-03-22 21:02:50 +01001191 if a:0 > 0 && a:1 != ""
1192 " if a netrw window is already on the left-side of the tab
1193 " and a directory has been specified, explore with that
1194 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001195" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001196 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001197" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001198 exe "1wincmd w"
1199 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001200" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001201 exe "Explore ".fnameescape(a1)
1202 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001203 let s:lexplore_win= curwin
1204 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001205 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001206" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207 unlet t:netrw_lexposn
1208 endif
1209" call Dret("netrw#Lexplore")
1210 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001211 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001212 exe curwin."wincmd w"
1213 else
1214 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001215" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001216 endif
1217
Bram Moolenaar8d043172014-01-23 14:24:41 +01001218 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001219 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001220 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001221" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001222 else
1223 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001224" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001225 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001226" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001227
1228 if lexwinnr > 0
1229 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001230" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001231 exe lexwinnr."wincmd w"
1232 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001233 let t:netrw_lexposn = winsaveview()
1234" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001235" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001236 close
1237 if lexwinnr < curwin
1238 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001239 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001240 if lexwinnr != curwin
1241 exe curwin."wincmd w"
1242 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001243 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001244" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001245
1246 else
1247 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001248" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001249 exe "1wincmd w"
1250 let keep_altv = g:netrw_altv
1251 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001252 if a:count != 0
1253 let netrw_winsize = g:netrw_winsize
1254 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001255 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001256 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001257" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001258 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 +02001259" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001260 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001261" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001262 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001263 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001264 elseif curfile =~ '^\a\{3,}://'
1265" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001266 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001267 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001268" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001269 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001270 endif
1271 if a:count != 0
1272 let g:netrw_winsize = netrw_winsize
1273 endif
1274 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001275 let g:netrw_altv = keep_altv
1276 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001277 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1278 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001279 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001280 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001281" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1282" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001283 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001284" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001285" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1286 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001287 unlet t:netrw_lexposn
1288 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001289 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001290
1291 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001292 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001293 if a:rightside
1294 let g:netrw_chgwin= 1
1295 else
1296 let g:netrw_chgwin= 2
1297 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001298" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001299 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001300
Bram Moolenaar8d043172014-01-23 14:24:41 +01001301" call Dret("netrw#Lexplore")
1302endfun
1303
1304" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001305" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001306" supports :NetrwClean -- remove netrw from first directory on runtimepath
1307" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001308fun! netrw#Clean(sys)
1309" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001310
1311 if a:sys
1312 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1313 else
1314 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1315 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001316" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001317 let diddel= 0
1318 let diddir= ""
1319
1320 if choice == 1
1321 for dir in split(&rtp,',')
1322 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001323" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001324 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1325 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1326 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1327 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1328 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1329 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 +00001330 let diddir= dir
1331 let diddel= diddel + 1
1332 if !a:sys|break|endif
1333 endif
1334 endfor
1335 endif
1336
1337 echohl WarningMsg
1338 if diddel == 0
1339 echomsg "netrw is either not installed or not removable"
1340 elseif diddel == 1
1341 echomsg "removed one copy of netrw from <".diddir.">"
1342 else
1343 echomsg "removed ".diddel." copies of netrw"
1344 endif
1345 echohl None
1346
Bram Moolenaara6878372014-03-22 21:02:50 +01001347" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001348endfun
1349
Bram Moolenaar5c736222010-01-06 20:54:52 +01001350" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001351" netrw#MakeTgt: make a target out of the directory name provided {{{2
1352fun! netrw#MakeTgt(dname)
1353" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1354 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001355 let svpos = winsaveview()
1356" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001357 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1358" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001359 if s:netrwmftgt_islocal
1360 let netrwmftgt= simplify(a:dname)
1361 else
1362 let netrwmftgt= a:dname
1363 endif
1364 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1365 " re-selected target, so just clear it
1366 unlet s:netrwmftgt s:netrwmftgt_islocal
1367 else
1368 let s:netrwmftgt= netrwmftgt
1369 endif
1370 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001371 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001372 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001373" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1374 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001375" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001376endfun
1377
Bram Moolenaara6878372014-03-22 21:02:50 +01001378" ---------------------------------------------------------------------
1379" netrw#Obtain: {{{2
1380" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001381" islocal=0 obtain from remote source
1382" =1 obtain from local source
1383" fname : a filename or a list of filenames
1384" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001385fun! netrw#Obtain(islocal,fname,...)
1386" 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 +02001387 " NetrwStatusLine support - for obtaining support
1388
1389 if type(a:fname) == 1
1390 let fnamelist= [ a:fname ]
1391 elseif type(a:fname) == 3
1392 let fnamelist= a:fname
1393 else
1394 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 +01001395" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001396 return
1397 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001398" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001399 if a:0 > 0
1400 let tgtdir= a:1
1401 else
1402 let tgtdir= getcwd()
1403 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001404" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001405
1406 if exists("b:netrw_islocal") && b:netrw_islocal
1407 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001408" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001409 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1410 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001411 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001412 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001413" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001414 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001415" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001416 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001417 if v:shell_error != 0
1418 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 +01001419" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001420 return
1421 endif
1422 endfor
1423 else
1424 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001425" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1426 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1427" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001428 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001429 if v:shell_error != 0
1430 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 +01001431" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001432 return
1433 endif
1434 endif
1435 elseif !exists("b:netrw_curdir")
1436 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1437 else
1438 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1439 endif
1440
1441 else
1442 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001443" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001444 if type(a:fname) == 1
1445 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1446 endif
1447 call s:NetrwMethod(b:netrw_curdir)
1448
1449 if b:netrw_method == 4
1450 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001451" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001452 if exists("g:netrw_port") && g:netrw_port != ""
1453 let useport= " ".g:netrw_scpport." ".g:netrw_port
1454 else
1455 let useport= ""
1456 endif
1457 if b:netrw_fname =~ '/'
1458 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1459 else
1460 let path= ""
1461 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001462 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001463 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 +02001464
1465 elseif b:netrw_method == 2
1466 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001467" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001468 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001469 let tmpbufnr= bufnr("%")
1470 setl ff=unix
1471 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001472 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001473" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001474 endif
1475
1476 if exists("b:netrw_fname") && b:netrw_fname != ""
1477 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001478" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001479 endif
1480
1481 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001482 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001483" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001484 endif
1485 for fname in fnamelist
1486 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001487" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001488 endfor
1489 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001490 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 +02001491 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001492 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001493 endif
1494 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1495 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1496 let debugkeep= &debug
1497 setl debug=msg
1498 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1499 let &debug= debugkeep
1500 endif
1501
1502 elseif b:netrw_method == 3
1503 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001504" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001505 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001506 let tmpbufnr= bufnr("%")
1507 setl ff=unix
1508
1509 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001510 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001511" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001512 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001513 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001514" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001515 endif
1516
1517 if exists("g:netrw_uid") && g:netrw_uid != ""
1518 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001519 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001520" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001521 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001522 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001523 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001524" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001525 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001526 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001527" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001528 endif
1529 endif
1530
1531 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001532 NetrwKeepj put =g:netrw_ftpmode
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
1536 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001537 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001538" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001539 endif
1540
1541 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001542 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001543" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001544 endif
1545
1546 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001547 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001548" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001549 endif
1550 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001551 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001552 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001553" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001554
1555 " perform ftp:
1556 " -i : turns off interactive prompting from ftp
1557 " -n unix : DON'T use <.netrc>, even though it exists
1558 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001559 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1560 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001561 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001562 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1563 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001564" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001565 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001566 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001567 endif
1568 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001569
1570 elseif b:netrw_method == 9
1571 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001572" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001573 if a:fname =~ '/'
1574 let localfile= substitute(a:fname,'^.*/','','')
1575 else
1576 let localfile= a:fname
1577 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001578 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 +02001579
Bram Moolenaarff034192013-04-24 18:51:19 +02001580 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001581 " probably a badly formed url; protocol not recognized
1582" call Dret("netrw#Obtain : unsupported method")
1583 return
1584
1585 else
1586 " protocol recognized but not supported for Obtain (yet?)
1587 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001588 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001589 endif
1590" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001591 return
1592 endif
1593
1594 " restore status line
1595 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001596 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001597 endif
1598
1599 endif
1600
1601 " cleanup
1602 if exists("tmpbufnr")
1603 if bufnr("%") != tmpbufnr
1604 exe tmpbufnr."bw!"
1605 else
1606 q!
1607 endif
1608 endif
1609
Bram Moolenaara6878372014-03-22 21:02:50 +01001610" call Dret("netrw#Obtain")
1611endfun
1612
1613" ---------------------------------------------------------------------
1614" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1615fun! netrw#Nread(mode,fname)
1616" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001617 let svpos= winsaveview()
1618" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001619 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001620" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1621 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001622
1623 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1624 if exists("w:netrw_bannercnt")
1625 " start with cursor just after the banner
1626 exe w:netrw_bannercnt
1627 endif
1628 endif
1629" call Dret("netrw#Nread")
1630endfun
1631
1632" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001633" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1634" Options get restored by s:NetrwOptionsRestore()
1635"
1636" Option handling:
1637" * save user's options (s:NetrwOptionsSave)
1638" * set netrw-safe options (s:NetrwOptionsSafe)
1639" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1640" * restore user's options (s:netrwOPtionsRestore)
1641" - restore a user option when != safe option (s:NetrwRestoreSetting)
1642" vt: (variable type) normally its either "w:" or "s:"
1643fun! s:NetrwOptionsSave(vt)
1644" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1645" 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 +02001646" 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>"))
1647" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001648
1649 if !exists("{a:vt}netrw_optionsave")
1650 let {a:vt}netrw_optionsave= 1
1651 else
1652" call Dret("s:NetrwOptionsSave : options already saved")
1653 return
1654 endif
1655" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1656
1657 " Save current settings and current directory
1658" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1659 let s:yykeep = @@
1660 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1661 let {a:vt}netrw_aikeep = &l:ai
1662 let {a:vt}netrw_awkeep = &l:aw
1663 let {a:vt}netrw_bhkeep = &l:bh
1664 let {a:vt}netrw_blkeep = &l:bl
1665 let {a:vt}netrw_btkeep = &l:bt
1666 let {a:vt}netrw_bombkeep = &l:bomb
1667 let {a:vt}netrw_cedit = &cedit
1668 let {a:vt}netrw_cikeep = &l:ci
1669 let {a:vt}netrw_cinkeep = &l:cin
1670 let {a:vt}netrw_cinokeep = &l:cino
1671 let {a:vt}netrw_comkeep = &l:com
1672 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001673 let {a:vt}netrw_cuckeep = &l:cuc
1674 let {a:vt}netrw_culkeep = &l:cul
1675" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001676 let {a:vt}netrw_diffkeep = &l:diff
1677 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001678 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1679 let {a:vt}netrw_ffkeep = &l:ff
1680 endif
1681 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1682 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001683 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001684 let {a:vt}netrw_hidkeep = &l:hidden
1685 let {a:vt}netrw_imkeep = &l:im
1686 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001687 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001688 let {a:vt}netrw_lskeep = &l:ls
1689 let {a:vt}netrw_makeep = &l:ma
1690 let {a:vt}netrw_magickeep = &l:magic
1691 let {a:vt}netrw_modkeep = &l:mod
1692 let {a:vt}netrw_nukeep = &l:nu
1693 let {a:vt}netrw_rnukeep = &l:rnu
1694 let {a:vt}netrw_repkeep = &l:report
1695 let {a:vt}netrw_rokeep = &l:ro
1696 let {a:vt}netrw_selkeep = &l:sel
1697 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001698 if !g:netrw_use_noswf
1699 let {a:vt}netrw_swfkeep = &l:swf
1700 endif
1701 let {a:vt}netrw_tskeep = &l:ts
1702 let {a:vt}netrw_twkeep = &l:tw " textwidth
1703 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1704 let {a:vt}netrw_wrapkeep = &l:wrap
1705 let {a:vt}netrw_writekeep = &l:write
1706
1707 " save a few selected netrw-related variables
1708" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1709 if g:netrw_keepdir
1710 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001711" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001712 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001713 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001714 sil! let {a:vt}netrw_starkeep = @*
1715 sil! let {a:vt}netrw_pluskeep = @+
1716 endif
1717 sil! let {a:vt}netrw_slashkeep= @/
1718
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001719" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001720" 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>"))
1721" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1722endfun
1723
1724" ---------------------------------------------------------------------
1725" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1726" Use s:NetrwSaveOptions() to save user settings
1727" Use s:NetrwOptionsRestore() to restore user settings
1728fun! s:NetrwOptionsSafe(islocal)
1729" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1730" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1731" 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>"))
1732 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1733 call s:NetrwSetSafeSetting("&l:ai",0)
1734 call s:NetrwSetSafeSetting("&l:aw",0)
1735 call s:NetrwSetSafeSetting("&l:bl",0)
1736 call s:NetrwSetSafeSetting("&l:bomb",0)
1737 if a:islocal
1738 call s:NetrwSetSafeSetting("&l:bt","nofile")
1739 else
1740 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1741 endif
1742 call s:NetrwSetSafeSetting("&l:ci",0)
1743 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001744 if g:netrw_fastbrowse > a:islocal
1745 call s:NetrwSetSafeSetting("&l:bh","hide")
1746 else
1747 call s:NetrwSetSafeSetting("&l:bh","delete")
1748 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001749 call s:NetrwSetSafeSetting("&l:cino","")
1750 call s:NetrwSetSafeSetting("&l:com","")
1751 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1752 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1753 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001754 if &go =~ 'a' | set go-=a | endif
1755 if &go =~ 'A' | set go-=A | endif
1756 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001757 call s:NetrwSetSafeSetting("&l:hid",0)
1758 call s:NetrwSetSafeSetting("&l:im",0)
1759 setl isk+=@ isk+=* isk+=/
1760 call s:NetrwSetSafeSetting("&l:magic",1)
1761 if g:netrw_use_noswf
1762 call s:NetrwSetSafeSetting("swf",0)
1763 endif
1764 call s:NetrwSetSafeSetting("&l:report",10000)
1765 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1766 call s:NetrwSetSafeSetting("&l:spell",0)
1767 call s:NetrwSetSafeSetting("&l:tw",0)
1768 call s:NetrwSetSafeSetting("&l:wig","")
1769 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001770
1771 " set up cuc and cul based on g:netrw_cursor and listing style
1772 " COMBAK -- cuc cul related
1773 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001774
1775 " allow the user to override safe options
1776" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1777 if &ft == "netrw"
1778" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1779 keepalt NetrwKeepj doau FileType netrw
1780 endif
1781
1782" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1783" 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>"))
1784" call Dret("s:NetrwOptionsSafe")
1785endfun
1786
1787" ---------------------------------------------------------------------
1788" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1789fun! s:NetrwOptionsRestore(vt)
1790" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001791" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001792" 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 +01001793 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001794" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001795
1796 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1797 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001798" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001799 filetype detect
1800" 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>"))
1801 else
1802 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001803 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001804" 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 +02001805" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001806 return
1807 endif
1808 unlet {a:vt}netrw_optionsave
1809
1810 if exists("+acd")
1811 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001812" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001813 let curdir = getcwd()
1814 let &l:acd = {a:vt}netrw_acdkeep
1815 unlet {a:vt}netrw_acdkeep
1816 if &l:acd
1817 call s:NetrwLcd(curdir)
1818 endif
1819 endif
1820 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001821" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001822 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1823 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1824 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1825 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1826 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001827" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001828 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1829 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1830 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1831 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1832 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001833" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001834 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1835 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1836 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1837 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1838 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001839 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001840" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1841 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1842 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001843 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001844 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1845" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1846 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1847 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1848" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1849 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1850" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1851 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1852 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001853 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001854 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1855 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1856" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1857 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1858 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1859 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1860 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1861" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001862 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001863 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1864 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1865 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001866 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001867" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001868 call s:NetrwRestoreSetting("s:yykeep","@@")
1869 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1870 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1871 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1872 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1873
Bram Moolenaara6878372014-03-22 21:02:50 +01001874 if exists("{a:vt}netrw_swfkeep")
1875 if &directory == ""
1876 " user hasn't specified a swapfile directory;
1877 " netrw will temporarily set the swapfile directory
1878 " to the current directory as returned by getcwd().
1879 let &l:directory= getcwd()
1880 sil! let &l:swf = {a:vt}netrw_swfkeep
1881 setl directory=
1882 unlet {a:vt}netrw_swfkeep
1883 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001884 if !g:netrw_use_noswf
1885 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1886 sil! let &l:swf= {a:vt}netrw_swfkeep
1887 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001888 unlet {a:vt}netrw_swfkeep
1889 endif
1890 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001891 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001892 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1893 if exists("{a:vt}netrw_dirkeep")
1894 call s:NetrwLcd(dirkeep)
1895 unlet {a:vt}netrw_dirkeep
1896 endif
1897 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001898 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001899" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001900 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1901 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001902 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001903 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001904
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001905" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1906" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1907" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1908" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1909" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001910 " Moved the filetype detect here from NetrwGetFile() because remote files
1911 " were having their filetype detect-generated settings overwritten by
1912 " NetrwOptionRestore.
1913 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001914" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1915 filetype detect
1916" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001917 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001918" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001919" 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 +02001920" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001921endfun
1922
1923" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001924" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1925" but only when the options' value and the safe setting differ
1926" Doing this means that netrw will not come up as having changed a
1927" setting last when it really didn't actually change it.
1928"
1929" Called from s:NetrwOptionsSafe
1930" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1931fun! s:NetrwSetSafeSetting(setting,safesetting)
1932" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001933
Bram Moolenaar85850f32019-07-19 22:05:51 +02001934 if a:setting =~ '^&'
1935" call Decho("fyi: a:setting starts with &")
1936 exe "let settingval= ".a:setting
1937" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001938
Bram Moolenaar85850f32019-07-19 22:05:51 +02001939 if settingval != a:safesetting
1940" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1941 if type(a:safesetting) == 0
1942 exe "let ".a:setting."=".a:safesetting
1943 elseif type(a:safesetting) == 1
1944 exe "let ".a:setting."= '".a:safesetting."'"
1945 else
1946 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1947 endif
1948 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001949 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001950
Bram Moolenaar85850f32019-07-19 22:05:51 +02001951" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001952endfun
1953
1954" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001955" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1956" but only if the setting value differs from the associated keepvar.
1957" Doing this means that netrw will not come up as having changed a
1958" setting last when it really didn't actually change it.
1959"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001960" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001961" keepvars are set up by s:NetrwOptionsSave
1962fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001963""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001964
Bram Moolenaar85850f32019-07-19 22:05:51 +02001965 " typically called from s:NetrwOptionsRestore
1966 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1967 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001968 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001969 if exists(a:keepvar)
1970 exe "let keepvarval= ".a:keepvar
1971 exe "let setting= ".a:setting
1972
1973"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1974"" call Decho("fyi: keepvarval=".keepvarval)
1975"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1976
1977 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001978"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001979 if type(a:setting) == 0
1980 exe "let ".a:setting."= ".keepvarval
1981 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001982 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001983 else
1984 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1985 endif
1986 endif
1987
1988 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001989 endif
1990
Bram Moolenaar85850f32019-07-19 22:05:51 +02001991"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001992endfun
1993
1994" ---------------------------------------------------------------------
1995" NetrwStatusLine: {{{2
1996fun! NetrwStatusLine()
1997
1998" vvv NetrwStatusLine() debugging vvv
1999" let g:stlmsg=""
2000" if !exists("w:netrw_explore_bufnr")
2001" let g:stlmsg="!X<explore_bufnr>"
2002" elseif w:netrw_explore_bufnr != bufnr("%")
2003" let g:stlmsg="explore_bufnr!=".bufnr("%")
2004" endif
2005" if !exists("w:netrw_explore_line")
2006" let g:stlmsg=" !X<explore_line>"
2007" elseif w:netrw_explore_line != line(".")
2008" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2009" endif
2010" if !exists("w:netrw_explore_list")
2011" let g:stlmsg=" !X<explore_list>"
2012" endif
2013" ^^^ NetrwStatusLine() debugging ^^^
2014
2015 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")
2016 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002017 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002018 let &laststatus = s:netrw_users_ls
2019 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2020 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2021 return ""
2022 else
2023 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2024 endif
2025endfun
2026
Bram Moolenaar85850f32019-07-19 22:05:51 +02002027" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002028" Netrw Transfer Functions: {{{1
2029" ===============================
2030
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002032" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002033" mode: =0 read remote file and insert before current line
2034" =1 read remote file and insert after current line
2035" =2 replace with remote file
2036" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002037fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002038" 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 +00002039
Bram Moolenaar5c736222010-01-06 20:54:52 +01002040 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002041 call s:NetrwOptionsSave("w:")
2042 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002043 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002044 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2045 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2046 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002047" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002048
Bram Moolenaar5c736222010-01-06 20:54:52 +01002049 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002050 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002051 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002052 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002053 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002054 elseif a:mode == 2 " replace with remote file
2055 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002056 elseif a:mode == 3 " skip read of file (leave as temporary)
2057 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002058 else
2059 exe a:mode
2060 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002061 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002062 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002063" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002064
Bram Moolenaar5c736222010-01-06 20:54:52 +01002065 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002066 let tmpfile= s:GetTempfile("")
2067 if tmpfile == ""
2068" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002069 return
2070 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002071
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002072 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002073
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002074 " attempt to repeat with previous host-file-etc
2075 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002076" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 let choice = b:netrw_lastfile
2078 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002079
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002080 else
2081 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002082" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002083
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002084 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002085 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002086 echomsg 'NetRead Usage:'
2087 echomsg ':Nread machine:path uses rcp'
2088 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2089 echomsg ':Nread "machine id password path" uses ftp'
2090 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2091 echomsg ':Nread fetch://machine/path uses fetch'
2092 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2093 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002094 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002095 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002096 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2097 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2098 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2099 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002100 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002101 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002102
Bram Moolenaar9964e462007-05-05 17:54:07 +00002103 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002104 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002105" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002106 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002107 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002108 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002109 else
2110 " case "... ... ..."
2111 let choice = strpart(choice,1,strlen(choice)-1)
2112 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002113
Bram Moolenaar9964e462007-05-05 17:54:07 +00002114 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002115 let wholechoice = wholechoice . " " . choice
2116 let ichoice = ichoice + 1
2117 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002118 if !exists("g:netrw_quiet")
2119 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2120 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002121" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002122 return
2123 endif
2124 let choice= a:{ichoice}
2125 endwhile
2126 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2127 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002128 endif
2129 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002131" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002132 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002133
Bram Moolenaar5c736222010-01-06 20:54:52 +01002134 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002135 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002136 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002137" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002138 return
2139 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002140 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002141
Bram Moolenaar8d043172014-01-23 14:24:41 +01002142 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002143" 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 +02002144 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002145" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002146 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002147" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002148 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002150
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002151 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002152 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002153 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002154 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2155 echo "(netrw) Processing your read request..."
2156 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002157
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002158 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002159 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002160 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002161" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002162 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002163 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002164 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002165 " ER: the tmpfile is full path: rcp sees C:\... as host C
2166 if s:netrw_has_nt_rcp == 1
2167 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2168 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2169 else
2170 " Any way needed it machine contains a '.'
2171 let uid_machine = g:netrw_machine .'.'. $USERNAME
2172 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002173 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002174 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2175 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2176 else
2177 let uid_machine = g:netrw_machine
2178 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002180 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 +00002181 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002182 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002183
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002184 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002185 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002186 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002187" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002188 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002189 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002190 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002191 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002192 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002193" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002194 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002195 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002196" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002197 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002198 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002199" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002200 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002201 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 +00002202 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002203 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002204 endif
2205 " 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 +00002206 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002207 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002208 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002209 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002210 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002211 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002212 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002213 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002214 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2215 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002216 q!
2217 endif
2218 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002219 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002220 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002221
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002222 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002223 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002224 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2225 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002226" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002227 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002228 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002229 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002230 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002231 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002232 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002233" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002235 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002236" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002237 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002238
Bram Moolenaar97d62492012-11-15 21:28:22 +01002239 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002240 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002241 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002242" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002243 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002244 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002245 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002246" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002247 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002248 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002249" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002250 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002251 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002252
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002253 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002254 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002255" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002256 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002257 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002258 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002259" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002260 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002261 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002262" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002263
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002264 " perform ftp:
2265 " -i : turns off interactive prompting from ftp
2266 " -n unix : DON'T use <.netrc>, even though it exists
2267 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002268 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002269 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002270 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2271 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002272" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002273 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002274 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002275 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002276 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002277 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002278 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002279 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002280
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002281 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002282 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002283 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002284" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002285 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002286 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002287 else
2288 let useport= ""
2289 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002290 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2291 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002292 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002293 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2294 else
2295 let tmpfile_get = tmpfile
2296 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002297 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 +00002298 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002299 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002300
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002301 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002302 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002303 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002304" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002305 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002306 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002307 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002308 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002309" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002310 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002311 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002312
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002313 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2314 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002315" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002316 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002317 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 +00002318 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002319 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 +00002320 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002321 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002322
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002323 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002324 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002325" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002326 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2327 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002328" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2329" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2330 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 +00002331 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002332" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002333 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002334 endif
2335 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002336" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002337 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002338
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002339 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002340 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002341 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002342" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002343
Bram Moolenaar5c736222010-01-06 20:54:52 +01002344 if !executable(g:netrw_dav_cmd)
2345 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2346" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2347 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002348 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002349 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002350 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 +01002351 else
2352 " Construct execution string (four lines) which will be passed through filter
2353 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2354 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002355 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002356 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002357 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002358 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002359 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002360 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002361 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002362 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002363 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002364 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2365 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002366
Bram Moolenaar5c736222010-01-06 20:54:52 +01002367 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002368 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002369 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002370 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002371 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002372 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002373 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002374
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002375 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002376 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002377 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002378" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002379 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 +00002380 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002381 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002382
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002383 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002384 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002385 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002386 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002387" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002388 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002389 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002390 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002391 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002392" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002393 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002394 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002395 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002396 let netrw_option= "http"
2397 else
2398 let netrw_option= "ftp"
2399 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002400" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002401
Bram Moolenaar446cb832008-06-24 21:56:24 +00002402 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002403 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 +00002404 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002405 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002406 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002407
Bram Moolenaar446cb832008-06-24 21:56:24 +00002408 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002409 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002410" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002411 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002412
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002413 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002414 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002415 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002416" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2417 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 +00002418 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002419 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002420
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002421 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002422 " NetRead: (file) NetRead Method #10 {{{3
2423 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002424" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2425 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002426 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2427 let b:netrw_lastfile = choice
2428
2429 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002430 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002431 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002432 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002433 endif
2434 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002435
Bram Moolenaar5c736222010-01-06 20:54:52 +01002436 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002437 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002438" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002439 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002440 unlet b:netrw_fname
2441 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002442 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 +01002443" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002444 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002445 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002446 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002447
Bram Moolenaar9964e462007-05-05 17:54:07 +00002448" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002449endfun
2450
2451" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002452" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002453fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002454" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002455
Bram Moolenaar5c736222010-01-06 20:54:52 +01002456 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002457 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002458 call s:NetrwOptionsSave("w:")
2459 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002460
Bram Moolenaar5c736222010-01-06 20:54:52 +01002461 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002462 let tmpfile= s:GetTempfile("")
2463 if tmpfile == ""
2464" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002465 return
2466 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002467
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002468 if a:0 == 0
2469 let ichoice = 0
2470 else
2471 let ichoice = 1
2472 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002473
Bram Moolenaar9964e462007-05-05 17:54:07 +00002474 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002475" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002476 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002477 " For binary writes, always write entire file.
2478 " (line numbers don't really make sense for that).
2479 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002480" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002481 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002482 elseif g:netrw_cygwin
2483 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002484 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002485" 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 +01002486 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002487 else
2488 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002489" 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 +01002490 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002491 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002492
Bram Moolenaar9964e462007-05-05 17:54:07 +00002493 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002494 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002495 " on the temporary file's name. Deletion of the temporary file during
2496 " cleanup then causes an error message.
2497 0file!
2498 endif
2499
Bram Moolenaar5c736222010-01-06 20:54:52 +01002500 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002501 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002502
Bram Moolenaar9964e462007-05-05 17:54:07 +00002503 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002504 " attempt to repeat with previous host-file-etc
2505 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002506" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002507 let choice = b:netrw_lastfile
2508 let ichoice= ichoice + 1
2509 else
2510 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002511
Bram Moolenaar8d043172014-01-23 14:24:41 +01002512 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002513 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002514 echomsg 'NetWrite Usage:"'
2515 echomsg ':Nwrite machine:path uses rcp'
2516 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2517 echomsg ':Nwrite "machine id password path" uses ftp'
2518 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2519 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2520 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2521 echomsg ':Nwrite rcp://machine/path uses rcp'
2522 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2523 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2524 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002525 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002526 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002527
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002528 elseif match(choice,"^\"") != -1
2529 if match(choice,"\"$") != -1
2530 " case "..."
2531 let choice=strpart(choice,1,strlen(choice)-2)
2532 else
2533 " case "... ... ..."
2534 let choice = strpart(choice,1,strlen(choice)-1)
2535 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002536
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002537 while match(choice,"\"$") == -1
2538 let wholechoice= wholechoice . " " . choice
2539 let ichoice = ichoice + 1
2540 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002541 if !exists("g:netrw_quiet")
2542 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2543 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002544" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002545 return
2546 endif
2547 let choice= a:{ichoice}
2548 endwhile
2549 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2550 endif
2551 endif
2552 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002553 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002554" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002555
Bram Moolenaar9964e462007-05-05 17:54:07 +00002556 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002557 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002558 if !exists("b:netrw_method") || b:netrw_method < 0
2559" call Dfunc("netrw#NetWrite : unsupported method")
2560 return
2561 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002562
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002563 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002564 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002565 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002566 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2567 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002568" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002569 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002570
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002571 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002572 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002573 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002574" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002575 if s:netrw_has_nt_rcp == 1
2576 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2577 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2578 else
2579 let uid_machine = g:netrw_machine .'.'. $USERNAME
2580 endif
2581 else
2582 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2583 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2584 else
2585 let uid_machine = g:netrw_machine
2586 endif
2587 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002588 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 +00002589 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002590
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002591 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002592 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002593 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002594" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002595 let netrw_fname = b:netrw_fname
2596
2597 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2598 let bhkeep = &l:bh
2599 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002600 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002601 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002602
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002603" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002604 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002605 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002607 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002608 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002610 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002611 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002612" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002614 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 +00002615 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002616" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2617 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 endif
2619 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2620 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002621 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002622 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002623 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002624 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002626
2627 " remove enew buffer (quietly)
2628 let filtbuf= bufnr("%")
2629 exe curbuf."b!"
2630 let &l:bh = bhkeep
2631 exe filtbuf."bw!"
2632
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002634
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002635 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002636 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002637 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002638 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002639" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002640 let netrw_fname = b:netrw_fname
2641 let bhkeep = &l:bh
2642
2643 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2644 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002645 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002646 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002647 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002648
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002649 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002650 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002651" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002652 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002653 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002654" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002655 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002656 if exists("g:netrw_uid") && g:netrw_uid != ""
2657 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002658 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002659" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002660 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002661 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002662 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002663" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002664 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002665 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002666" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002667 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002668 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002669 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002670" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002671 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002672 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002673" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002674 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002675 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002676" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002677 " save choice/id/password for future use
2678 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002679
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002680 " perform ftp:
2681 " -i : turns off interactive prompting from ftp
2682 " -n unix : DON'T use <.netrc>, even though it exists
2683 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002684 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002685 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002686 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2687 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002688 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002689 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002690 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002691 let mod=1
2692 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002693
2694 " remove enew buffer (quietly)
2695 let filtbuf= bufnr("%")
2696 exe curbuf."b!"
2697 let &l:bh= bhkeep
2698 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002699
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002700 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002701 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002702 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002703" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002704 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002705 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002706 else
2707 let useport= ""
2708 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002709 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 +00002710 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002711
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002712 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002713 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002714 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002715" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002716 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2717 if executable(curl)
2718 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002719 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 +01002720 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002721 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002722 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002723
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002724 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002725 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002726 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002727" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002728
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002729 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002730 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2731 let bhkeep = &l:bh
2732
2733 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2734 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002735 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002736 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002737
Bram Moolenaarff034192013-04-24 18:51:19 +02002738 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002739 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002740 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002741 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002742 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002743 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002744 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002745 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002746 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002747 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002748
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002749 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002750 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002751 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002752
2753 " remove enew buffer (quietly)
2754 let filtbuf= bufnr("%")
2755 exe curbuf."b!"
2756 let &l:bh = bhkeep
2757 exe filtbuf."bw!"
2758
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002759 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002760
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002761 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002762 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002763 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002764" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002765 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 +00002766 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002767
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002768 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002769 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002770 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002771" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002772 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002773 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2774 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2775 else
2776 let uid_machine = g:netrw_machine
2777 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002778
2779 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2780 let bhkeep = &l:bh
2781 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002782 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002783 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002784
Bram Moolenaarff034192013-04-24 18:51:19 +02002785 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002786 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002787" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002788 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002789 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002790 let filtbuf= bufnr("%")
2791 exe curbuf."b!"
2792 let &l:bh = bhkeep
2793 exe filtbuf."bw!"
2794 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002795
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002796 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002797 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002798 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002799 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002800 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002802 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002803
Bram Moolenaar5c736222010-01-06 20:54:52 +01002804 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002805" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002806 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002807" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002808 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002809 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002810 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002811
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002812 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002813 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002814 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002815" 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 +02002816 elseif !exists("leavemod")
2817 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002818" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002819 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002820" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002822
Bram Moolenaar9964e462007-05-05 17:54:07 +00002823" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002824endfun
2825
2826" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002827" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002828" uses NetRead to get a copy of the file into a temporarily file,
2829" then sources that file,
2830" then removes that file.
2831fun! netrw#NetSource(...)
2832" call Dfunc("netrw#NetSource() a:0=".a:0)
2833 if a:0 > 0 && a:1 == '?'
2834 " give help
2835 echomsg 'NetSource Usage:'
2836 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2837 echomsg ':Nsource fetch://machine/path uses fetch'
2838 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002839 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002840 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2841 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2842 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2843 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2844 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002845 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002846 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002847 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002848 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002849" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002850 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002851" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002852 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002853" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002854 if delete(s:netrw_tmpfile)
2855 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2856 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002857 unlet s:netrw_tmpfile
2858 else
2859 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2860 endif
2861 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002862 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002863 endif
2864" call Dret("netrw#NetSource")
2865endfun
2866
Bram Moolenaar8d043172014-01-23 14:24:41 +01002867" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002868" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2869" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002870fun! netrw#SetTreetop(iscmd,...)
2871" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2872" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002873
Bram Moolenaar85850f32019-07-19 22:05:51 +02002874 " iscmd==0: netrw#SetTreetop called using gn mapping
2875 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2876" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002877 " clear out the current tree
2878 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002879" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002880 let inittreetop= w:netrw_treetop
2881 unlet w:netrw_treetop
2882 endif
2883 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002884" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002885 unlet w:netrw_treedict
2886 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002887" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002888
Bram Moolenaar85850f32019-07-19 22:05:51 +02002889 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002890 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002891" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002892 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002893 if isdirectory(s:NetrwFile(a:1))
2894" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002895 let treedir = a:1
2896 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002897 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002898 let treedir = b:netrw_curdir."/".a:1
2899 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002900" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002901 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002902 " normally the cursor is left in the message window.
2903 " However, here this results in the directory being listed in the message window, which is not wanted.
2904 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002905 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002906 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002907 let treedir = "."
2908 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002909 endif
2910 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002911" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002912
2913 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002914 let islocal= expand("%") !~ '^\a\{3,}://'
2915" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002916
2917 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002918 if islocal
2919 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2920 else
2921 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2922 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002923
Bram Moolenaara6878372014-03-22 21:02:50 +01002924" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002925endfun
2926
Bram Moolenaar9964e462007-05-05 17:54:07 +00002927" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002928" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002929" readcmd == %r : replace buffer with newly read file
2930" == 0r : read file at top of buffer
2931" == r : read file after current line
2932" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002933fun! s:NetrwGetFile(readcmd, tfile, method)
2934" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002935
2936 " readcmd=='t': simply do nothing
2937 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002938" 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 +01002939" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002940 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002941 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002942
Bram Moolenaar9964e462007-05-05 17:54:07 +00002943 " get name of remote filename (ie. url and all)
2944 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002945" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002946
Bram Moolenaar9964e462007-05-05 17:54:07 +00002947 if exists("*NetReadFixup")
2948 " for the use of NetReadFixup (not otherwise used internally)
2949 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002950 endif
2951
Bram Moolenaar9964e462007-05-05 17:54:07 +00002952 if a:readcmd[0] == '%'
2953 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002954" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955
2956 " rename the current buffer to the temp file (ie. tfile)
2957 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002958 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002959 else
2960 let tfile= a:tfile
2961 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002962 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002963
2964 " edit temporary file (ie. read the temporary file in)
2965 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002966" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002967 call zip#Browse(tfile)
2968 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002969" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002970 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002971 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002972" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002973 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002974 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002975" call Decho("handling remote bz2-compressed tar file",'~'.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\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002978" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002979 call tar#Browse(tfile)
2980 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002981" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002982 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002983 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002984" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002985 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002986 endif
2987
2988 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002989 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002990
Bram Moolenaar71badf92023-04-22 22:40:14 +01002991 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002992 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002993 " Note that isk must not include a "/" for scripts.vim
2994 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002995" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2996" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002997" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002998" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2999 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003000 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003001 filetype detect
3002" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003003 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003004" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003005 let line1 = 1
3006 let line2 = line("$")
3007
Bram Moolenaar8d043172014-01-23 14:24:41 +01003008 elseif !&ma
3009 " 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 +01003010 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003011" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003012 return
3013
Bram Moolenaar9964e462007-05-05 17:54:07 +00003014 elseif s:FileReadable(a:tfile)
3015 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003016" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003017 let curline = line(".")
3018 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003019" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003020 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003021 let line1= curline + 1
3022 let line2= line("$") - lastline + 1
3023
3024 else
3025 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003026" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3027" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003028 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003029" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003030 return
3031 endif
3032
3033 " User-provided (ie. optional) fix-it-up command
3034 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003035" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003036 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003037" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003038" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003039 endif
3040
Bram Moolenaaradc21822011-04-01 18:03:16 +02003041 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003042 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003043 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003044 endif
3045
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003046" 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 +00003047
3048 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003049" redraw!
3050
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003051" 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 +00003052" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003053endfun
3054
Bram Moolenaar9964e462007-05-05 17:54:07 +00003055" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003056" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003057" Input:
3058" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3059" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003060" b:netrw_method= 1: rcp
3061" 2: ftp + <.netrc>
3062" 3: ftp + machine, id, password, and [path]filename
3063" 4: scp
3064" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003065" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003066" 7: rsync
3067" 8: fetch
3068" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003069" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003070" g:netrw_machine= hostname
3071" b:netrw_fname = filename
3072" g:netrw_port = optional port number (for ftp)
3073" g:netrw_choice = copy of input url (choice)
3074fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003075" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003076
Bram Moolenaar251e1912011-06-19 05:09:16 +02003077 " sanity check: choice should have at least three slashes in it
3078 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3079 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3080 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003081" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003082 return
3083 endif
3084
Bram Moolenaar5c736222010-01-06 20:54:52 +01003085 " record current g:netrw_machine, if any
3086 " curmachine used if protocol == ftp and no .netrc
3087 if exists("g:netrw_machine")
3088 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003089" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003090 else
3091 let curmachine= "N O T A HOST"
3092 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003093 if exists("g:netrw_port")
3094 let netrw_port= g:netrw_port
3095 endif
3096
3097 " insure that netrw_ftp_cmd starts off every method determination
3098 " with the current g:netrw_ftp_cmd
3099 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003100
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003101 " initialization
3102 let b:netrw_method = 0
3103 let g:netrw_machine = ""
3104 let b:netrw_fname = ""
3105 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003106 let g:netrw_choice = a:choice
3107
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003108 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003109 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003110 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3111 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003112 " rcpurm : rcp://[user@]host/filename Use rcp
3113 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003114 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003115 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003116 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003117 " rsyncurm : rsync://host[:port]/path Use rsync
3118 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3119 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003120 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003121 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3122 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003123 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3124 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003125 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003126 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003127 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003128 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003129 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003130 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003131 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003132 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003133
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003134" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003135 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003136 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003137 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003138" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003139 let b:netrw_method = 1
3140 let userid = substitute(a:choice,rcpurm,'\1',"")
3141 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3142 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003143 if userid != ""
3144 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003146
Bram Moolenaaradc21822011-04-01 18:03:16 +02003147 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003148 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003149" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003150 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003151 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3152 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3153 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003154
Bram Moolenaar15146672011-10-20 22:22:38 +02003155 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003156 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003157" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003158 let b:netrw_method = 5
3159 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3160 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003161 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003162
Bram Moolenaaradc21822011-04-01 18:03:16 +02003163 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003164 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003165" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003166 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003167 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003168 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3169 else
3170 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3171 endif
3172 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003173
Bram Moolenaaradc21822011-04-01 18:03:16 +02003174 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003175 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003176" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003177 let b:netrw_method = 7
3178 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3179 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003180
Bram Moolenaaradc21822011-04-01 18:03:16 +02003181 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003182 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003183" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003184 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003185 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3186 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3187 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003188" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003189 if userid != ""
3190 let g:netrw_uid= userid
3191 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003192
Bram Moolenaaradc21822011-04-01 18:03:16 +02003193 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003194 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003195 call NetUserPass("ftp:".g:netrw_machine)
3196 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003197 " if there's a change in hostname, require password re-entry
3198 unlet s:netrw_passwd
3199 endif
3200 if exists("netrw_port")
3201 unlet netrw_port
3202 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003203 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003204
Bram Moolenaar446cb832008-06-24 21:56:24 +00003205 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003206 let b:netrw_method = 3
3207 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003208 let host= substitute(g:netrw_machine,'\..*$','','')
3209 if exists("s:netrw_hup[host]")
3210 call NetUserPass("ftp:".host)
3211
Nir Lichtman1e34b952024-05-08 19:19:34 +02003212 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003213" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3214" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003215 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003216 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003217" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003218 endif
3219 let b:netrw_method= 2
3220 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003221" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003222 let b:netrw_method= 2
3223 else
3224 if !exists("g:netrw_uid") || g:netrw_uid == ""
3225 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003226 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003227 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003228 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003229 endif
3230 let b:netrw_method= 3
3231 endif
3232 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003233
Bram Moolenaaradc21822011-04-01 18:03:16 +02003234 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003235 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003236" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003237 let b:netrw_method = 8
3238 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3239 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3240 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3241 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003242
Bram Moolenaaradc21822011-04-01 18:03:16 +02003243 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003244 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003245" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003247 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3248 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003249 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003250 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003251 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003252
Bram Moolenaaradc21822011-04-01 18:03:16 +02003253 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003254 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003255" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003256 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003257 let b:netrw_method = 3
3258 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3259 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003260
Bram Moolenaar9964e462007-05-05 17:54:07 +00003261 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003262 let b:netrw_method = 2
3263 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3264 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3265 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003266
Bram Moolenaaradc21822011-04-01 18:03:16 +02003267 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003268 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003269" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003270 let b:netrw_method = 9
3271 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3272 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003273
Bram Moolenaaradc21822011-04-01 18:03:16 +02003274 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003275 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003276" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003277 let b:netrw_method = 1
3278 let userid = substitute(a:choice,rcphf,'\2',"")
3279 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3280 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003281" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3282" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3283" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3284" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003285 if userid != ""
3286 let g:netrw_uid= userid
3287 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003288
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003289 " Method#10: file://user@hostname/...path-to-file {{{3
3290 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003291" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003292 let b:netrw_method = 10
3293 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003294" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003295
Bram Moolenaaradc21822011-04-01 18:03:16 +02003296 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003297 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003298 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003299 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003300 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003301 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003303 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003304
Bram Moolenaar81695252004-12-29 20:58:21 +00003305 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003306 " remove any leading [:#] from port number
3307 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3308 elseif exists("netrw_port")
3309 " retain port number as implicit for subsequent ftp operations
3310 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003311 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003312
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003313" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3314" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3315" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3316" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003317" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003318" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003319" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003320" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003321" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003322" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003323" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003324" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326
Bram Moolenaar9964e462007-05-05 17:54:07 +00003327" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003328" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003329" Usage: :call NetUserPass() -- will prompt for userid and password
3330" :call NetUserPass("uid") -- will prompt for password
3331" :call NetUserPass("uid","password") -- sets global userid and password
3332" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3333" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334fun! NetUserPass(...)
3335
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003336" call Dfunc("NetUserPass() a:0=".a:0)
3337
3338 if !exists('s:netrw_hup')
3339 let s:netrw_hup= {}
3340 endif
3341
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003343 " case: no input arguments
3344
3345 " change host and username if not previously entered; get new password
3346 if !exists("g:netrw_machine")
3347 let g:netrw_machine= input('Enter hostname: ')
3348 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003349 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003350 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351 let g:netrw_uid= input('Enter username: ')
3352 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003353 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003354 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003355
3356 " set up hup database
3357 let host = substitute(g:netrw_machine,'\..*$','','')
3358 if !exists('s:netrw_hup[host]')
3359 let s:netrw_hup[host]= {}
3360 endif
3361 let s:netrw_hup[host].uid = g:netrw_uid
3362 let s:netrw_hup[host].passwd = s:netrw_passwd
3363
3364 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003365 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003366
3367 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003368 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003369 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003370" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003371 let host = substitute(a:1,'^ftp:','','')
3372 let host = substitute(host,'\..*','','')
3373 if exists("s:netrw_hup[host]")
3374 let g:netrw_uid = s:netrw_hup[host].uid
3375 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003376" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3377" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003378 else
3379 let g:netrw_uid = input("Enter UserId: ")
3380 let s:netrw_passwd = inputsecret("Enter Password: ")
3381 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003382
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003383 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003384 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003385" 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 +02003386 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003387 if g:netrw_machine =~ '[0-9.]\+'
3388 let host= g:netrw_machine
3389 else
3390 let host= substitute(g:netrw_machine,'\..*$','','')
3391 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003392 else
3393 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003394 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003395 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003396" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003397 if exists("g:netrw_passwd")
3398 " ask for password if one not previously entered
3399 let s:netrw_passwd= g:netrw_passwd
3400 else
3401 let s:netrw_passwd = inputsecret("Enter Password: ")
3402 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003403 endif
3404
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003405" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003406 if exists("host")
3407 if !exists('s:netrw_hup[host]')
3408 let s:netrw_hup[host]= {}
3409 endif
3410 let s:netrw_hup[host].uid = g:netrw_uid
3411 let s:netrw_hup[host].passwd = s:netrw_passwd
3412 endif
3413
3414 elseif a:0 == 2
3415 let g:netrw_uid = a:1
3416 let s:netrw_passwd = a:2
3417
3418 elseif a:0 == 3
3419 " enter hostname, user-id, and password into the hup dictionary
3420 let host = substitute(a:1,'^\a\+:','','')
3421 let host = substitute(host,'\..*$','','')
3422 if !exists('s:netrw_hup[host]')
3423 let s:netrw_hup[host]= {}
3424 endif
3425 let s:netrw_hup[host].uid = a:2
3426 let s:netrw_hup[host].passwd = a:3
3427 let g:netrw_uid = s:netrw_hup[host].uid
3428 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003429" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3430" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003432
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003433" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003434endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435
Bram Moolenaar85850f32019-07-19 22:05:51 +02003436" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003437" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003438" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003440" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003441" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3442fun! s:ExplorePatHls(pattern)
3443" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3444 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003445" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003446 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003447" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003448 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3449" call Dret("s:ExplorePatHls repat<".repat.">")
3450 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003451endfun
3452
3453" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003454" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003455" 0: (user: <mb>) bookmark current directory
3456" 1: (user: <gb>) change to the bookmarked directory
3457" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003458" 3: (browsing) records current directory history
3459" 4: (user: <u>) go up (previous) directory, using history
3460" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003461" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003462fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003463" 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 +02003464 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3465" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3466 return
3467 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003468
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003469 let ykeep = @@
3470 let curbufnr = bufnr("%")
3471
Bram Moolenaar9964e462007-05-05 17:54:07 +00003472 if a:chg == 0
3473 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003474" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003475 if exists("s:netrwmarkfilelist_{curbufnr}")
3476 call s:NetrwBookmark(0)
3477 echo "bookmarked marked files"
3478 else
3479 call s:MakeBookmark(a:curdir)
3480 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003481 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003482
KSR-Yasudaf4498252023-10-06 03:34:17 +09003483 try
3484 call s:NetrwBookHistSave()
3485 catch
3486 endtry
3487
Bram Moolenaar9964e462007-05-05 17:54:07 +00003488 elseif a:chg == 1
3489 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003490" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003491 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003492" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003493 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003494 else
3495 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3496 endif
3497
3498 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003499" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003500 let didwork= 0
3501 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003502" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003503 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003504" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003505 let cnt= 1
3506 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003507" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003508 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003509 let didwork = 1
3510 let cnt = cnt + 1
3511 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003512 endif
3513
3514 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003515 " Note: history is saved only when PerformListing is done;
3516 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3517 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003518 let first = 1
3519 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003520 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003521 while ( first || cnt != g:netrw_dirhistcnt )
3522" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003523 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003524" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003525 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003526 let didwork= 1
3527 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003528 let histcnt = histcnt + 1
3529 let first = 0
3530 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003531 if cnt < 0
3532 let cnt= cnt + g:netrw_dirhistmax
3533 endif
3534 endwhile
3535 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003536 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003537 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003538 if didwork
3539 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3540 endif
3541
3542 elseif a:chg == 3
3543 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003544" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003545 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 +02003546 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003547 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3548 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003549 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003550" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003551 endif
3552
3553 elseif a:chg == 4
3554 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003555" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003556 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003557 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3558 if g:netrw_dirhistcnt < 0
3559 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003560 endif
3561 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003562 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003563 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003564 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3565" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003566 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003567 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003568" call Decho("setl ma noro",'~'.expand("<slnum>"))
3569 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003570 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003571" call Decho("setl nomod",'~'.expand("<slnum>"))
3572" 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 +00003573 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003574" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3575 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003576 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003577 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003578 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003579 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003580 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003581 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003582 echo "Sorry, no predecessor directory exists yet"
3583 endif
3584
3585 elseif a:chg == 5
3586 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003587" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003588 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003589 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3590 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3591" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003592 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003593" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003594 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003595 sil! NetrwKeepj %d _
3596" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3597" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003598 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003599" 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 +02003600 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003601" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3602 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003603 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003604 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3605 if g:netrw_dirhistcnt < 0
3606 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003607 endif
3608 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003609 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003610 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003611 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003612 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003613 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003614
3615 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003616" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003617 if exists("s:netrwmarkfilelist_{curbufnr}")
3618 call s:NetrwBookmark(1)
3619 echo "removed marked files from bookmarks"
3620 else
3621 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003622 let iremove = v:count
3623 let dremove = g:netrw_bookmarklist[iremove - 1]
3624" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003625 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003626" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3627 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3628 echo "removed ".dremove." from g:netrw_bookmarklist"
3629" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003630 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003631" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003632
3633 try
3634 call s:NetrwBookHistSave()
3635 catch
3636 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003637 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003638 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003639 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003640 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003641" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003642endfun
3643
3644" ---------------------------------------------------------------------
3645" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003646" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003647" Sister function: s:NetrwBookHistSave()
3648fun! s:NetrwBookHistRead()
3649" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003650 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003651" 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 +02003652 return
3653 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003654 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003655
3656 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003657 if !exists("s:netrw_initbookhist")
3658 let home = s:NetrwHome()
3659 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003660 if filereadable(s:NetrwFile(savefile))
3661" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003662 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003663 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003664
3665 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003666 if g:netrw_dirhistmax > 0
3667 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003668 if filereadable(s:NetrwFile(savefile))
3669" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003670 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003671 endif
3672 let s:netrw_initbookhist= 1
3673 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003674 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003675 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003676
Bram Moolenaar97d62492012-11-15 21:28:22 +01003677 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003678" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3679" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003680" call Dret("s:NetrwBookHistRead")
3681endfun
3682
3683" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003684" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003685" Sister function: s:NetrwBookHistRead()
3686" I used to do this via viminfo but that appears to
3687" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003688" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3689" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003690" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003691fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003692" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003693 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003694" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003695 return
3696 endif
3697
Bram Moolenaar5c736222010-01-06 20:54:52 +01003698 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003699" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003700 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003701
3702 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003703 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003704" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003705 if g:netrw_use_noswf
3706 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3707 else
3708 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3709 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003710 setl nocin noai noci magic nospell nohid wig= noaw
3711 setl ma noro write
3712 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003713 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003714
Bram Moolenaar85850f32019-07-19 22:05:51 +02003715 " rename enew'd file: .netrwhist -- no attempt to merge
3716 " record dirhistmax and current dirhistcnt
3717 " save history
3718" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003719 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003720 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003721 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3722 if g:netrw_dirhistmax > 0
3723 let lastline = line("$")
3724 let cnt = g:netrw_dirhistcnt
3725 let first = 1
3726 while ( first || cnt != g:netrw_dirhistcnt )
3727 let lastline= lastline + 1
3728 if exists("g:netrw_dirhist_{cnt}")
3729 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3730" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3731 endif
3732 let first = 0
3733 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3734 if cnt < 0
3735 let cnt= cnt + g:netrw_dirhistmax
3736 endif
3737 endwhile
3738 exe "sil! w! ".savefile
3739" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3740 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003741
Bram Moolenaar85850f32019-07-19 22:05:51 +02003742 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003743 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003744 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003745" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003746 " merge and write .netrwbook
3747 let savefile= s:NetrwHome()."/.netrwbook"
3748
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003749 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003750 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003751 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003752 for bdm in booklist
3753 if index(g:netrw_bookmarklist,bdm) == -1
3754 call add(g:netrw_bookmarklist,bdm)
3755 endif
3756 endfor
3757 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003758 endif
3759
3760 " construct and save .netrwbook
3761 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003762 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003763" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003764 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003765
3766 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003767 let bgone= bufnr("%")
3768 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003769 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003770
3771" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003772endfun
3773
3774" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003775" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3776" list of the contents of a local or remote directory. It is assumed that the
3777" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3778" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003779" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003780fun! s:NetrwBrowse(islocal,dirname)
3781 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003782" 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 +02003783" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3784" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3785" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003786
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003787 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3788 " This is useful when one edits a local file, then :e ., then :Rex
3789 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3790 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003791" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003792 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003793
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003794 " s:NetrwBrowse : initialize history {{{3
3795 if !exists("s:netrw_initbookhist")
3796 NetrwKeepj call s:NetrwBookHistRead()
3797 endif
3798
3799 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003800 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003801 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003802" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003803 else
3804 let dirname= a:dirname
3805 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003806
Bram Moolenaar85850f32019-07-19 22:05:51 +02003807 " repoint t:netrw_lexbufnr if appropriate
3808 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3809" call Decho("set repointlexbufnr to true!")
3810 let repointlexbufnr= 1
3811 endif
3812
3813 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003814 if exists("s:netrw_skipbrowse")
3815 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003816" 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 +01003817" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003818 return
3819 endif
3820 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003821 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003822" call Dret("s:NetrwBrowse : missing shellescape()")
3823 return
3824 endif
3825 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003826 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003827" call Dret("s:NetrwBrowse : missing fnameescape()")
3828 return
3829 endif
3830
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003831 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003832 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003833
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003834 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003835 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3836 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3837" call Decho("clearing marked files",'~'.expand("<slnum>"))
3838 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3839 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003840 endif
3841
3842 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003843 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003844" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3845" 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 +02003846 if s:NetrwLcd(dirname)
3847" call Dret("s:NetrwBrowse : lcd failure")
3848 return
3849 endif
3850 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003851" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003852
Bram Moolenaar5c736222010-01-06 20:54:52 +01003853 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003854 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003855" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003856 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003857" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003858 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003859 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003860 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003861" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003862
3863 " remove any filetype indicator from end of dirname, except for the
3864 " "this is a directory" indicator (/).
3865 " There shouldn't be one of those here, anyway.
3866 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003867" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003868 call s:RemotePathAnalysis(dirname)
3869
3870 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3871 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003872 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003873 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003874" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003875 let b:netrw_curdir = dirname
3876 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003877 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003878 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3879 sil call netrw#NetRead(2,url)
3880 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003881" call Decho("url<".url.">",'~'.expand("<slnum>"))
3882" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3883" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003884 if s:path =~ '.bz2'
3885 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3886 elseif s:path =~ '.gz'
3887 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3888 elseif s:path =~ '.gz'
3889 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3890 else
3891 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3892 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003893 endif
3894
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003895 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003896 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003897 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003898" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003899 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003900" 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 +00003901
Bram Moolenaar446cb832008-06-24 21:56:24 +00003902" call Dret("s:NetrwBrowse : file<".s:fname.">")
3903 return
3904 endif
3905
Bram Moolenaaradc21822011-04-01 18:03:16 +02003906 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003907 call s:UseBufWinVars()
3908
3909 " set up some variables {{{3
3910 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003911 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003912 let s:last_sort_by = g:netrw_sort_by
3913
3914 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003915 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003916
Bram Moolenaar97d62492012-11-15 21:28:22 +01003917 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003918" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003919 let svpos = winsaveview()
3920" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003921 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003922
Bram Moolenaar446cb832008-06-24 21:56:24 +00003923 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003924 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3925 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3926" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3927" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3928 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3929 else
3930" " call Decho("2match none",'~'.expand("<slnum>"))
3931 2match none
3932 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003933 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003934 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003935 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003936" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003937 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003938" 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 +01003939" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003940 return
3941 endif
3942
3943 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003945 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003946 if b:netrw_curdir =~ '[/\\]$'
3947 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3948 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003949 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003950 let b:netrw_curdir= b:netrw_curdir."/"
3951 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003952 if b:netrw_curdir == ''
3953 if has("amiga")
3954 " On the Amiga, the empty string connotes the current directory
3955 let b:netrw_curdir= getcwd()
3956 else
3957 " under unix, when the root directory is encountered, the result
3958 " from the preceding substitute is an empty string.
3959 let b:netrw_curdir= '/'
3960 endif
3961 endif
3962 if !a:islocal && b:netrw_curdir !~ '/$'
3963 let b:netrw_curdir= b:netrw_curdir.'/'
3964 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003965" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003966
3967 " ------------
3968 " (local only) {{{3
3969 " ------------
3970 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003971" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003972
3973 " Set up ShellCmdPost handling. Append current buffer to browselist
3974 call s:LocalFastBrowser()
3975
3976 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3977 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003978" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3979" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003980 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003981 if s:NetrwLcd(b:netrw_curdir)
3982" call Dret("s:NetrwBrowse : lcd failure")
3983 return
3984 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003985 endif
3986 endif
3987
3988 " --------------------------------
3989 " remote handling: {{{3
3990 " --------------------------------
3991 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003992" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003993
Bram Moolenaar97d62492012-11-15 21:28:22 +01003994 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003995" 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 +02003996 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003997 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003998" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003999 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4000 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4001 if dirname !~ '/$'
4002 let dirname= dirname.'/'
4003 endif
4004 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004005" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004006 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004007 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004008" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004009 endif
4010
4011 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4012 if dirname !~ dirpat
4013 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004014 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004015 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004016 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004017" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004018 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004019" 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 +00004020" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4021 return
4022 endif
4023 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004024" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004025 endif " (additional remote handling)
4026
Bram Moolenaar85850f32019-07-19 22:05:51 +02004027 " -------------------------------
4028 " Perform Directory Listing: {{{3
4029 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004030 NetrwKeepj call s:NetrwMaps(a:islocal)
4031 NetrwKeepj call s:NetrwCommands(a:islocal)
4032 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004033
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004034 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004035 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004036" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4037
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004038 " If there is a rexposn: restore position with rexposn
4039 " Otherwise : set rexposn
4040 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004041" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4042 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4043 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4044 NetrwKeepj exe w:netrw_bannercnt
4045 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004046 else
4047 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4048 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004049 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004050 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004051" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004052 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004053 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004054
Bram Moolenaar85850f32019-07-19 22:05:51 +02004055 " repoint t:netrw_lexbufnr if appropriate
4056 if exists("repointlexbufnr")
4057 let t:netrw_lexbufnr= bufnr("%")
4058" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4059 endif
4060
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004061 " restore position
4062 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004063" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4064 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004065 endif
4066
Bram Moolenaara6878372014-03-22 21:02:50 +01004067 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004068 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4069 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004070" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4071" 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 +02004072" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004073 return
4074endfun
4075
4076" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004077" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4078" may not apply correctly; ie. netrw's idea of the current directory may
4079" differ from vim's. This function insures that netrw's idea of the current
4080" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004081" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004082fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004083" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4084" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4085" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4086" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4087" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004088
4089 " clean up any leading treedepthstring
4090 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4091 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004092" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004093 else
4094 let fname= a:fname
4095 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004096
4097 if g:netrw_keepdir
4098 " vim's idea of the current directory possibly may differ from netrw's
4099 if !exists("b:netrw_curdir")
4100 let b:netrw_curdir= getcwd()
4101 endif
4102
Nir Lichtman1e34b952024-05-08 19:19:34 +02004103 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004104 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004105 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004106 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004107" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004108 else
4109 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004110 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004111" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004112 endif
4113
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004114 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004115 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004116 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004117" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004118 else
4119 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004120 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004121" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004122 endif
4123 else
4124 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004125 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004126" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4127" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4128" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004129 endif
4130
Bram Moolenaar85850f32019-07-19 22:05:51 +02004131" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004132 return ret
4133endfun
4134
4135" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004136" s:NetrwFileInfo: supports qf (query for file information) {{{2
4137fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004138" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004139 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004140 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004141 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004142 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004143 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004144 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004145 let lsopt= "-lsadh --si"
4146 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004147" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004148 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004149
4150 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004151 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004152" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004153
Bram Moolenaara6878372014-03-22 21:02:50 +01004154 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004155 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004156" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004157
4158 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004159 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004160" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004161
Bram Moolenaar446cb832008-06-24 21:56:24 +00004162 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004163" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004164 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004165" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004166 endif
4167 else
4168 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004169" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4170 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004171 let fname= substitute(a:fname,".$","","")
4172 else
4173 let fname= a:fname
4174 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004175 let t = getftime(s:NetrwFile(fname))
4176 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004177 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004178 let sz= s:NetrwHumanReadable(sz)
4179 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004180 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4181" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004182 endif
4183 else
4184 echo "sorry, \"qf\" not supported yet for remote files"
4185 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004186 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004187" call Dret("s:NetrwFileInfo")
4188endfun
4189
4190" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004191" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4192fun! s:NetrwFullPath(filename)
4193" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4194 let filename= a:filename
4195 if filename !~ '^/'
4196 let filename= resolve(getcwd().'/'.filename)
4197 endif
4198 if filename != "/" && filename =~ '/$'
4199 let filename= substitute(filename,'/$','','')
4200 endif
4201" " call Dret("s:NetrwFullPath <".filename.">")
4202 return filename
4203endfun
4204
4205" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004206" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004207" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004208" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004209" 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 +00004210fun! s:NetrwGetBuffer(islocal,dirname)
4211" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004212" 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 +02004213" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4214" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004215 let dirname= a:dirname
4216
4217 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004218" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004219 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004220" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004221 let s:netrwbuf= {}
4222 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004223" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4224" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4225
4226 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4227 let bufnum = -1
4228
4229 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4230 if has_key(s:netrwbuf,"NetrwTreeListing")
4231 let bufnum= s:netrwbuf["NetrwTreeListing"]
4232 else
4233 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4234 endif
4235" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4236 if !bufexists(bufnum)
4237 call remove(s:netrwbuf,"NetrwTreeListing"])
4238 let bufnum= -1
4239 endif
4240 elseif bufnr("NetrwTreeListing") != -1
4241 let bufnum= bufnr("NetrwTreeListing")
4242" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4243 else
4244" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4245 let bufnum= -1
4246 endif
4247
4248 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004249 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004250" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004251 if !bufexists(bufnum)
4252 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4253 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004254 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004255
Bram Moolenaar446cb832008-06-24 21:56:24 +00004256 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004257" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004258 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004259 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004260" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4261
Bram Moolenaar71badf92023-04-22 22:40:14 +01004262 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004263 " IF the buffer already has the desired name
4264 " AND it is empty
4265 let curbuf = bufname("%")
4266 if curbuf == '.'
4267 let curbuf = getcwd()
4268 endif
4269" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004270" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004271" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4272" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4273" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4274" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4275 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004276" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4277 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004278 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004279" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004280 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004281 " 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 +00004282
4283 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004284 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004285" 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 +00004286 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004287" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004288 " name the buffer
4289 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4290 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004291" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004292 let w:netrw_treebufnr = bufnr("%")
4293 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004294 if g:netrw_use_noswf
4295 setl nobl bt=nofile noswf
4296 else
4297 setl nobl bt=nofile
4298 endif
4299 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4300 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4301 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4302 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004303" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004304 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004305 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004306 " enter the new buffer into the s:netrwbuf dictionary
4307 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4308" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4309" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004310 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004311" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004312
4313 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004314" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004315 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004316 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004317 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004318
4319 if &ft == "netrw"
4320" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4321 exe "sil! NetrwKeepj noswapfile b ".bufnum
4322" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004323 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004324" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4325 call s:NetrwEditBuf(bufnum)
4326" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004327 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004328" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004329 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004330 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004331 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004332
4333 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004334 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004335
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004336 if line("$") <= 1 && getline(1) == ""
4337 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004338 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004339" 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>"))
4340" 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 +01004341" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4342 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004343
Bram Moolenaar97d62492012-11-15 21:28:22 +01004344 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004345" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004346 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004347 sil NetrwKeepj %d _
4348" 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>"))
4349" 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 +01004350" 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 +00004351 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004352
Bram Moolenaar446cb832008-06-24 21:56:24 +00004353 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004354" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4355" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004356 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004357 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004358 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004359" 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>"))
4360" 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 +01004361" 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 +00004362 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004363
Bram Moolenaar446cb832008-06-24 21:56:24 +00004364 else
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>"))
4367" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004368 return 1
4369 endif
4370 endif
4371
4372 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4373 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4374 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4375 " med 1 D H
4376 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004377" 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 +00004378 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004379 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004380 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004381
4382 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004383" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4384" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4385 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004386
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004387" 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>"))
4388" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4389" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004390 return 0
4391endfun
4392
4393" ---------------------------------------------------------------------
4394" s:NetrwGetcwd: get the current directory. {{{2
4395" Change backslashes to forward slashes, if any.
4396" If doesc is true, escape certain troublesome characters
4397fun! s:NetrwGetcwd(doesc)
4398" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4399 let curdir= substitute(getcwd(),'\\','/','ge')
4400 if curdir !~ '[\/]$'
4401 let curdir= curdir.'/'
4402 endif
4403 if a:doesc
4404 let curdir= fnameescape(curdir)
4405 endif
4406" call Dret("NetrwGetcwd <".curdir.">")
4407 return curdir
4408endfun
4409
4410" ---------------------------------------------------------------------
4411" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4412fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004413" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4414" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4415 let keepsol= &l:sol
4416 setl nosol
4417
Bram Moolenaar446cb832008-06-24 21:56:24 +00004418 call s:UseBufWinVars()
4419
4420 " insure that w:netrw_liststyle is set up
4421 if !exists("w:netrw_liststyle")
4422 if exists("g:netrw_liststyle")
4423 let w:netrw_liststyle= g:netrw_liststyle
4424 else
4425 let w:netrw_liststyle= s:THINLIST
4426 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004427" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004428 endif
4429
4430 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4431 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004432" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004433 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004434 let dirname= "./"
4435 let curline= getline('.')
4436
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004437 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004438 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004439 let s:netrw_skipbrowse= 1
4440 echo 'Pressing "s" also works'
4441
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004442 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004443 let s:netrw_skipbrowse= 1
4444 echo 'Press "S" to edit sorting sequence'
4445
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004446 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004447 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004448 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004449
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004450 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004451 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004452 let s:netrw_skipbrowse= 1
4453 echo 'Pressing "a" also works'
4454
4455 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004456 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004457 endif
4458
4459 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004460" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004461 NetrwKeepj norm! 0
4462 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004463
4464 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004465" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004466 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004467 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4468
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004469 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004470" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004471 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004472 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004473
4474 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004475" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004476 let dirname= getline('.')
4477
4478 if !exists("b:netrw_cpf")
4479 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004480 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 +01004481 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004482" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004483 endif
4484
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004485" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004486 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004487" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4488" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004490 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004491 else
4492 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004493 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004494 endif
4495 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004496 let eofname= filestart + b:netrw_cpf + 1
4497 if eofname <= col("$")
4498 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004499 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004500 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004501 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004502 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004503 let dirname = @a
4504 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004505" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004506 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004507" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508 endif
4509
4510 " symlinks are indicated by a trailing "@". Remove it before further processing.
4511 let dirname= substitute(dirname,"@$","","")
4512
4513 " executables are indicated by a trailing "*". Remove it before further processing.
4514 let dirname= substitute(dirname,"\*$","","")
4515
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004516 let &l:sol= keepsol
4517
Bram Moolenaar446cb832008-06-24 21:56:24 +00004518" call Dret("s:NetrwGetWord <".dirname.">")
4519 return dirname
4520endfun
4521
4522" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004523" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4524" g:netrw_bufsettings will be used after the listing is produced.
4525" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004526fun! s:NetrwListSettings(islocal)
4527" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004528" 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 +00004529 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004530" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4531 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4532 setl bt=nofile nobl ma nonu nowrap noro nornu
4533 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004534 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004535 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004536 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004537" call Dredir("ls!","s:NetrwListSettings")
4538" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004539 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004540 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004541 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004542 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004543 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004544 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004545 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004546" 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 +00004547" call Dret("s:NetrwListSettings")
4548endfun
4549
4550" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004551" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004552" islocal=0: remote browsing
4553" =1: local browsing
4554fun! s:NetrwListStyle(islocal)
4555" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004556
Bram Moolenaar97d62492012-11-15 21:28:22 +01004557 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004558 let fname = s:NetrwGetWord()
4559 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004560 let svpos = winsaveview()
4561" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004562 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004563" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4564" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4565" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004566
Bram Moolenaar85850f32019-07-19 22:05:51 +02004567 " repoint t:netrw_lexbufnr if appropriate
4568 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4569" call Decho("set repointlexbufnr to true!")
4570 let repointlexbufnr= 1
4571 endif
4572
Bram Moolenaar446cb832008-06-24 21:56:24 +00004573 if w:netrw_liststyle == s:THINLIST
4574 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004575" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004576 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4577
4578 elseif w:netrw_liststyle == s:LONGLIST
4579 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004580" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004581 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4582
4583 elseif w:netrw_liststyle == s:WIDELIST
4584 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004585" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004586 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4587
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004588 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004589" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004590 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4591
4592 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004593 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004594 let g:netrw_liststyle = s:THINLIST
4595 let w:netrw_liststyle = g:netrw_liststyle
4596 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4597 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004598 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004599" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004600
4601 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004602" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4603 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004604 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004605" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004606 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004607" 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 +00004608
4609 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004610" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004611 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004612 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004613
Bram Moolenaar85850f32019-07-19 22:05:51 +02004614 " repoint t:netrw_lexbufnr if appropriate
4615 if exists("repointlexbufnr")
4616 let t:netrw_lexbufnr= bufnr("%")
4617" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4618 endif
4619
Bram Moolenaar13600302014-05-22 18:26:40 +02004620 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004621" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4622 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004623 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004624
4625" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4626endfun
4627
4628" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004629" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4630fun! s:NetrwBannerCtrl(islocal)
4631" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4632
Bram Moolenaar97d62492012-11-15 21:28:22 +01004633 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004634 " toggle the banner (enable/suppress)
4635 let g:netrw_banner= !g:netrw_banner
4636
4637 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004638 let svpos= winsaveview()
4639" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004640 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4641
4642 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004643 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4644 let fname= s:NetrwGetWord()
4645 sil NetrwKeepj $
4646 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4647" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4648 if result <= 0 && exists("w:netrw_bannercnt")
4649 exe "NetrwKeepj ".w:netrw_bannercnt
4650 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004651 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004652 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004653" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4654endfun
4655
4656" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004657" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4658"
4659" No bang: enters files/directories into Netrw's bookmark system
4660" No argument and in netrw buffer:
4661" if there are marked files: bookmark marked files
4662" otherwise : bookmark file/directory under cursor
4663" No argument and not in netrw buffer: bookmarks current open file
4664" Has arguments: globs them individually and bookmarks them
4665"
4666" With bang: deletes files/directories from Netrw's bookmark system
4667fun! s:NetrwBookmark(del,...)
4668" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4669 if a:0 == 0
4670 if &ft == "netrw"
4671 let curbufnr = bufnr("%")
4672
4673 if exists("s:netrwmarkfilelist_{curbufnr}")
4674 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004675" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004676 let svpos = winsaveview()
4677" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004678 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004679 for fname in s:netrwmarkfilelist_{curbufnr}
4680 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4681 endfor
4682 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4683 call s:NetrwUnmarkList(curbufnr,curdir)
4684 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004685" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4686 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004687 else
4688 let fname= s:NetrwGetWord()
4689 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4690 endif
4691
4692 else
4693 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004694" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004695 let fname= expand("%")
4696 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4697 endif
4698
4699 else
4700 " bookmark specified files
4701 " attempts to infer if working remote or local
4702 " by deciding if the current file begins with an url
4703 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004704 let islocal= expand("%") !~ '^\a\{3,}://'
4705" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004706 let i = 1
4707 while i <= a:0
4708 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004709 if v:version > 704 || (v:version == 704 && has("patch656"))
4710 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004711 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004712 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004713 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004714 else
4715 let mbfiles= [a:{i}]
4716 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004717" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004718 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004719" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004720 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4721 endfor
4722 let i= i + 1
4723 endwhile
4724 endif
4725
4726 " update the menu
4727 call s:NetrwBookmarkMenu()
4728
4729" call Dret("s:NetrwBookmark")
4730endfun
4731
4732" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004733" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4734" .2.[cnt] for bookmarks, and
4735" .3.[cnt] for history
4736" (see s:NetrwMenu())
4737fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004738 if !exists("s:netrw_menucnt")
4739 return
4740 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004741" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004742
4743 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004744 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004745 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004746" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004747 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4748 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004749 endif
4750 if !exists("s:netrw_initbookhist")
4751 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004752 endif
4753
4754 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004755 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004756 let cnt= 1
4757 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004758" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004759 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004760
4761 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004762 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004763
4764 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004765 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 +01004766 let cnt= cnt + 1
4767 endfor
4768
4769 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004770
4771 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004772 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004773 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004774 let first = 1
4775 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004776 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004777 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004778 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004779 if exists("g:netrw_dirhist_{cnt}")
4780 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004781" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004782 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4783 endif
4784 let first = 0
4785 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4786 if cnt < 0
4787 let cnt= cnt + g:netrw_dirhistmax
4788 endif
4789 endwhile
4790 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004791
Bram Moolenaar9964e462007-05-05 17:54:07 +00004792 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004793" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004794endfun
4795
4796" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004797" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4798" directory and a new directory name. Also, if the
4799" "new directory name" is actually a file,
4800" NetrwBrowseChgDir() edits the file.
4801fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004802" 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 +01004803" 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 +00004804
Bram Moolenaar97d62492012-11-15 21:28:22 +01004805 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004806 if !exists("b:netrw_curdir")
4807 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4808 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004809 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004810" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4811" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004812" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004813" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004814 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004815 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004816" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004817
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004818 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004819" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004820 call s:SavePosn(s:netrw_posn)
4821 NetrwKeepj call s:NetrwOptionsSave("s:")
4822 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004823 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004824 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004825 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004826 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004827 endif
4828 let newdir = a:newdir
4829 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004830 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004831" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004832" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004833" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004834
4835 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004836" 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 +01004837 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004838" 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 +01004839 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004840 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004841" 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 +01004842 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004843" 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 +02004844 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004845 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004846 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004847 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004848" 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 +01004849 endif
4850 endif
4851" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004852" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004853 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004854
Bram Moolenaar446cb832008-06-24 21:56:24 +00004855 " set up o/s-dependent directory recognition pattern
4856 if has("amiga")
4857 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004858 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004859 let dirpat= '[\/]$'
4860 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004861" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004862
4863 if dirname !~ dirpat
4864 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004865 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004866 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004867" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004868 endif
4869
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004870" 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 +01004871 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004872 " ------------------------------
4873 " NetrwBrowseChgDir: edit a file {{{3
4874 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004875" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004876
Bram Moolenaar97d62492012-11-15 21:28:22 +01004877 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004878 let s:rexposn_{bufnr("%")}= winsaveview()
4879" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004880" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4881" 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 +01004882
Bram Moolenaar446cb832008-06-24 21:56:24 +00004883 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004884" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4885" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004886" let newdir = s:NetrwTreePath(s:netrw_treetop)
4887" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004888 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004889 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4890" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4891 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004892 if dirname =~ '/$'
4893 let dirname= dirname.newdir
4894 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004895 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004896 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004897" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4898" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004899 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004900" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004902 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004904 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004905" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004906 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004907 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004908" 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 +02004909 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004910 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004911 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004912" " 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 +01004913 if type(g:netrw_browse_split) == 3
4914 " open file in server
4915 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004916" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004917 call s:NetrwServerEdit(a:islocal,dirname)
4918" call Dret("s:NetrwBrowseChgDir")
4919 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004920
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004921 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004922 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004923" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004924 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4925 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004926 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004927 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004928 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004929 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004930
Bram Moolenaar446cb832008-06-24 21:56:24 +00004931 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004932 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004933" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004934 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4935 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004936 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004937 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004938 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004939 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004940
Bram Moolenaar446cb832008-06-24 21:56:24 +00004941 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004942 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004943" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004944 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004945 if !exists("b:netrw_curdir")
4946 let b:netrw_curdir= getcwd()
4947 endif
4948 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004949
Bram Moolenaar446cb832008-06-24 21:56:24 +00004950 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004951 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004952" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004953 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004954 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004955" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004956 return
4957 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004958 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004959
Bram Moolenaar9964e462007-05-05 17:54:07 +00004960 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004961 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004962" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004963 call s:NetrwMenu(0)
4964 " optional change to window
4965 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004966" 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 +02004967 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004968 " if g:netrw_chgwin is set to one more than the last window, then
4969 " vertically split the last window to make that window available.
4970 let curwin= winnr()
4971 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4972 vs
4973 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004974 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004975 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004976 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004977 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004978 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004979
Bram Moolenaar9964e462007-05-05 17:54:07 +00004980 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004981
Bram Moolenaar446cb832008-06-24 21:56:24 +00004982 " the point where netrw actually edits the (local) file
4983 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004984 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004985 if !&mod
4986 " if e the new file would fail due to &mod, then don't change any of the flags
4987 let dolockout= 1
4988 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004989 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004990" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004991 " some like c-^ to return to the last edited file
4992 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004993 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4994 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004995 call s:NetrwEditFile("e","",dirname)
4996" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004997 " COMBAK -- cuc cul related
4998 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004999 if &hidden || &bufhidden == "hide"
5000 " file came from vim's hidden storage. Don't "restore" options with it.
5001 let dorestore= 0
5002 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005003 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005004" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005005 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005006
5007 " handle g:Netrw_funcref -- call external-to-netrw functions
5008 " This code will handle g:Netrw_funcref as an individual function reference
5009 " or as a list of function references. It will ignore anything that's not
5010 " a function reference. See :help Funcref for information about function references.
5011 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005012" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005013 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005014" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005015 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005016 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005017" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005018 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005019 if type(Fncref) == 2
5020 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005021 endif
5022 endfor
5023 endif
5024 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005025 endif
5026
5027 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005028 " ----------------------------------------------------
5029 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5030 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005031" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005032 let dirname = newdir
5033 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005034 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005035 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005036
5037 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005038 " ---------------------------------------------
5039 " NetrwBrowseChgDir: refresh the directory list {{{3
5040 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005041" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005042 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005043 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005044
5045 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005046 " --------------------------------------
5047 " NetrwBrowseChgDir: go up one directory {{{3
5048 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005049" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005050
5051 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5052 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005053" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5054" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005055 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005056 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005057 endif
5058
5059 if has("amiga")
5060 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005061" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005062 if a:islocal
5063 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5064 let dirname= substitute(dirname,'/$','','')
5065 else
5066 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5067 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005068" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005069
Nir Lichtman1e34b952024-05-08 19:19:34 +02005070 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005071 " windows
5072 if a:islocal
5073 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5074 if dirname == ""
5075 let dirname= '/'
5076 endif
5077 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005078 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005079 endif
5080 if dirname =~ '^\a:$'
5081 let dirname= dirname.'/'
5082 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005083" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005084
Bram Moolenaar446cb832008-06-24 21:56:24 +00005085 else
5086 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005087" 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 +00005088 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 Moolenaar446cb832008-06-24 21:56:24 +00005095 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005096" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005097 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005098 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005099 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005100
5101 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005102 " --------------------------------------
5103 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5104 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005105" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005106 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5107" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005108 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005109 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005110" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5111 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005112 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005113 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005114" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005115 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005116 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005117" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005118
5119 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005120" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005121 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005122" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005123 let haskey= 1
5124 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005125" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005126 endif
5127
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005128 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005129" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005130 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005131 if has_key(w:netrw_treedict,treedir."/")
5132 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005133" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005134 let haskey = 1
5135 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005136" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005137 endif
5138 endif
5139
5140 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005141" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005142 if !haskey && treedir =~ '/$'
5143 let treedir= substitute(treedir,'/$','','')
5144 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005145" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005146 let haskey = 1
5147 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005148" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005149 endif
5150 endif
5151
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005152" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005153 if haskey
5154 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005155" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005156 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005157" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5158" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005159 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005160 else
5161 " go down one directory
5162 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005163" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5164" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005165 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005166 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005167" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005168 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005169
5170 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005171 " ----------------------------------------
5172 " NetrwBrowseChgDir: Go down one directory {{{3
5173 " ----------------------------------------
5174 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005175" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005176 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005177 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005178 endif
5179
Bram Moolenaar97d62492012-11-15 21:28:22 +01005180 " --------------------------------------
5181 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5182 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005183 if dorestore
5184 " dorestore is zero'd when a local file was hidden or bufhidden;
5185 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005186" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005187 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005188" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005189" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005190 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005191 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005192" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005193 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005194" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5195" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005196 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005197" 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 +02005198 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005199" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5200" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005201 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005202" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005203 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005204 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005205 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005206 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005207
Bram Moolenaar446cb832008-06-24 21:56:24 +00005208" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5209 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005210endfun
5211
5212" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005213" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5214" for thin, long, and wide: cursor placed just after banner
5215" for tree, keeps cursor on current filename
5216fun! s:NetrwBrowseUpDir(islocal)
5217" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005218 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5219 " this test needed because occasionally this function seems to be incorrectly called
5220 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005221 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005222 " directories.
5223" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5224 return
5225 endif
5226
Bram Moolenaara6878372014-03-22 21:02:50 +01005227 norm! 0
5228 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005229" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005230 let curline= getline(".")
5231 let swwline= winline() - 1
5232 if exists("w:netrw_treetop")
5233 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005234 elseif exists("b:netrw_curdir")
5235 let w:netrw_treetop= b:netrw_curdir
5236 else
5237 let w:netrw_treetop= getcwd()
5238 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005239 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005240 let curfile = getline(".")
5241 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005242 if a:islocal
5243 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5244 else
5245 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5246 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005247" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5248" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5249 if w:netrw_treetop == '/'
5250 keepj call search('^\M'.curfile,"w")
5251 elseif curfile == '../'
5252 keepj call search('^\M'.curfile,"wb")
5253 else
5254" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5255 while 1
5256 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5257 let treepath= s:NetrwTreePath(w:netrw_treetop)
5258" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5259 if treepath == curpath
5260 break
5261 endif
5262 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005263 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005264
Bram Moolenaara6878372014-03-22 21:02:50 +01005265 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005266" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005267 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005268 if exists("b:netrw_curdir")
5269 let curdir= b:netrw_curdir
5270 else
5271 let curdir= expand(getcwd())
5272 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005273 if a:islocal
5274 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5275 else
5276 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5277 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005278 call s:RestorePosn(s:netrw_posn)
5279 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005280 let curdir= '\<'. escape(curdir, '~'). '/'
5281 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005282 endif
5283" call Dret("s:NetrwBrowseUpDir")
5284endfun
5285
5286" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005287" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005288" given filename; typically this means given their extension.
5289" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005290fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005291 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005292" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005293
Bram Moolenaar91359012019-11-30 17:57:03 +01005294 if a:remote == 0 && isdirectory(a:fname)
5295 " if its really just a local directory, then do a "gf" instead
5296" 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 +01005297" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5298 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005299" call Dret("netrw#BrowseX")
5300 return
5301 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5302 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5303" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5304" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5305" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5306" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5307 norm! gf
5308" call Dret("netrw#BrowseX")
5309 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005310 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005311" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005312
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005313 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5314 let remote = a:remote
5315 else
5316 let remote = 0
5317 endif
5318
Bram Moolenaar97d62492012-11-15 21:28:22 +01005319 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005320 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005321" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005322
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005323 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5324 let awkeep = &aw
5325 set noaw
5326
Bram Moolenaar5c736222010-01-06 20:54:52 +01005327 " special core dump handler
5328 if a:fname =~ '/core\(\.\d\+\)\=$'
5329 if exists("g:Netrw_corehandler")
5330 if type(g:Netrw_corehandler) == 2
5331 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005332" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005333 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005334 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005335 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005336" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005337 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005338 if type(Fncref) == 2
5339 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005340 endif
5341 endfor
5342 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005343" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005344 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005345 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005346 let &aw= awkeep
5347" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005348 return
5349 endif
5350 endif
5351
Bram Moolenaar446cb832008-06-24 21:56:24 +00005352 " set up the filename
5353 " (lower case the extension, make a local copy of a remote file)
5354 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005355 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005356 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005357 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005358 if exten =~ "[\\/]"
5359 let exten= ""
5360 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005361" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005362
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005363 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005364 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005365" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005366 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005367 call netrw#NetRead(3,a:fname)
5368 " attempt to rename tempfile
5369 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005370 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005371" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5372" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005373 if s:netrw_tmpfile != newname && newname != ""
5374 if rename(s:netrw_tmpfile,newname) == 0
5375 " renaming succeeded
5376" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5377 let fname= newname
5378 else
5379 " renaming failed
5380" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5381 let fname= s:netrw_tmpfile
5382 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005383 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005384 let fname= s:netrw_tmpfile
5385 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005386 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005387" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005388 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005389 " special ~ handler for local
5390 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005391" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5392 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005393 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005394 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005395" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5396" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005397
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005398 " set up redirection (avoids browser messages)
5399 " by default, g:netrw_suppress_gx_mesg is true
5400 if g:netrw_suppress_gx_mesg
5401 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005402 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005403 let redir= substitute(&srr,"%s","nul","")
5404 else
5405 let redir= substitute(&srr,"%s","/dev/null","")
5406 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005407 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005408 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005409 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005410 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005411 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005412 else
5413 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005414 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005415" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005416
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005417 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005418 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005419" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005420 if g:netrw_browsex_viewer =~ '\s'
5421 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5422 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5423 let oviewer = ''
5424 let cnt = 1
5425 while !executable(viewer) && viewer != oviewer
5426 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5427 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5428 let cnt = cnt + 1
5429 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005430" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005431 endwhile
5432 else
5433 let viewer = g:netrw_browsex_viewer
5434 let viewopt = ""
5435 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005436" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005437 endif
5438
5439 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005440" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005441 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005442" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005443 let ret= netrwFileHandlers#Invoke(exten,fname)
5444
5445 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005446" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005447 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005448 let ret= v:shell_error
5449
Nir Lichtman1e34b952024-05-08 19:19:34 +02005450 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005451" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005452 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005453 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005454 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005455 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005456 else
5457 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5458 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005459 let ret= v:shell_error
5460
Bram Moolenaar97d62492012-11-15 21:28:22 +01005461 elseif has("win32unix")
5462 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005463" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005464 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005465" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005466 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005467 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005468" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005469 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005470 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005471" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005472 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005473 else
5474 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5475 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005476 let ret= v:shell_error
5477
Bram Moolenaar85850f32019-07-19 22:05:51 +02005478 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005479" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5480 if a:fname =~ '^https\=://'
5481 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5482 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005483" call Decho("fname<".fname.">")
5484" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005485 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5486
5487 else
5488 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5489 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005490 let ret= v:shell_error
5491
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005492 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5493" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5494 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5495 let ret= v:shell_error
5496
5497 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5498" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5499 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5500 let ret= v:shell_error
5501
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005502 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005503" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005504 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005505 let ret= v:shell_error
5506
5507 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005508" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005509 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005510 let ret= v:shell_error
5511
5512 else
5513 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005514" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005515 let ret= netrwFileHandlers#Invoke(exten,fname)
5516 endif
5517
5518 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5519 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005520" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005521 let ret= netrwFileHandlers#Invoke(exten,fname)
5522 endif
5523
Bram Moolenaarc236c162008-07-13 17:41:49 +00005524 " restoring redraw! after external file handlers
5525 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005526
5527 " cleanup: remove temporary file,
5528 " delete current buffer if success with handler,
5529 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005530 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005531 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005532" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005533"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005534" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005535" endif
5536
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005537 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005538 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005539 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005540 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005541 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005542 if use_ctrlo
5543 exe "sil! NetrwKeepj norm! \<c-o>"
5544 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005545 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005546" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005547 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005548 let @@ = ykeep
5549 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005550
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005551" call Dret("netrw#BrowseX")
5552endfun
5553
5554" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005555" netrw#GX: gets word under cursor for gx support {{{2
5556" See also: netrw#BrowseXVis
5557" netrw#BrowseX
5558fun! netrw#GX()
5559" call Dfunc("netrw#GX()")
5560 if &ft == "netrw"
5561 let fname= s:NetrwGetWord()
5562 else
5563 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5564 endif
5565" call Dret("netrw#GX <".fname.">")
5566 return fname
5567endfun
5568
5569" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005570" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5571fun! netrw#BrowseXVis()
5572" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005573 let akeep = @a
5574 norm! gv"ay
5575 let gxfile= @a
5576 let @a = akeep
5577 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005578" call Dret("netrw#BrowseXVis")
5579endfun
5580
5581" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005582" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5583" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5584" to become an unlisted buffer, so in that case don't bwipe it.
5585fun! s:NetrwBufRename(newname)
5586" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5587" call Dredir("ls!","s:NetrwBufRename (before rename)")
5588 let oldbufname= bufname(bufnr("%"))
5589" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5590
5591 if oldbufname != a:newname
5592" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5593 let b:junk= 1
5594" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5595 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005596" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005597 let oldbufnr= bufnr(oldbufname)
5598" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5599" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5600 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5601" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5602 exe "bwipe! ".oldbufnr
5603" else " Decho
5604" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005605" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5606" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5607" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005608 endif
5609" call Dredir("ls!","s:NetrwBufRename (after rename)")
5610" else " Decho
5611" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5612 endif
5613
5614" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5615endfun
5616
5617" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005618" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005619fun! netrw#CheckIfRemote(...)
5620" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5621 if a:0 > 0
5622 let curfile= a:1
5623 else
5624 let curfile= expand("%")
5625 endif
5626" call Decho("curfile<".curfile.">")
5627 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005628" call Dret("netrw#CheckIfRemote 1")
5629 return 1
5630 else
5631" call Dret("netrw#CheckIfRemote 0")
5632 return 0
5633 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005634endfun
5635
5636" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005637" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5638fun! s:NetrwChgPerm(islocal,curdir)
5639" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005640 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005641 call inputsave()
5642 let newperm= input("Enter new permission: ")
5643 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005644 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5645 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5646" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005647 call system(chgperm)
5648 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005649 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005650 endif
5651 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005652 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005653 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005654 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005655" call Dret("s:NetrwChgPerm")
5656endfun
5657
5658" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005659" s:CheckIfKde: checks if kdeinit is running {{{2
5660" Returns 0: kdeinit not running
5661" 1: kdeinit is running
5662fun! s:CheckIfKde()
5663" call Dfunc("s:CheckIfKde()")
5664 " seems kde systems often have gnome-open due to dependencies, even though
5665 " gnome-open's subsidiary display tools are largely absent. Kde systems
5666 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5667 if !exists("s:haskdeinit")
5668 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005669 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005670 if v:shell_error
5671 let s:haskdeinit = 0
5672 endif
5673 else
5674 let s:haskdeinit= 0
5675 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005676" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005677 endif
5678
5679" call Dret("s:CheckIfKde ".s:haskdeinit)
5680 return s:haskdeinit
5681endfun
5682
5683" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005684" s:NetrwClearExplore: clear explore variables (if any) {{{2
5685fun! s:NetrwClearExplore()
5686" call Dfunc("s:NetrwClearExplore()")
5687 2match none
5688 if exists("s:explore_match") |unlet s:explore_match |endif
5689 if exists("s:explore_indx") |unlet s:explore_indx |endif
5690 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5691 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5692 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5693 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5694 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5695 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5696 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5697" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005698" call Dret("s:NetrwClearExplore")
5699endfun
5700
5701" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005702" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5703fun! s:NetrwEditBuf(bufnum)
5704" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5705 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5706" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5707 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5708 else
5709" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005710 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005711 endif
5712" call Dret("s:NetrwEditBuf")
5713endfun
5714
5715" ---------------------------------------------------------------------
5716" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5717" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5718fun! s:NetrwEditFile(cmd,opt,fname)
5719" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5720 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5721" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5722 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5723 else
5724" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5725 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5726 endif
5727" call Dret("s:NetrwEditFile")
5728endfun
5729
5730" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005731" s:NetrwExploreListUniq: {{{2
5732fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005733" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005734
5735 " this assumes that the list is already sorted
5736 let newexplist= []
5737 for member in a:explist
5738 if !exists("uniqmember") || member != uniqmember
5739 let uniqmember = member
5740 let newexplist = newexplist + [ member ]
5741 endif
5742 endfor
5743
Bram Moolenaar15146672011-10-20 22:22:38 +02005744" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005745 return newexplist
5746endfun
5747
5748" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005749" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5750fun! s:NetrwForceChgDir(islocal,newdir)
5751" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005752 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005753 if a:newdir !~ '/$'
5754 " ok, looks like force is needed to get directory-style treatment
5755 if a:newdir =~ '@$'
5756 let newdir= substitute(a:newdir,'@$','/','')
5757 elseif a:newdir =~ '[*=|\\]$'
5758 let newdir= substitute(a:newdir,'.$','/','')
5759 else
5760 let newdir= a:newdir.'/'
5761 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005762" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005763 else
5764 " should already be getting treatment as a directory
5765 let newdir= a:newdir
5766 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005767 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005768 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005769 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005770" call Dret("s:NetrwForceChgDir")
5771endfun
5772
5773" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005774" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005775" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5776" expr : this is the expression to follow the directory. Will use s:ComposePath()
5777" pare =1: remove the current directory from the resulting glob() filelist
5778" =0: leave the current directory in the resulting glob() filelist
5779fun! s:NetrwGlob(direntry,expr,pare)
5780" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005781 if netrw#CheckIfRemote()
5782 keepalt 1sp
5783 keepalt enew
5784 let keep_liststyle = w:netrw_liststyle
5785 let w:netrw_liststyle = s:THINLIST
5786 if s:NetrwRemoteListing() == 0
5787 keepj keepalt %s@/@@
5788 let filelist= getline(1,$)
5789 q!
5790 else
5791 " remote listing error -- leave treedict unchanged
5792 let filelist= w:netrw_treedict[a:direntry]
5793 endif
5794 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005795 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5796 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5797 if a:pare
5798 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5799 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005800 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005801 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5802 if a:pare
5803 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5804 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005805 endif
5806" call Dret("s:NetrwGlob ".string(filelist))
5807 return filelist
5808endfun
5809
5810" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005811" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5812fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005813" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005814 if a:newfile =~ '[/@*=|\\]$'
5815 let newfile= substitute(a:newfile,'.$','','')
5816 else
5817 let newfile= a:newfile
5818 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005819 if a:islocal
5820 call s:NetrwBrowseChgDir(a:islocal,newfile)
5821 else
5822 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5823 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005824" call Dret("s:NetrwForceFile")
5825endfun
5826
5827" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005828" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5829" and switches the hiding mode. The actual hiding is done by
5830" s:NetrwListHide().
5831" g:netrw_hide= 0: show all
5832" 1: show not-hidden files
5833" 2: show hidden files only
5834fun! s:NetrwHide(islocal)
5835" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005836 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005837 let svpos= winsaveview()
5838" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005839
5840 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005841" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5842" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005843
5844 " hide the files in the markfile list
5845 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005846" 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 +00005847 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5848 " remove fname from hiding list
5849 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5850 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5851 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005852" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005853 else
5854 " append fname to hiding list
5855 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5856 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5857 else
5858 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5859 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005860" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005861 endif
5862 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005863 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005864 let g:netrw_hide= 1
5865
5866 else
5867
5868 " switch between show-all/show-not-hidden/show-hidden
5869 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005870 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005871 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005872 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005873 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005874" call Dret("NetrwHide")
5875 return
5876 endif
5877 endif
5878
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005879 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005880" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5881 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005882 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005883" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005884endfun
5885
5886" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005887" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5888fun! s:NetrwHideEdit(islocal)
5889" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5890
5891 let ykeep= @@
5892 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005893 let svpos= winsaveview()
5894" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005895
5896 " get new hiding list from user
5897 call inputsave()
5898 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5899 call inputrestore()
5900 let g:netrw_list_hide= newhide
5901" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5902
5903 " refresh the listing
5904 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5905
5906 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005907" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5908 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005909 let @@= ykeep
5910
5911" call Dret("NetrwHideEdit")
5912endfun
5913
5914" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005915" s:NetrwHidden: invoked by "gh" {{{2
5916fun! s:NetrwHidden(islocal)
5917" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005918 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005919 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005920 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005921" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005922
5923 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005924 " remove .file pattern from hiding list
5925" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005926 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005927 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005928" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005929 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5930 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005931" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005932 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5933 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005934 if g:netrw_list_hide =~ '^,'
5935 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5936 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005937
5938 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005939 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005940" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5941 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005942 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005943" call Dret("s:NetrwHidden")
5944endfun
5945
5946" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005947" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5948fun! s:NetrwHome()
5949 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005950 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005951 else
5952 " go to vim plugin home
5953 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005954 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005955 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005956 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005957 let home= basehome."/.vim"
5958 break
5959 endif
5960 endfor
5961 if home == ""
5962 " just pick the first directory
5963 let home= substitute(&rtp,',.*$','','')
5964 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005965 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005966 let home= substitute(home,'/','\\','g')
5967 endif
5968 endif
5969 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005970 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005971" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005972 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005973" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005974 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005975 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005976" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005977 call mkdir(home)
5978 endif
5979 endif
5980 let g:netrw_home= home
5981 return home
5982endfun
5983
5984" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005985" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5986fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005987 if exists("s:netrwdrag")
5988 return
5989 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005990 if &ft != "netrw"
5991 return
5992 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005993" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005994
Bram Moolenaar97d62492012-11-15 21:28:22 +01005995 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005996 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005997 while getchar(0) != 0
5998 "clear the input stream
5999 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006000 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006001 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006002 let mouse_lnum = v:mouse_lnum
6003 let wlastline = line('w$')
6004 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006005" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6006" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006007 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6008 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006009 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006010" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6011 return
6012 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006013 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006014 " 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 +01006015 " without this test when its disabled.
6016 " 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 +01006017" 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 +01006018 if v:mouse_col > virtcol('.')
6019 let @@= ykeep
6020" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6021 return
6022 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006023
Bram Moolenaar446cb832008-06-24 21:56:24 +00006024 if a:islocal
6025 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006026 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006027 endif
6028 else
6029 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006030 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006031 endif
6032 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006033 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006034" call Dret("s:NetrwLeftmouse")
6035endfun
6036
6037" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006038" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6039fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006040 if &ft != "netrw"
6041 return
6042 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006043" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6044 call s:NetrwMarkFileTgt(a:islocal)
6045" call Dret("s:NetrwCLeftmouse")
6046endfun
6047
6048" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006049" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6050" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006051" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006052" a:islocal=2 : <c-r> used, remote
6053" a:islocal=3 : <c-r> used, local
6054fun! s:NetrwServerEdit(islocal,fname)
6055" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6056 let islocal = a:islocal%2 " =0: remote =1: local
6057 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006058" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006059
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006060 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006061 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006062 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006063" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006064 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006065 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006066 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6067 unlet s:netrw_browse_split_{winnr()}
6068 endif
6069 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6070" call Dret("s:NetrwServerEdit")
6071 return
6072 endif
6073
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006074" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006075 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006076" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006077
6078 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006079" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006080 let srvrname = g:netrw_browse_split[0]
6081 let tabnum = g:netrw_browse_split[1]
6082 let winnum = g:netrw_browse_split[2]
6083
6084 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006085" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006086
6087 if !ctrlr
6088 " user must have closed the server window and the user did not use <c-r>, but
6089 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006090" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006091 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006092 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006093 endif
6094 let g:netrw_browse_split= 0
6095 if exists("s:netrw_browse_split_".winnr())
6096 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6097 endif
6098 call s:NetrwBrowseChgDir(islocal,a:fname)
6099" call Dret("s:NetrwServerEdit")
6100 return
6101
6102 elseif has("win32") && executable("start")
6103 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006104" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006105 call system("start gvim --servername ".srvrname)
6106
6107 else
6108 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006109" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006110 call system("gvim --servername ".srvrname)
6111 endif
6112 endif
6113
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006114" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006115 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6116 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006117 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006118
6119 else
6120
6121 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6122
6123 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006124" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006125 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006126 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006127 endif
6128 let g:netrw_browse_split= 0
6129 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6130" call Dret("s:NetrwServerEdit")
6131 return
6132
6133 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006134" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006135 if has("win32") && executable("start")
6136 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006137" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006138 call system("start gvim --servername ".g:netrw_servername)
6139 else
6140 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006141" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006142 call system("gvim --servername ".g:netrw_servername)
6143 endif
6144 endif
6145 endif
6146
6147 while 1
6148 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006149" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6150 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006151 break
6152 catch /^Vim\%((\a\+)\)\=:E241/
6153 sleep 200m
6154 endtry
6155 endwhile
6156
6157 if exists("g:netrw_browse_split")
6158 if type(g:netrw_browse_split) != 3
6159 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6160 endif
6161 unlet g:netrw_browse_split
6162 endif
6163 let g:netrw_browse_split= [g:netrw_servername,1,1]
6164 endif
6165
6166 else
6167 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6168 endif
6169
6170" call Dret("s:NetrwServerEdit")
6171endfun
6172
6173" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006174" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6175fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006176 if &ft != "netrw"
6177 return
6178 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006179" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006180
Bram Moolenaar8d043172014-01-23 14:24:41 +01006181 let s:ngw= s:NetrwGetWord()
6182 call s:NetrwMarkFile(a:islocal,s:ngw)
6183
6184" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006185endfun
6186
6187" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006188" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6189" Used to mark multiple files.
6190fun! s:NetrwSLeftdrag(islocal)
6191" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6192 if !exists("s:netrwdrag")
6193 let s:netrwdrag = winnr()
6194 if a:islocal
6195 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006196 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006197 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006198 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006199 endif
6200 let ngw = s:NetrwGetWord()
6201 if !exists("s:ngw") || s:ngw != ngw
6202 call s:NetrwMarkFile(a:islocal,ngw)
6203 endif
6204 let s:ngw= ngw
6205" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6206endfun
6207
6208" ---------------------------------------------------------------------
6209" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6210fun! s:NetrwSLeftrelease(islocal)
6211" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6212 if exists("s:netrwdrag")
6213 nunmap <s-leftrelease>
6214 let ngw = s:NetrwGetWord()
6215 if !exists("s:ngw") || s:ngw != ngw
6216 call s:NetrwMarkFile(a:islocal,ngw)
6217 endif
6218 if exists("s:ngw")
6219 unlet s:ngw
6220 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006221 unlet s:netrwdrag
6222 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006223" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006224endfun
6225
6226" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006227" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6228" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006229fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006230" 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 +02006231" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006232 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006233
6234 " 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 +02006235 " How-it-works: take the hiding command, convert it into a range.
6236 " Duplicate characters don't matter.
6237 " Remove all such characters from the '/~@#...890' string.
6238 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006239" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006240 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006241 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006242" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006243
6244 while listhide != ""
6245 if listhide =~ ','
6246 let hide = substitute(listhide,',.*$','','e')
6247 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6248 else
6249 let hide = listhide
6250 let listhide = ""
6251 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006252" 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 +01006253 if g:netrw_sort_by =~ '^[ts]'
6254 if hide =~ '^\^'
6255" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6256 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6257 elseif hide =~ '^\\(\^'
6258 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6259 endif
6260" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6261 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006262
6263 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006264" 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 +00006265 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006266" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006267 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006268 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006269" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006270 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006271 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006272" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006273 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006274
Bram Moolenaar446cb832008-06-24 21:56:24 +00006275 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006276 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006277" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006278 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006279" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006280 endif
6281
Bram Moolenaaradc21822011-04-01 18:03:16 +02006282 " remove any blank lines that have somehow remained.
6283 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006284 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006285
Bram Moolenaar97d62492012-11-15 21:28:22 +01006286 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006287" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006288endfun
6289
6290" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006291" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006292" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006293fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006294" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006295
Bram Moolenaar97d62492012-11-15 21:28:22 +01006296 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006297 " get name of new directory from user. A bare <CR> will skip.
6298 " if its currently a directory, also request will be skipped, but with
6299 " a message.
6300 call inputsave()
6301 let newdirname= input("Please give directory name: ")
6302 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006303" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006304
6305 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006306 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006307" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006308 return
6309 endif
6310
6311 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006312" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006313
6314 " Local mkdir:
6315 " sanity checks
6316 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006317" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6318 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006319 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006320 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006321 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006322 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006323" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006324 return
6325 endif
6326 if s:FileReadable(fullnewdir)
6327 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006328 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006329 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006330 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006331" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006332 return
6333 endif
6334
6335 " requested new local directory is neither a pre-existing file or
6336 " directory, so make it!
6337 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006338 if has("unix")
6339 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6340 else
6341 call mkdir(fullnewdir,"p")
6342 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006343 else
6344 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006345 if s:NetrwLcd(b:netrw_curdir)
6346" call Dret("s:NetrwMakeDir : lcd failure")
6347 return
6348 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006349" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006350 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006351 if v:shell_error != 0
6352 let @@= ykeep
6353 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 +01006354" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006355 return
6356 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006357 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006358" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006359 if s:NetrwLcd(netrw_origdir)
6360" call Dret("s:NetrwBrowse : lcd failure")
6361 return
6362 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006363 endif
6364 endif
6365
6366 if v:shell_error == 0
6367 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006368" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006369 let svpos= winsaveview()
6370" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006371 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006372" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6373 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006374 elseif !exists("g:netrw_quiet")
6375 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6376 endif
6377" redraw!
6378
6379 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006380 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006381" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006382 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6383 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006384 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006385 if v:shell_error == 0
6386 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006387 let svpos= winsaveview()
6388" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006389 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006390" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6391 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006392 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006393 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006394 endif
6395" redraw!
6396
6397 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006398 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006399 let svpos= winsaveview()
6400" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006401" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006402 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006403" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006404 let remotepath= b:netrw_fname
6405 else
6406 let remotepath= ""
6407 endif
6408 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006409 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006410" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6411 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006412
Bram Moolenaar446cb832008-06-24 21:56:24 +00006413 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006414 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006415 let svpos= winsaveview()
6416" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006417" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006418 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006419" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006420 let remotepath= b:netrw_fname
6421 else
6422 let remotepath= ""
6423 endif
6424 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006425 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006426" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6427 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006428 endif
6429
Bram Moolenaar97d62492012-11-15 21:28:22 +01006430 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006431" call Dret("s:NetrwMakeDir")
6432endfun
6433
6434" ---------------------------------------------------------------------
6435" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6436fun! s:TreeSqueezeDir(islocal)
6437" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6438 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6439 " its a tree-listing style
6440 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006441 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006442 let depth = strchars(substitute(curdepth,' ','','g'))
6443 let srch = -1
6444" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6445" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006446" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006447" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6448 if depth >= 2
6449 NetrwKeepj norm! 0
6450 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6451 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6452" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6453" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6454 elseif depth == 1
6455 NetrwKeepj norm! 0
6456 let treedepthchr= substitute(s:treedepthstring,' ','','')
6457 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6458" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6459 endif
6460 if srch > 0
6461" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6462 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6463 exe srch
6464 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006465 endif
6466" call Dret("s:TreeSqueezeDir")
6467endfun
6468
6469" ---------------------------------------------------------------------
6470" s:NetrwMaps: {{{2
6471fun! s:NetrwMaps(islocal)
6472" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6473
Bram Moolenaar85850f32019-07-19 22:05:51 +02006474 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006475 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006476" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006477 if !hasmapto("<Plug>NetrwReturn")
6478 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006479" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006480 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6481 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006482" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006483 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6484 endif
6485 endif
6486 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006487" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006488 endif
6489
Bram Moolenaar85850f32019-07-19 22:05:51 +02006490 " generate default <Plug> maps {{{3
6491 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006492 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006493 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6494 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6495 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6496 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6497 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6498 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6499 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6500 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6501 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6502 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6503" ---------------------------------------------------------------------
6504" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6505" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6506" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6507" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6508" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6509" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6510" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6511" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6512" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6513" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6514" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6515" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6516" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6517" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6518" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6519" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6520" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6521" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6522" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6523" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6524" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6525" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6526" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6527" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6528" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6529" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6530" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6531" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6532" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6533" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6534" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6535" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6536" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6537" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6538" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6539" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6540" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6541" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6542" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6543" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6544" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6545" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6546" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6547" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6548" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6549" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6550" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6551
Bram Moolenaara6878372014-03-22 21:02:50 +01006552 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006553" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006554 " local normal-mode maps {{{3
6555 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6556 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6557 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6558 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6559 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6560 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6561 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6562 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6563 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6564 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6565 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6566" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006567 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6568 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6569 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006570 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006571 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006572 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6573 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6574 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6575 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006576 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6577 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6578 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6579 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6580 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6581 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6582 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6583 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6584 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6585 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6586 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6587 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6588 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006589 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006590 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006591 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6592 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6593 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6594 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6595 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006596 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006597 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006598 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6599 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006600 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6601 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6602 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006603 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006604 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006605 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6606 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006607 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006608 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006609 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6610 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6611 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006612 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6613 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006614
6615 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 +01006616 if !hasmapto('<Plug>NetrwHideEdit')
6617 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006618 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006619 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006620 if !hasmapto('<Plug>NetrwRefresh')
6621 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006622 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006623 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 +01006624 if s:didstarstar || !mapcheck("<s-down>","n")
6625 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006626 endif
6627 if s:didstarstar || !mapcheck("<s-up>","n")
6628 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006629 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006630 if !hasmapto('<Plug>NetrwTreeSqueeze')
6631 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006632 endif
6633 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006634 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6635 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006636 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6637 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6638 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6639 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6640 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6641 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6642 imap <buffer> <leftmouse> <Plug>ILeftmouse
6643 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006644 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6645 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6646 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6647 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6648 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006649 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006650 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6651 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006652 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006653 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6654 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6655 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6656 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6657 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6658 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6659 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006660 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6661
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006662 " support user-specified maps
6663 call netrw#UserMaps(1)
6664
Bram Moolenaar85850f32019-07-19 22:05:51 +02006665 else
6666 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006667" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006668 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006669 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6670 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6671 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6672 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6673 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6674 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6675 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6676 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6677 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6678 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6679 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6680" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006681 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6682 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6683 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6684 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6685 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6686 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6687 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6688 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006689 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006690 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006691 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6692 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6693 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6694 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6695 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6696 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6697 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6698 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6699 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6700 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6701 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006702 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006703 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006704 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6705 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6706 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6707 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6708 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006709 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6710 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6711 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6712 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006713 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006714 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6715 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006716 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006717 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 +01006718 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6719 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6720 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6721 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6722 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6723 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6724 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6725 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6726 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006727 if !hasmapto('<Plug>NetrwHideEdit')
6728 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006729 endif
6730 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6731 if !hasmapto('<Plug>NetrwRefresh')
6732 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006733 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006734 if !hasmapto('<Plug>NetrwTreeSqueeze')
6735 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006736 endif
6737 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006738
6739 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006740 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006741
6742 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6743 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006744 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006745 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006746 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006747 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006748 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006749 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006750 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006751 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006752 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006753 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006754 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6755 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6756 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006757 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006758 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006759 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6760 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006761 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006762 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6763 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6764 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6765 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6766 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6767 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6768 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006769 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006770
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006771 " support user-specified maps
6772 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006773 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006774
6775" call Dret("s:NetrwMaps")
6776endfun
6777
6778" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006779" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006780" If -buffer, the command is only available from within netrw buffers
6781" Otherwise, the command is available from any window, so long as netrw
6782" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006783fun! s:NetrwCommands(islocal)
6784" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6785
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006786 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6787 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006788 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 +01006789 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006790 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006791 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006792 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006793 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006794 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006795
6796" call Dret("s:NetrwCommands")
6797endfun
6798
6799" ---------------------------------------------------------------------
6800" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6801" glob()ing only works with local files
6802fun! s:NetrwMarkFiles(islocal,...)
6803" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006804 let curdir = s:NetrwGetCurdir(a:islocal)
6805 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006806 while i <= a:0
6807 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006808 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006809 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006810 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006811 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006812 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006813 else
6814 let mffiles= [a:{i}]
6815 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006816" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006817 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006818" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006819 call s:NetrwMarkFile(a:islocal,mffile)
6820 endfor
6821 let i= i + 1
6822 endwhile
6823" call Dret("s:NetrwMarkFiles")
6824endfun
6825
6826" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006827" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006828fun! s:NetrwMarkTarget(...)
6829" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6830 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006831 let curdir = s:NetrwGetCurdir(1)
6832 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006833 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006834 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6835 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006836 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006837" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006838 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006839 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6840 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006841 let svpos = winsaveview()
6842" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006843 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006844" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6845 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006846" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006847endfun
6848
6849" ---------------------------------------------------------------------
6850" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6851" mark and unmark files. If a markfile list exists,
6852" then the rename and delete functions will use it instead
6853" of whatever may happen to be under the cursor at that
6854" moment. When the mouse and gui are available,
6855" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006856"
6857" Creates two lists
6858" s:netrwmarkfilelist -- holds complete paths to all marked files
6859" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6860"
6861" Creates a marked file match string
6862" s:netrwmarfilemtch_# -- used with 2match to display marked files
6863"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006864" Creates a buffer version of islocal
6865" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006866fun! s:NetrwMarkFile(islocal,fname)
6867" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006868" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006869
6870 " sanity check
6871 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006872" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006873 return
6874 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006875 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006876
Bram Moolenaar97d62492012-11-15 21:28:22 +01006877 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006878 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006879 if a:fname =~ '^\a'
6880 let leader= '\<'
6881 else
6882 let leader= ''
6883 endif
6884 if a:fname =~ '\a$'
6885 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6886 else
6887 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6888 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006889
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006890 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006891 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006892" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6893" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6894" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006895 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006896
6897 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006898 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006899" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006900 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006901 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006902
6903 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006904 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006905" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006906 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6907 if s:netrwmarkfilelist_{curbufnr} == []
6908 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006909" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006910 call s:NetrwUnmarkList(curbufnr,curdir)
6911 else
6912 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006913" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006914 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006915 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006916 for fname in s:netrwmarkfilelist_{curbufnr}
6917 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006918 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006919 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006920 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006921 endif
6922 let first= 0
6923 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006924" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006925 endif
6926 endif
6927
6928 else
6929 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006930" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006931
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006932" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006933 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006934 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6935" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006936
6937 " build initial markfile matching pattern
6938 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006939 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006940 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006941 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006943" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006944 endif
6945
6946 " handle global markfilelist
6947 if exists("s:netrwmarkfilelist")
6948 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6949 if index(s:netrwmarkfilelist,dname) == -1
6950 " append new filename to global markfilelist
6951 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006952" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006953 else
6954 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006955" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6956" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006957 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006958" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006959 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006960" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006961 unlet s:netrwmarkfilelist
6962 endif
6963 endif
6964 else
6965 " initialize new global-directory markfilelist
6966 let s:netrwmarkfilelist= []
6967 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006968" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006969 endif
6970
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006971 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006972 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6973 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6974" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6975 if exists("g:did_drchip_netrwlist_syntax")
6976 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6977 endif
6978 else
6979" " call Decho("2match none",'~'.expand("<slnum>"))
6980 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006981 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006982 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006983 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006984" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6985" 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 +00006986endfun
6987
6988" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006989" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6990" mA: move the argument list to marked file list (tomflist=1)
6991" Uses the global marked file list
6992fun! s:NetrwMarkFileArgList(islocal,tomflist)
6993" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6994
6995 let svpos = winsaveview()
6996" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6997 let curdir = s:NetrwGetCurdir(a:islocal)
6998 let curbufnr = bufnr("%")
6999
7000 if a:tomflist
7001 " mA: move argument list to marked file list
7002 while argc()
7003 let fname= argv(0)
7004" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7005 exe "argdel ".fnameescape(fname)
7006 call s:NetrwMarkFile(a:islocal,fname)
7007 endwhile
7008
7009 else
7010 " ma: move marked file list to argument list
7011 if exists("s:netrwmarkfilelist")
7012
7013 " for every filename in the marked list
7014 for fname in s:netrwmarkfilelist
7015" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7016 exe "argadd ".fnameescape(fname)
7017 endfor " for every file in the marked list
7018
7019 " unmark list and refresh
7020 call s:NetrwUnmarkList(curbufnr,curdir)
7021 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7022" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7023 NetrwKeepj call winrestview(svpos)
7024 endif
7025 endif
7026
7027" call Dret("s:NetrwMarkFileArgList")
7028endfun
7029
7030" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007031" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7032" compress/decompress files using the programs
7033" in g:netrw_compress and g:netrw_uncompress,
7034" using g:netrw_compress_suffix to know which to
7035" do. By default:
7036" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007037" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007038fun! s:NetrwMarkFileCompress(islocal)
7039" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007040 let svpos = winsaveview()
7041" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007042 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007043 let curbufnr = bufnr("%")
7044
Bram Moolenaarff034192013-04-24 18:51:19 +02007045 " sanity check
7046 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007047 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007048" call Dret("s:NetrwMarkFileCompress")
7049 return
7050 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007051" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007052
Bram Moolenaar446cb832008-06-24 21:56:24 +00007053 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007054
7055 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007056 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007057 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007058" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007059 if exists("g:netrw_decompress['".sfx."']")
7060 " fname has a suffix indicating that its compressed; apply associated decompression routine
7061 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007062" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007063 let exe= netrw#WinPath(exe)
7064 if a:islocal
7065 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007066 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007067 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007068 call system(exe." ".fname)
7069 if v:shell_error
7070 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007071 endif
7072 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007073 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7074 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007075 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007076
Bram Moolenaarff034192013-04-24 18:51:19 +02007077 endif
7078 unlet sfx
7079
Bram Moolenaar446cb832008-06-24 21:56:24 +00007080 if exists("exe")
7081 unlet exe
7082 elseif a:islocal
7083 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007084 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007085 if v:shell_error
7086 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7087 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007088 else
7089 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007090 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007091 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007092 endfor " for every file in the marked list
7093
Bram Moolenaar446cb832008-06-24 21:56:24 +00007094 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007095 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007096" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7097 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007098 endif
7099" call Dret("s:NetrwMarkFileCompress")
7100endfun
7101
7102" ---------------------------------------------------------------------
7103" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7104" If no marked files, then set up directory as the
7105" target. Currently does not support copying entire
7106" directories. Uses the local-buffer marked file list.
7107" Returns 1=success (used by NetrwMarkFileMove())
7108" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007109fun! s:NetrwMarkFileCopy(islocal,...)
7110" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7111
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007112 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007113 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007114 if b:netrw_curdir !~ '/$'
7115 if !exists("b:netrw_curdir")
7116 let b:netrw_curdir= curdir
7117 endif
7118 let b:netrw_curdir= b:netrw_curdir."/"
7119 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007120
Bram Moolenaarff034192013-04-24 18:51:19 +02007121 " sanity check
7122 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007123 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007124" call Dret("s:NetrwMarkFileCopy")
7125 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007126 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007127" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007128
Bram Moolenaar446cb832008-06-24 21:56:24 +00007129 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007130 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007131" call Dret("s:NetrwMarkFileCopy 0")
7132 return 0
7133 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007134" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007135
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007136 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007137 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007138" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007139 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007140 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7141" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7142 return
7143 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007144
7145 " copy marked files while within the same directory (ie. allow renaming)
7146 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7147 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7148 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007149" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007150 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007151 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7152 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007153" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007154 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007155 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007156 let oldname = a:1
7157 else
7158 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007159" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007160 let s:recursive= 1
7161 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7162 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7163 if ret == 0
7164 break
7165 endif
7166 endfor
7167 unlet s:recursive
7168 call s:NetrwUnmarkList(curbufnr,curdir)
7169" call Dret("s:NetrwMarkFileCopy ".ret)
7170 return ret
7171 endif
7172
7173 call inputsave()
7174 let newname= input("Copy ".oldname." to : ",oldname,"file")
7175 call inputrestore()
7176 if newname == ""
7177" call Dret("s:NetrwMarkFileCopy 0")
7178 return 0
7179 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007180 let args= s:ShellEscape(oldname)
7181 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007182 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007183 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7184 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007185 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007186 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007187 let args= substitute(args,'/','\\','g')
7188 let tgt = substitute(tgt, '/','\\','g')
7189 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007190 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7191 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7192 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7193 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7194" call Decho("args <".args.">",'~'.expand("<slnum>"))
7195" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007196 if isdirectory(s:NetrwFile(args))
7197" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007198 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007199" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007200 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007201 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7202 " contents to a target. One must append the source directory name to the target to get xcopy to
7203 " do the right thing.
7204 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007205" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007206 endif
7207 else
7208 let copycmd= g:netrw_localcopycmd
7209 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007210 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007211 let copycmd = substitute(copycmd,'\s.*$','','')
7212 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007213 let copycmd = netrw#WinPath(copycmd).copycmdargs
7214 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007215 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007216 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007217" call Decho("args <".args.">",'~'.expand("<slnum>"))
7218" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7219" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7220" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007221 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007222 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007223 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007224 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 +01007225 else
7226 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7227 endif
7228" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007229 return 0
7230 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007231
7232 elseif a:islocal && !s:netrwmftgt_islocal
7233 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007234" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007235 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007236
7237 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007238 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007239" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007240 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007241
7242 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007243 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007244" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007245 let curdir = getcwd()
7246 let tmpdir = s:GetTempfile("")
7247 if tmpdir !~ '/'
7248 let tmpdir= curdir."/".tmpdir
7249 endif
7250 if exists("*mkdir")
7251 call mkdir(tmpdir)
7252 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007253 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007254 if v:shell_error != 0
7255 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 +01007256" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007257 return
7258 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007259 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007260 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007261 if s:NetrwLcd(tmpdir)
7262" call Dret("s:NetrwMarkFileCopy : lcd failure")
7263 return
7264 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007265 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007266 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007267 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007268 if getcwd() == tmpdir
7269 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007270 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007271 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007272 if s:NetrwLcd(curdir)
7273" call Dret("s:NetrwMarkFileCopy : lcd failure")
7274 return
7275 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007276 if delete(tmpdir,"d")
7277 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007278 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007280 if s:NetrwLcd(curdir)
7281" call Dret("s:NetrwMarkFileCopy : lcd failure")
7282 return
7283 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007284 endif
7285 endif
7286 endif
7287
7288 " -------
7289 " cleanup
7290 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007291" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007292 " remove markings from local buffer
7293 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007294" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7295" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7296" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7297" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7298" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7299" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7300 if exists("s:recursive")
7301" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7302 else
7303" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007304 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007305 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007306 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007307 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007308 else
7309 " refresh local and targets for fast browsing
7310 if !exists("s:recursive")
7311 " remove markings from local buffer
7312" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7313 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7314 endif
7315
7316 " refresh buffers
7317 if s:netrwmftgt_islocal
7318" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7319 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7320 endif
7321 if a:islocal && s:netrwmftgt != curdir
7322" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7323 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7324 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007325 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007326
Bram Moolenaar446cb832008-06-24 21:56:24 +00007327" call Dret("s:NetrwMarkFileCopy 1")
7328 return 1
7329endfun
7330
7331" ---------------------------------------------------------------------
7332" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7333" invoke vim's diff mode on the marked files.
7334" Either two or three files can be so handled.
7335" Uses the global marked file list.
7336fun! s:NetrwMarkFileDiff(islocal)
7337" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7338 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007339
Bram Moolenaarff034192013-04-24 18:51:19 +02007340 " sanity check
7341 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007342 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007343" call Dret("s:NetrwMarkFileDiff")
7344 return
7345 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007346 let curdir= s:NetrwGetCurdir(a:islocal)
7347" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007348
Bram Moolenaara6878372014-03-22 21:02:50 +01007349 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007350 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007351 for fname in s:netrwmarkfilelist
7352 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007353 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007354" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007355 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007356 diffthis
7357 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007358 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007359" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007360 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361 diffthis
7362 else
7363 break
7364 endif
7365 endfor
7366 call s:NetrwUnmarkList(curbufnr,curdir)
7367 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007368
Bram Moolenaar446cb832008-06-24 21:56:24 +00007369" call Dret("s:NetrwMarkFileDiff")
7370endfun
7371
7372" ---------------------------------------------------------------------
7373" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7374" Uses global markfilelist
7375fun! s:NetrwMarkFileEdit(islocal)
7376" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7377
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007378 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007379 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007380
7381 " sanity check
7382 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007383 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007384" call Dret("s:NetrwMarkFileEdit")
7385 return
7386 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007387" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007388
Bram Moolenaar446cb832008-06-24 21:56:24 +00007389 if exists("s:netrwmarkfilelist_{curbufnr}")
7390 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007391 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007392 " unmark markedfile list
7393" call s:NetrwUnmarkList(curbufnr,curdir)
7394 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007395" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007396 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007397 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007398 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007399
Bram Moolenaar446cb832008-06-24 21:56:24 +00007400" call Dret("s:NetrwMarkFileEdit")
7401endfun
7402
7403" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007404" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007405fun! s:NetrwMarkFileQFEL(islocal,qfel)
7406" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7407 call s:NetrwUnmarkAll()
7408 let curbufnr= bufnr("%")
7409
7410 if !empty(a:qfel)
7411 for entry in a:qfel
7412 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007413" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007414 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007415" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007416 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7417 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7418 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7419 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007420" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007421 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7422 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007423" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007424 endif
7425 endfor
7426 echo "(use me to edit marked files)"
7427 else
7428 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7429 endif
7430
7431" call Dret("s:NetrwMarkFileQFEL")
7432endfun
7433
7434" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007435" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7436" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7437" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7438fun! s:NetrwMarkFileExe(islocal,enbloc)
7439" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007440 let svpos = winsaveview()
7441" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007442 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007443 let curbufnr = bufnr("%")
7444
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007445 if a:enbloc == 0
7446 " individually apply command to files, one at a time
7447 " sanity check
7448 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7449 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7450" call Dret("s:NetrwMarkFileExe")
7451 return
7452 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007453" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007454
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007455 if exists("s:netrwmarkfilelist_{curbufnr}")
7456 " get the command
7457 call inputsave()
7458 let cmd= input("Enter command: ","","file")
7459 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007460" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007461 if cmd == ""
7462" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7463 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007464 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007465
7466 " apply command to marked files, individually. Substitute: filename -> %
7467 " If no %, then append a space and the filename to the command
7468 for fname in s:netrwmarkfilelist_{curbufnr}
7469 if a:islocal
7470 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007471 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007472 endif
7473 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007474 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007475 endif
7476 if cmd =~ '%'
7477 let xcmd= substitute(cmd,'%',fname,'g')
7478 else
7479 let xcmd= cmd.' '.fname
7480 endif
7481 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007482" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483 let ret= system(xcmd)
7484 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007485" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007486 let ret= s:RemoteSystem(xcmd)
7487 endif
7488 if v:shell_error < 0
7489 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7490 break
7491 else
7492 echo ret
7493 endif
7494 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007495
7496 " unmark marked file list
7497 call s:NetrwUnmarkList(curbufnr,curdir)
7498
7499 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007500 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007501" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7502 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007503 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007504 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007505 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007506
7507 else " apply command to global list of files, en bloc
7508
7509 call inputsave()
7510 let cmd= input("Enter command: ","","file")
7511 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007512" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007513 if cmd == ""
7514" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7515 return
7516 endif
7517 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007518 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007519 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007520 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007521 endif
7522 if a:islocal
7523 call system(cmd)
7524 if v:shell_error < 0
7525 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7526 endif
7527 else
7528 let ret= s:RemoteSystem(cmd)
7529 endif
7530 call s:NetrwUnmarkAll()
7531
7532 " refresh the listing
7533 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007534" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7535 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007536
7537 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007538
Bram Moolenaar446cb832008-06-24 21:56:24 +00007539" call Dret("s:NetrwMarkFileExe")
7540endfun
7541
7542" ---------------------------------------------------------------------
7543" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7544" as the marked file(s) (toggles suffix presence)
7545" Uses the local marked file list.
7546fun! s:NetrwMarkHideSfx(islocal)
7547" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007548 let svpos = winsaveview()
7549" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007550 let curbufnr = bufnr("%")
7551
7552 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7553 if exists("s:netrwmarkfilelist_{curbufnr}")
7554
7555 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007556" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007557 " construct suffix pattern
7558 if fname =~ '\.'
7559 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7560 else
7561 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7562 endif
7563 " determine if its in the hiding list or not
7564 let inhidelist= 0
7565 if g:netrw_list_hide != ""
7566 let itemnum = 0
7567 let hidelist= split(g:netrw_list_hide,',')
7568 for hidepat in hidelist
7569 if sfxpat == hidepat
7570 let inhidelist= 1
7571 break
7572 endif
7573 let itemnum= itemnum + 1
7574 endfor
7575 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007576" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007577 if inhidelist
7578 " remove sfxpat from list
7579 call remove(hidelist,itemnum)
7580 let g:netrw_list_hide= join(hidelist,",")
7581 elseif g:netrw_list_hide != ""
7582 " append sfxpat to non-empty list
7583 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7584 else
7585 " set hiding list to sfxpat
7586 let g:netrw_list_hide= sfxpat
7587 endif
7588 endfor
7589
7590 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007591 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007592" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7593 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007594 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007595 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007596 endif
7597
7598" call Dret("s:NetrwMarkHideSfx")
7599endfun
7600
7601" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007602" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007603" Uses the local marked-file list.
7604fun! s:NetrwMarkFileVimCmd(islocal)
7605" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007606 let svpos = winsaveview()
7607" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007608 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007609 let curbufnr = bufnr("%")
7610
Bram Moolenaarff034192013-04-24 18:51:19 +02007611 " sanity check
7612 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007613 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007614" call Dret("s:NetrwMarkFileVimCmd")
7615 return
7616 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007617" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007618
Bram Moolenaar15146672011-10-20 22:22:38 +02007619 if exists("s:netrwmarkfilelist_{curbufnr}")
7620 " get the command
7621 call inputsave()
7622 let cmd= input("Enter vim command: ","","file")
7623 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007624" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007625 if cmd == ""
7626" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7627 return
7628 endif
7629
7630 " apply command to marked files. Substitute: filename -> %
7631 " If no %, then append a space and the filename to the command
7632 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007633" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007634 if a:islocal
7635 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007636 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007637" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007638 exe cmd
7639 exe "sil! keepalt wq!"
7640 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007641" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007642 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007643 endif
7644 endfor
7645
7646 " unmark marked file list
7647 call s:NetrwUnmarkList(curbufnr,curdir)
7648
7649 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007650 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007651" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7652 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007653 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007654 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007655 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007656
Bram Moolenaar15146672011-10-20 22:22:38 +02007657" call Dret("s:NetrwMarkFileVimCmd")
7658endfun
7659
7660" ---------------------------------------------------------------------
7661" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7662" as the marked file(s) (toggles suffix presence)
7663" Uses the local marked file list.
7664fun! s:NetrwMarkHideSfx(islocal)
7665" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007666 let svpos = winsaveview()
7667" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007668 let curbufnr = bufnr("%")
7669
7670 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7671 if exists("s:netrwmarkfilelist_{curbufnr}")
7672
7673 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007674" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007675 " construct suffix pattern
7676 if fname =~ '\.'
7677 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7678 else
7679 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7680 endif
7681 " determine if its in the hiding list or not
7682 let inhidelist= 0
7683 if g:netrw_list_hide != ""
7684 let itemnum = 0
7685 let hidelist= split(g:netrw_list_hide,',')
7686 for hidepat in hidelist
7687 if sfxpat == hidepat
7688 let inhidelist= 1
7689 break
7690 endif
7691 let itemnum= itemnum + 1
7692 endfor
7693 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007694" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007695 if inhidelist
7696 " remove sfxpat from list
7697 call remove(hidelist,itemnum)
7698 let g:netrw_list_hide= join(hidelist,",")
7699 elseif g:netrw_list_hide != ""
7700 " append sfxpat to non-empty list
7701 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7702 else
7703 " set hiding list to sfxpat
7704 let g:netrw_list_hide= sfxpat
7705 endif
7706 endfor
7707
7708 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007709 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007710" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7711 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007712 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007713 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007714 endif
7715
7716" call Dret("s:NetrwMarkHideSfx")
7717endfun
7718
7719" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007720" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7721" Uses the global markfilelist
7722fun! s:NetrwMarkFileGrep(islocal)
7723" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007724 let svpos = winsaveview()
7725" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007726 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007727 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007728
7729 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007730" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007731 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007732" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007733 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007734 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007735" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007736 let netrwmarkfilelist= "*"
7737 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007738
Bram Moolenaarff034192013-04-24 18:51:19 +02007739 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007740" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007741 call inputsave()
7742 let pat= input("Enter pattern: ","")
7743 call inputrestore()
7744 let patbang = ""
7745 if pat =~ '^!'
7746 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007747 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007748 endif
7749 if pat =~ '^\i'
7750 let pat = escape(pat,'/')
7751 let pat = '/'.pat.'/'
7752 else
7753 let nonisi = pat[0]
7754 endif
7755
7756 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007757" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007758 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007759 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007760 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007761 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007762" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7763 return
7764 endtry
7765 echo "(use :cn, :cp to navigate, :Rex to return)"
7766
7767 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007768" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7769 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007770
7771 if exists("nonisi")
7772 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007773" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007774 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007775 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007776 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007777 endif
7778
7779" call Dret("s:NetrwMarkFileGrep")
7780endfun
7781
7782" ---------------------------------------------------------------------
7783" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7784" uses the global marked file list
7785" s:netrwmfloc= 0: target directory is remote
7786" = 1: target directory is local
7787fun! s:NetrwMarkFileMove(islocal)
7788" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007789 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007790 let curbufnr = bufnr("%")
7791
7792 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007793 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007794 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007795" call Dret("s:NetrwMarkFileMove")
7796 return
7797 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007798" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007799
Bram Moolenaar446cb832008-06-24 21:56:24 +00007800 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007801 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007802" call Dret("s:NetrwMarkFileCopy 0")
7803 return 0
7804 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007805" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007806
7807 if a:islocal && s:netrwmftgt_islocal
7808 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007809" call Decho("move from local to local",'~'.expand("<slnum>"))
7810" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007811 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007812 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7813" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7814 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007815 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007816 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007817" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007818 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007819 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007820" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007821 if g:netrw_localmovecmd =~ '\s'
7822 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7823 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7824 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007825" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007826 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007827 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007828" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007829 endif
7830 else
7831 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007832" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007833 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007834 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007835 if g:netrw_keepdir
7836 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7837 let fname= b:netrw_curdir."/".fname
7838 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007839 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007840 let fname= substitute(fname,'/','\\','g')
7841 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007842" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007843 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007844 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007845 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007846 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 +01007847 else
7848 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7849 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007850 break
7851 endif
7852 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007853
7854 elseif a:islocal && !s:netrwmftgt_islocal
7855 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007856" call Decho("move from local to remote",'~'.expand("<slnum>"))
7857" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007858 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007859 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007860" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007861 for fname in mflist
7862 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7863 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7864 endfor
7865 unlet mflist
7866
7867 elseif !a:islocal && s:netrwmftgt_islocal
7868 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007869" call Decho("move from remote to local",'~'.expand("<slnum>"))
7870" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007871 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007872 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007873" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007874 for fname in mflist
7875 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7876 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7877 endfor
7878 unlet mflist
7879
7880 elseif !a:islocal && !s:netrwmftgt_islocal
7881 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007882" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7883" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007884 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007885 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007886" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007887 for fname in mflist
7888 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7889 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7890 endfor
7891 unlet mflist
7892 endif
7893
7894 " -------
7895 " cleanup
7896 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007897" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007898
7899 " remove markings from local buffer
7900 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7901
7902 " refresh buffers
7903 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007904" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007905 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007906 endif
7907 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007908" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007909 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007910 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007911 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007912" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007913 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007914 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007915
Bram Moolenaar446cb832008-06-24 21:56:24 +00007916" call Dret("s:NetrwMarkFileMove")
7917endfun
7918
7919" ---------------------------------------------------------------------
7920" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7921" using the hardcopy command. Local marked-file list only.
7922fun! s:NetrwMarkFilePrint(islocal)
7923" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7924 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007925
7926 " sanity check
7927 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007928 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007929" call Dret("s:NetrwMarkFilePrint")
7930 return
7931 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007932" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7933 let curdir= s:NetrwGetCurdir(a:islocal)
7934
Bram Moolenaar446cb832008-06-24 21:56:24 +00007935 if exists("s:netrwmarkfilelist_{curbufnr}")
7936 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007937 call s:NetrwUnmarkList(curbufnr,curdir)
7938 for fname in netrwmarkfilelist
7939 if a:islocal
7940 if g:netrw_keepdir
7941 let fname= s:ComposePath(curdir,fname)
7942 endif
7943 else
7944 let fname= curdir.fname
7945 endif
7946 1split
7947 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007948" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007949 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007950" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007951 hardcopy
7952 q
7953 endfor
7954 2match none
7955 endif
7956" call Dret("s:NetrwMarkFilePrint")
7957endfun
7958
7959" ---------------------------------------------------------------------
7960" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7961" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007962" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007963fun! s:NetrwMarkFileRegexp(islocal)
7964" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7965
7966 " get the regular expression
7967 call inputsave()
7968 let regexp= input("Enter regexp: ","","file")
7969 call inputrestore()
7970
7971 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007972 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007973" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007974 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007975" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007976 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007977 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007978 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007979 else
7980 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007981 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007982 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007983" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007984
7985 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007986 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007987 if fname =~ '^'.fnameescape(curdir)
7988" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7989 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7990 else
7991" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7992 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7993 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007994 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007995
7996 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007997" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007998
7999 " convert displayed listing into a filelist
8000 let eikeep = &ei
8001 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008002 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008003 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008004" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008005 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008006 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008007 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008008 sil NetrwKeepj norm! "ap
8009 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008010 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008011 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008012 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008013 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008014 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008015 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008016 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008017 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008018 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008019 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008020 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8021 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008022 call histdel("/",-1)
8023 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024 endif
8025 " convert regexp into the more usual glob-style format
8026 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008027" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008028 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008029 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008030 let filelist= getline(1,line("$"))
8031 q!
8032 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008033 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008034 endfor
8035 unlet filelist
8036 let @a = areg
8037 let &ei = eikeep
8038 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008039 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008040
8041" call Dret("s:NetrwMarkFileRegexp")
8042endfun
8043
8044" ---------------------------------------------------------------------
8045" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8046" Uses the local marked file list.
8047fun! s:NetrwMarkFileSource(islocal)
8048" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8049 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008050
8051 " sanity check
8052 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008053 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008054" call Dret("s:NetrwMarkFileSource")
8055 return
8056 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008057" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8058 let curdir= s:NetrwGetCurdir(a:islocal)
8059
Bram Moolenaar446cb832008-06-24 21:56:24 +00008060 if exists("s:netrwmarkfilelist_{curbufnr}")
8061 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008062 call s:NetrwUnmarkList(curbufnr,curdir)
8063 for fname in netrwmarkfilelist
8064 if a:islocal
8065 if g:netrw_keepdir
8066 let fname= s:ComposePath(curdir,fname)
8067 endif
8068 else
8069 let fname= curdir.fname
8070 endif
8071 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008072" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008073 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008074 endfor
8075 2match none
8076 endif
8077" call Dret("s:NetrwMarkFileSource")
8078endfun
8079
8080" ---------------------------------------------------------------------
8081" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8082" Uses the global markfilelist
8083fun! s:NetrwMarkFileTag(islocal)
8084" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008085 let svpos = winsaveview()
8086" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008087 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008088 let curbufnr = bufnr("%")
8089
Bram Moolenaarff034192013-04-24 18:51:19 +02008090 " sanity check
8091 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008092 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008093" call Dret("s:NetrwMarkFileTag")
8094 return
8095 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008096" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008097
Bram Moolenaar446cb832008-06-24 21:56:24 +00008098 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008099" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8100 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008101 call s:NetrwUnmarkAll()
8102
8103 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008104
8105" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8106 call system(g:netrw_ctags." ".netrwmarkfilelist)
8107 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008108 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8109 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008110
Bram Moolenaar446cb832008-06-24 21:56:24 +00008111 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008112 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008113 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008114 let curdir= b:netrw_curdir
8115 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008116 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008117 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008118" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008119 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008120 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008121 wq!
8122 endif
8123 2match none
8124 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008125" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8126 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008127 endif
8128
8129" call Dret("s:NetrwMarkFileTag")
8130endfun
8131
8132" ---------------------------------------------------------------------
8133" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008134" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008135" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008136" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008137" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008138fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008139" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8140 let svpos = winsaveview()
8141" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008142 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008143 let hadtgt = exists("s:netrwmftgt")
8144 if !exists("w:netrw_bannercnt")
8145 let w:netrw_bannercnt= b:netrw_bannercnt
8146 endif
8147
8148 " set up target
8149 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008150" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008151 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8152 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008153" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008154 unlet s:netrwmftgt s:netrwmftgt_islocal
8155 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008156 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008157 endif
8158 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008159" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8160 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008161" call Dret("s:NetrwMarkFileTgt : removed target")
8162 return
8163 else
8164 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008165" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008166 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008167
8168 else
8169 " get word under cursor.
8170 " * If directory, use it for the target.
8171 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008172" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008173 let curword= s:NetrwGetWord()
8174 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008175 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008176 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008177" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008178 elseif !a:islocal && tgtdir =~ '/$'
8179 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008180" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008181 else
8182 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184 endif
8185 endif
8186 if a:islocal
8187 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8188 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008189" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008190 endif
8191 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008192 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008193 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8194 endif
8195 let s:netrwmftgt_islocal= a:islocal
8196
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008197 " need to do refresh so that the banner will be updated
8198 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008199 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008200" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008201 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008202 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008203" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008204 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008205 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8206 else
8207 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8208 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008209" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8210 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008211 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008212 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008213 endif
8214
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008215" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8216" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008217" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8218endfun
8219
8220" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008221" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8222fun! s:NetrwGetCurdir(islocal)
8223" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8224
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008225 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008226 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8227" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8228 elseif !exists("b:netrw_curdir")
8229 let b:netrw_curdir= getcwd()
8230" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8231 endif
8232
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008233" 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 +01008234 if b:netrw_curdir !~ '\<\a\{3,}://'
8235 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008236" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008237 if g:netrw_keepdir == 0
8238 call s:NetrwLcd(curdir)
8239 endif
8240 endif
8241
8242" call Dret("s:NetrwGetCurdir <".curdir.">")
8243 return b:netrw_curdir
8244endfun
8245
8246" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008247" s:NetrwOpenFile: query user for a filename and open it {{{2
8248fun! s:NetrwOpenFile(islocal)
8249" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008250 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008251 call inputsave()
8252 let fname= input("Enter filename: ")
8253 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008254" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8255
8256 " determine if Lexplore is in use
8257 if exists("t:netrw_lexbufnr")
8258 " check if t:netrw_lexbufnr refers to a netrw window
8259" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8260 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8261 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8262" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8263 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8264 exe "NetrwKeepj e ".fnameescape(fname)
8265 let @@= ykeep
8266" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8267 endif
8268 endif
8269
8270 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008271 if fname !~ '[/\\]'
8272 if exists("b:netrw_curdir")
8273 if exists("g:netrw_quiet")
8274 let netrw_quiet_keep = g:netrw_quiet
8275 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008276 let g:netrw_quiet = 1
8277 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008278 let s:rexposn_{bufnr("%")}= winsaveview()
8279" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008280 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008281 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008282 else
8283 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8284 endif
8285 if exists("netrw_quiet_keep")
8286 let g:netrw_quiet= netrw_quiet_keep
8287 else
8288 unlet g:netrw_quiet
8289 endif
8290 endif
8291 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008292 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008293 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008294 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008295" call Dret("s:NetrwOpenFile")
8296endfun
8297
8298" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008299" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8300" For the mapping to this function be made via
8301" netrwPlugin, you'll need to have had
8302" g:netrw_usetab set to non-zero.
8303fun! netrw#Shrink()
8304" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8305 let curwin = winnr()
8306 let wiwkeep = &wiw
8307 set wiw=1
8308
8309 if &ft == "netrw"
8310 if winwidth(0) > g:netrw_wiw
8311 let t:netrw_winwidth= winwidth(0)
8312 exe "vert resize ".g:netrw_wiw
8313 wincmd l
8314 if winnr() == curwin
8315 wincmd h
8316 endif
8317" call Decho("vert resize 0",'~'.expand("<slnum>"))
8318 else
8319 exe "vert resize ".t:netrw_winwidth
8320" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8321 endif
8322
8323 elseif exists("t:netrw_lexbufnr")
8324 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8325 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8326 let t:netrw_winwidth= winwidth(0)
8327 exe "vert resize ".g:netrw_wiw
8328 wincmd l
8329 if winnr() == curwin
8330 wincmd h
8331 endif
8332" call Decho("vert resize 0",'~'.expand("<slnum>"))
8333 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8334 exe "vert resize ".t:netrw_winwidth
8335" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8336 else
8337 call netrw#Lexplore(0,0)
8338 endif
8339
8340 else
8341 call netrw#Lexplore(0,0)
8342 endif
8343 let wiw= wiwkeep
8344
8345" call Dret("netrw#Shrink")
8346endfun
8347
8348" ---------------------------------------------------------------------
8349" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8350fun! s:NetSortSequence(islocal)
8351" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8352
8353 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008354 let svpos= winsaveview()
8355" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008356 call inputsave()
8357 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8358 call inputrestore()
8359
8360 " refresh the listing
8361 let g:netrw_sort_sequence= newsortseq
8362 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008363" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8364 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008365 let @@= ykeep
8366
8367" call Dret("NetSortSequence")
8368endfun
8369
8370" ---------------------------------------------------------------------
8371" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8372" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008373" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008374fun! s:NetrwUnmarkList(curbufnr,curdir)
8375" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8376
8377 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008378 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008379 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8380 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8381 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8382 call remove(s:netrwmarkfilelist,idx) " remove from global list
8383 endfor
8384 if s:netrwmarkfilelist == []
8385 unlet s:netrwmarkfilelist
8386 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008387
Bram Moolenaar446cb832008-06-24 21:56:24 +00008388 " getting rid of the local marked-file lists is easy
8389 unlet s:netrwmarkfilelist_{a:curbufnr}
8390 endif
8391 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8392 unlet s:netrwmarkfilemtch_{a:curbufnr}
8393 endif
8394 2match none
8395" call Dret("s:NetrwUnmarkList")
8396endfun
8397
8398" ---------------------------------------------------------------------
8399" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8400fun! s:NetrwUnmarkAll()
8401" call Dfunc("s:NetrwUnmarkAll()")
8402 if exists("s:netrwmarkfilelist")
8403 unlet s:netrwmarkfilelist
8404 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008405 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008406 2match none
8407" call Dret("s:NetrwUnmarkAll")
8408endfun
8409
8410" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008411" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008412fun! s:NetrwUnmarkAll2()
8413" call Dfunc("s:NetrwUnmarkAll2()")
8414 redir => netrwmarkfilelist_let
8415 let
8416 redir END
8417 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008418 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008419 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8420 for flist in netrwmarkfilelist_list
8421 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8422 unlet s:netrwmarkfilelist_{curbufnr}
8423 unlet s:netrwmarkfilemtch_{curbufnr}
8424 endfor
8425" call Dret("s:NetrwUnmarkAll2")
8426endfun
8427
8428" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008429" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8430"
8431" Marked files are in two types of lists:
8432" s:netrwmarkfilelist -- holds complete paths to all marked files
8433" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8434"
8435" Marked files suitable for use with 2match are in:
8436" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008437fun! s:NetrwUnMarkFile(islocal)
8438" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008439 let svpos = winsaveview()
8440" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008441 let curbufnr = bufnr("%")
8442
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008443 " unmark marked file list
8444 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8445 if exists("s:netrwmarkfilelist")
8446" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008447 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008448 endif
8449
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008450 let ibuf= 1
8451 while ibuf < bufnr("$")
8452 if exists("s:netrwmarkfilelist_".ibuf)
8453 unlet s:netrwmarkfilelist_{ibuf}
8454 unlet s:netrwmarkfilemtch_{ibuf}
8455 endif
8456 let ibuf = ibuf + 1
8457 endwhile
8458 2match none
8459
Bram Moolenaar446cb832008-06-24 21:56:24 +00008460" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008461"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8462call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008463" call Dret("s:NetrwUnMarkFile")
8464endfun
8465
8466" ---------------------------------------------------------------------
8467" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8468fun! s:NetrwMenu(domenu)
8469
8470 if !exists("g:NetrwMenuPriority")
8471 let g:NetrwMenuPriority= 80
8472 endif
8473
Bram Moolenaaradc21822011-04-01 18:03:16 +02008474 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008475" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8476
8477 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008478" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008479 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008480 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8481 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8482 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8483 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8484 if g:netrw_dirhistmax > 0
8485 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8486 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8487 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8488 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8489 else
8490 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8491 endif
8492 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8495 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8497 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8500 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8506 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 +01008507 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 +02008508 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8537 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>'
8538 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>'
8539 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>'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8541 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>'
8542 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>'
8543 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 +01008544 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 +02008545 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008547 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008548 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8549 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008550
8551 elseif !a:domenu
8552 let s:netrwcnt = 0
8553 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008554 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008555 exe curwin."wincmd w"
8556
8557 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008558" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008559 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008560" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008561 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008562 endif
8563 endif
8564" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008565 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008566 endif
8567
8568endfun
8569
8570" ---------------------------------------------------------------------
8571" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8572" Used by the O maps (as <SID>NetrwObtain())
8573fun! s:NetrwObtain(islocal)
8574" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8575
Bram Moolenaar97d62492012-11-15 21:28:22 +01008576 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008577 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008578 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008579 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008580 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8581 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008582 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008583 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008584 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008585
8586" call Dret("NetrwObtain")
8587endfun
8588
8589" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008590" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8591" If there's only one window, then the window will first be split.
8592" Returns:
8593" choice = 0 : didn't have to choose
8594" choice = 1 : saved modified file in window first
8595" choice = 2 : didn't save modified file, opened window
8596" choice = 3 : cancel open
8597fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008598" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008599
Bram Moolenaar97d62492012-11-15 21:28:22 +01008600 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008602 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008603" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008604
8605 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008606 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008608" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8609" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8610 let curword = s:NetrwGetWord()
8611 let choice = 0
8612 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8613" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008614 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008615" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008616 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008617" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008618" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008619" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008620
Bram Moolenaar8d043172014-01-23 14:24:41 +01008621 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008622 if lastwinnr == 1
8623 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008624" 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 +02008625 " g:netrw_preview=0: preview window shown in a horizontally split window
8626 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008627 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008628 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008629 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008630" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008631 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008632 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008633 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008634 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008635" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008636 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008637 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008638 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008639" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008640
8641 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008642" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008643 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008644" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008645 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008646" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008647 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008648" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008649 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008650" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008651" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008652" call Decho("COMBAK#12: mod=".&mod)
8653
8654 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8655 " whoops -- user trying to open file in the Lexplore window.
8656 " Use Lexplore's opening-file window instead.
8657" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8658" exe g:netrw_chgwin."wincmd w"
8659 wincmd p
8660 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8661 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008662
8663 " prevwinnr: the window number of the "prev" window
8664 " prevbufnr: the buffer number of the buffer in the "prev" window
8665 " bnrcnt : the qty of windows open on the "prev" buffer
8666 let prevwinnr = winnr()
8667 let prevbufnr = bufnr("%")
8668 let prevbufname = bufname("%")
8669 let prevmod = &mod
8670 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008671" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008672 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008673" 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 +01008674" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008675
8676 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008677 " and it doesn't appear in any other extant window, then ask the
8678 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008679 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008680" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008681 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008682" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008683 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008684" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008685
8686 if bnrcnt == 1 && &hidden == 0
8687 " only one copy of the modified buffer in a window, and
8688 " hidden not set, so overwriting will lose the modified file. Ask first...
8689 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008690" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008691 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008692" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008693
8694 if choice == 1
8695 " Yes -- write file & then browse
8696 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008697 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008698 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008699 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008700 exe origwin."wincmd w"
8701 let &ei = eikeep
8702 let @@ = ykeep
8703" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008704 return choice
8705 endif
8706
8707 elseif choice == 2
8708 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008709" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008710 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008711
8712 else
8713 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008714" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008715 exe origwin."wincmd w"
8716 let &ei= eikeep
8717 let @@ = ykeep
8718" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008719 return choice
8720 endif
8721 endif
8722 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008723 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008724 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008725" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008726
8727 " restore b:netrw_curdir (window split/enew may have lost it)
8728 let b:netrw_curdir= curdir
8729 if a:islocal < 2
8730 if a:islocal
8731 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8732 else
8733 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8734 endif
8735 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008736 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008737" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008738 return choice
8739endfun
8740
8741" ---------------------------------------------------------------------
8742" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8743" Always assumed to be local -> remote
8744" call s:NetrwUpload(filename, target)
8745" call s:NetrwUpload(filename, target, fromdirectory)
8746fun! s:NetrwUpload(fname,tgt,...)
8747" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8748
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008749 if a:tgt =~ '^\a\{3,}://'
8750 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008751 else
8752 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8753 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008754" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008755
8756 if a:0 > 0
8757 let fromdir= a:1
8758 else
8759 let fromdir= getcwd()
8760 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008761" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008762
8763 if type(a:fname) == 1
8764 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008765" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008766 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008767" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8768 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8769" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770 if a:tgt =~ '/$'
8771 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008772" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008773 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008774 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008775" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008776 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008777" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778 endif
8779 q!
8780
8781 elseif type(a:fname) == 3
8782 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008784 let curdir= getcwd()
8785 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008786 if s:NetrwLcd(fromdir)
8787" call Dret("s:NetrwUpload : lcd failure")
8788 return
8789 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008790 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008791 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792 if exists("g:netrw_port") && g:netrw_port != ""
8793 let useport= " ".g:netrw_scpport." ".g:netrw_port
8794 else
8795 let useport= ""
8796 endif
8797 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8798 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008799 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 +02008800 if s:NetrwLcd(curdir)
8801" call Dret("s:NetrwUpload : lcd failure")
8802 return
8803 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008804
8805 elseif a:tgt =~ '^ftp:'
8806 call s:NetrwMethod(a:tgt)
8807
8808 if b:netrw_method == 2
8809 " handle uploading a list of files via ftp+.netrc
8810 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008811 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008812" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008813
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008814 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008815" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008816
8817 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008818 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008819" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008820 endif
8821
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008822 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008823" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824
Bram Moolenaaradc21822011-04-01 18:03:16 +02008825 if tgtdir == ""
8826 let tgtdir= '/'
8827 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008828 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008829" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008830
8831 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008832 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8833" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008834 endfor
8835
8836 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008837 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 +00008838 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008839" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8840 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008841 endif
8842 " 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 +01008843 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008844 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008845 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8846 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8847 else
8848 bw!|q
8849 endif
8850
8851 elseif b:netrw_method == 3
8852 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8853 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008854 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008855 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008856 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008857
8858 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008859 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008860" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008861 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008862 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008863" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008864 endif
8865
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008866 if exists("g:netrw_uid") && g:netrw_uid != ""
8867 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008868 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008869" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008870 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008871 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008872 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008873" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008874 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008875 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008876" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008877 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008878 endif
8879
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008880 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008881" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008882
8883 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008884 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
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
8888 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008889 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008890" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008891 endif
8892
8893 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008894 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008895" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008896 endfor
8897
8898 " perform ftp:
8899 " -i : turns off interactive prompting from ftp
8900 " -n unix : DON'T use <.netrc>, even though it exists
8901 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008902 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008903 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008904 " 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 +01008905 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008906 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008907 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8908 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008909 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008910 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8911 let &debug = debugkeep
8912 let mod = 1
8913 else
8914 bw!|q
8915 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008916 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008917" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008918 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008919 endif
8920 else
8921 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8922 endif
8923 endif
8924
8925" call Dret("s:NetrwUpload")
8926endfun
8927
8928" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008929" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008930fun! s:NetrwPreview(path) range
8931" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008932" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8933" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008934 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008935 NetrwKeepj call s:NetrwOptionsSave("s:")
8936 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8937 NetrwKeepj call s:NetrwOptionsSafe(1)
8938 else
8939 NetrwKeepj call s:NetrwOptionsSafe(0)
8940 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008941 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008942" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008943 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008944" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8945 if g:netrw_preview
8946 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008947 let pvhkeep = &pvh
8948 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8949 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008950" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8951 else
8952 " horizontal split
8953 let pvhkeep = &pvh
8954 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8955 let &pvh = winheight(0) - winsz
8956" 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 +02008957 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008958 " g:netrw_preview g:netrw_alto
8959 " 1 : vert 1: top -- preview window is vertically split off and on the left
8960 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8961 " 0 : 1: top -- preview window is horizontally split off and on the top
8962 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8963 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008964 " 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 +02008965 " the BufEnter event set up in netrwPlugin.vim
8966" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8967 let eikeep = &ei
8968 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008969 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008970 let &ei= eikeep
8971" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008972 if exists("pvhkeep")
8973 let &pvh= pvhkeep
8974 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008975 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008976 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008977 endif
8978 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008979 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 +00008980 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008981 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008982 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008983" call Dret("NetrwPreview")
8984endfun
8985
8986" ---------------------------------------------------------------------
8987" s:NetrwRefresh: {{{2
8988fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008989" 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 +00008990 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008991 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008992" call Decho("setl ma noro",'~'.expand("<slnum>"))
8993" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008994 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008995 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8996 if !exists("w:netrw_treetop")
8997 if exists("b:netrw_curdir")
8998 let w:netrw_treetop= b:netrw_curdir
8999 else
9000 let w:netrw_treetop= getcwd()
9001 endif
9002 endif
9003 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9004 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009005
9006 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009007 let screenposn = winsaveview()
9008" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009009
9010" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9011" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9012 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009013 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009014 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009015 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009016 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009017 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009018
9019 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009020" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9021 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009022
9023 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009024 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9025 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9026" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9027 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9028 else
9029" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9030 2match none
9031 endif
9032 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009033
Bram Moolenaar97d62492012-11-15 21:28:22 +01009034" restore
9035 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009036" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009037endfun
9038
9039" ---------------------------------------------------------------------
9040" s:NetrwRefreshDir: refreshes a directory by name {{{2
9041" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009042" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009043fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009044" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009045 if g:netrw_fastbrowse == 0
9046 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009047" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009048 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009049" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009050
9051 if tgtwin > 0
9052 " tgtwin is being displayed, so refresh it
9053 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009054" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009055 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009056 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009057 exe curwin."wincmd w"
9058
9059 elseif bufnr(a:dirname) > 0
9060 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009061" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9062 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009063 endif
9064
9065 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009066" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009067 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009068 endif
9069" call Dret("s:NetrwRefreshDir")
9070endfun
9071
9072" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009073" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9074" window number to do its editing in.
9075" Supports [count]C where the count, if present, is used to specify
9076" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009077fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009078" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009079 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009080" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009081 if a:1 == "" " :NetrwC win#
9082 let g:netrw_chgwin= winnr()
9083 else " :NetrwC
9084 let g:netrw_chgwin= a:1
9085 endif
9086 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009087 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009088 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009089 let g:netrw_chgwin= winnr()
9090 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009091 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009092" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009093endfun
9094
9095" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009096" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9097" What this function does is to compute a priority for the patterns
9098" in the g:netrw_sort_sequence. It applies a substitute to any
9099" "files" that satisfy each pattern, putting the priority / in
9100" front. An "*" pattern handles the default priority.
9101fun! s:NetrwSetSort()
9102" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009103 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009104 if w:netrw_liststyle == s:LONGLIST
9105 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9106 else
9107 let seqlist = g:netrw_sort_sequence
9108 endif
9109 " sanity check -- insure that * appears somewhere
9110 if seqlist == ""
9111 let seqlist= '*'
9112 elseif seqlist !~ '\*'
9113 let seqlist= seqlist.',*'
9114 endif
9115 let priority = 1
9116 while seqlist != ""
9117 if seqlist =~ ','
9118 let seq = substitute(seqlist,',.*$','','e')
9119 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9120 else
9121 let seq = seqlist
9122 let seqlist = ""
9123 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009124 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009125 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009126 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009127 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009128 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009129 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009130 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009131" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009132
9133 " sanity check
9134 if w:netrw_bannercnt > line("$")
9135 " apparently no files were left after a Hiding pattern was used
9136" call Dret("SetSort : no files left after hiding")
9137 return
9138 endif
9139 if seq == '*'
9140 let starpriority= spriority
9141 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009142 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009143 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009144 " sometimes multiple sorting patterns will match the same file or directory.
9145 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009146 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9147 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009148 endif
9149 let priority = priority + 1
9150 endwhile
9151 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009152 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9153 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009154 endif
9155
9156 " Following line associated with priority -- items that satisfy a priority
9157 " pattern get prefixed by ###/ which permits easy sorting by priority.
9158 " Sometimes files can satisfy multiple priority patterns -- only the latest
9159 " priority pattern needs to be retained. So, at this point, these excess
9160 " priority prefixes need to be removed, but not directories that happen to
9161 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009162 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9163 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009164 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165
9166" call Dret("SetSort")
9167endfun
9168
Bram Moolenaarff034192013-04-24 18:51:19 +02009169" ---------------------------------------------------------------------
9170" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9171" Implements [count]Tb (bookhist<b>)
9172" [count]Th (bookhist<h>)
9173" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009174fun! s:NetrwSetTgt(islocal,bookhist,choice)
9175" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009176
9177 if a:bookhist == 'b'
9178 " supports choosing a bookmark as a target using a qb-generated list
9179 let choice= a:choice - 1
9180 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009181 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009182 else
9183 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9184 endif
9185
9186 elseif a:bookhist == 'h'
9187 " supports choosing a history stack entry as a target using a qb-generated list
9188 let choice= (a:choice % g:netrw_dirhistmax) + 1
9189 if exists("g:netrw_dirhist_".choice)
9190 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009191 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009192 else
9193 echomsg "Sorry, history#".a:choice." not available!"
9194 endif
9195 endif
9196
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009197 " refresh the display
9198 if !exists("b:netrw_curdir")
9199 let b:netrw_curdir= getcwd()
9200 endif
9201 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9202
Bram Moolenaarff034192013-04-24 18:51:19 +02009203" call Dret("s:NetrwSetTgt")
9204endfun
9205
Bram Moolenaar446cb832008-06-24 21:56:24 +00009206" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009207" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009208fun! s:NetrwSortStyle(islocal)
9209" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009210 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009211 let svpos= winsaveview()
9212" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009213
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009214 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 +01009215 NetrwKeepj norm! 0
9216 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009217" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9218 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009219
9220" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9221endfun
9222
9223" ---------------------------------------------------------------------
9224" s:NetrwSplit: mode {{{2
9225" =0 : net and o
9226" =1 : net and t
9227" =2 : net and v
9228" =3 : local and o
9229" =4 : local and t
9230" =5 : local and v
9231fun! s:NetrwSplit(mode)
9232" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9233
Bram Moolenaar97d62492012-11-15 21:28:22 +01009234 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009235 call s:SaveWinVars()
9236
9237 if a:mode == 0
9238 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009239 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009240 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009241" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009242 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009243 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009244 NetrwKeepj call s:RestoreWinVars()
9245 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009246 unlet s:didsplit
9247
9248 elseif a:mode == 1
9249 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009250 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009251" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009252 tabnew
9253 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009254 NetrwKeepj call s:RestoreWinVars()
9255 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009256 unlet s:didsplit
9257
9258 elseif a:mode == 2
9259 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009260 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009261 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009262" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009263 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009264 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009265 NetrwKeepj call s:RestoreWinVars()
9266 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 unlet s:didsplit
9268
9269 elseif a:mode == 3
9270 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009271 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009272 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009273" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009274 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009275 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009276 NetrwKeepj call s:RestoreWinVars()
9277 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278 unlet s:didsplit
9279
9280 elseif a:mode == 4
9281 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009282 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009283 let eikeep = &ei
9284 let netrw_winnr = winnr()
9285 let netrw_line = line(".")
9286 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009287 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009288 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009289 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009290 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9291 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009292 let &ei = eikeep
9293 let netrw_curdir = s:NetrwTreeDir(0)
9294" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009295 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009296 let b:netrw_curdir = netrw_curdir
9297 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009298 NetrwKeepj call s:RestoreWinVars()
9299 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009300 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009301 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009302 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9303 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009304 let &ei= eikeep
9305 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009306 unlet s:didsplit
9307
9308 elseif a:mode == 5
9309 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009310 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009311 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009312" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009313 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009314 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009315 NetrwKeepj call s:RestoreWinVars()
9316 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009317 unlet s:didsplit
9318
9319 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009320 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009321 endif
9322
Bram Moolenaar97d62492012-11-15 21:28:22 +01009323 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009324" call Dret("s:NetrwSplit")
9325endfun
9326
9327" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009328" s:NetrwTgtMenu: {{{2
9329fun! s:NetrwTgtMenu()
9330 if !exists("s:netrw_menucnt")
9331 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009332 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009333" call Dfunc("s:NetrwTgtMenu()")
9334
9335 " the following test assures that gvim is running, has menus available, and has menus enabled.
9336 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9337 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009338" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009339 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9340 endif
9341 if !exists("s:netrw_initbookhist")
9342 call s:NetrwBookHistRead()
9343 endif
9344
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009345 " try to cull duplicate entries
9346 let tgtdict={}
9347
Bram Moolenaarff034192013-04-24 18:51:19 +02009348 " target bookmarked places
9349 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009350" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009351 let cnt= 1
9352 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009353 if has_key(tgtdict,bmd)
9354 let cnt= cnt + 1
9355 continue
9356 endif
9357 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009358 let ebmd= escape(bmd,g:netrw_menu_escape)
9359 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009360" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009361 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 +02009362 let cnt= cnt + 1
9363 endfor
9364 endif
9365
9366 " target directory browsing history
9367 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009368" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009369 let histcnt = 1
9370 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009371 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009372 if exists("g:netrw_dirhist_{histcnt}")
9373 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009374 if has_key(tgtdict,histentry)
9375 let histcnt = histcnt + 1
9376 continue
9377 endif
9378 let tgtdict[histentry] = histcnt
9379 let ehistentry = escape(histentry,g:netrw_menu_escape)
9380" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009381 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 +02009382 endif
9383 let histcnt = histcnt + 1
9384 endwhile
9385 endif
9386 endif
9387" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009388endfun
9389
9390" ---------------------------------------------------------------------
9391" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9392" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009393fun! s:NetrwTreeDir(islocal)
9394" 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 +02009395" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009396" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9397" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9398" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009399" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009400
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009401 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009402 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009403" 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 +01009404 let treedir= s:treedir
9405 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009406 unlet s:prevwinopen
9407" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009408 return treedir
9409 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009410 if exists("s:prevwinopen")
9411 unlet s:prevwinopen
9412 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009413" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009414
Bram Moolenaar8d043172014-01-23 14:24:41 +01009415 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9416 let b:netrw_curdir= getcwd()
9417 endif
9418 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009419" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009420" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009421
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009422 let s:treecurpos= winsaveview()
9423" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009424" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009425
9426 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009427" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9428" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009429" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009430
9431 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009432 let curline= substitute(getline('.'),"\t -->.*$",'','')
9433 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009434" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009435 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009436" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9437 elseif curline =~ '@$'
9438" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009439 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009440" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009441 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009442" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009443 let treedir= ""
9444 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009445" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009446
9447 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009448" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9449" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009450" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009451 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009452" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009453 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009454" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9455 sil! NetrwKeepj %d _
9456" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009457 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009458" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009459" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009460 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009461" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009462
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009463" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009464" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009465" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009466
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009467 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9468" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9469" let newdir = w:netrw_treetop.'/'.potentialdir
9470" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9471" let treedir = s:NetrwTreePath(newdir)
9472" let w:netrw_treetop = newdir
9473" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9474" else
9475" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009476 if a:islocal && curline =~ '@$'
9477 if isdirectory(s:NetrwFile(potentialdir))
9478 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9479 let w:netrw_treetop = treedir
9480 endif
9481 else
9482 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9483 let treedir = s:NetrwTreePath(w:netrw_treetop)
9484 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009485 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009486" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009487
9488 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009489 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009490" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009491" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009492
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009493" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009494 return treedir
9495endfun
9496
9497" ---------------------------------------------------------------------
9498" s:NetrwTreeDisplay: recursive tree display {{{2
9499fun! s:NetrwTreeDisplay(dir,depth)
9500" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9501
9502 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009503 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009504
9505 " install ../ and shortdir
9506 if a:depth == ""
9507 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009508" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009509 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009510 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009511 if a:dir == w:netrw_treetop
9512 let shortdir= a:dir
9513 else
9514 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9515 endif
9516 call setline(line("$")+1,a:depth.shortdir)
9517 else
9518 let shortdir= substitute(a:dir,'^.*/','','e')
9519 call setline(line("$")+1,a:depth.shortdir.'/')
9520 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009521" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009522 " append a / to dir if its missing one
9523 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009524
9525 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009526 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009527" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009528
Bram Moolenaar85850f32019-07-19 22:05:51 +02009529 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9530 if g:netrw_hide == 1
9531 " hide given patterns
9532 let listhide= split(g:netrw_list_hide,',')
9533" call Decho("listhide=".string(listhide))
9534 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009535 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009536 endfor
9537
9538 elseif g:netrw_hide == 2
9539 " show given patterns (only)
9540 let listhide= split(g:netrw_list_hide,',')
9541" call Decho("listhide=".string(listhide))
9542 let entries=[]
9543 for entry in w:netrw_treedict[dir]
9544 for pat in listhide
9545 if entry =~ pat
9546 call add(entries,entry)
9547 break
9548 endif
9549 endfor
9550 endfor
9551 let w:netrw_treedict[dir]= entries
9552 endif
9553 if depth != ""
9554 " always remove "." and ".." entries when there's depth
9555 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9556 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9557 endif
9558
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009559" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009560 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009561 if dir =~ '/$'
9562 let direntry= substitute(dir.entry,'[@/]$','','e')
9563 else
9564 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9565 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009566" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009567 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009568" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009569 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009570 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009571" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9572 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9573 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9574" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009575 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009576 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009577" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009578 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009579 endif
9580 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009581" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009582
Bram Moolenaar446cb832008-06-24 21:56:24 +00009583" call Dret("NetrwTreeDisplay")
9584endfun
9585
9586" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009587" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9588fun! s:NetrwRefreshTreeDict(dir)
9589" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009590 if !exists("w:netrw_treedict")
9591" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9592 return
9593 endif
9594
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009595 for entry in w:netrw_treedict[a:dir]
9596 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9597" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9598
9599 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9600" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9601 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009602 let liststar = s:NetrwGlob(direntry,'*',1)
9603 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009604 let w:netrw_treedict[direntry] = liststar + listdotstar
9605" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9606
9607 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9608" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9609 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009610 let liststar = s:NetrwGlob(direntry.'/','*',1)
9611 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009612 let w:netrw_treedict[direntry]= liststar + listdotstar
9613" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9614
9615 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9616" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9617 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009618 let liststar = s:NetrwGlob(direntry.'/','*',1)
9619 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009620" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9621
9622 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009623" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009624 endif
9625 endfor
9626" call Dret("s:NetrwRefreshTreeDict")
9627endfun
9628
9629" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009630" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009631" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009632fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009633 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009634" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009635" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9636" 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>"))
9637" 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 +00009638
9639 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009640 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009641" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009642 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009643 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009644" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009645 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 +02009646" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009647 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009648 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009649" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009650 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009651 if exists("w:netrw_treetop")
9652 let s:netrw_treetop= w:netrw_treetop
9653 else
9654 let w:netrw_treetop= getcwd()
9655 let s:netrw_treetop= w:netrw_treetop
9656 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009657
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009659 " insure that we have a treedict, albeit empty
9660" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009661 let w:netrw_treedict= {}
9662 endif
9663
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009664 " update the dictionary for the current directory
9665" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009666" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009667 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009668 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009669" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009670 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009671
9672 " if past banner, record word
9673 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9674 let fname= expand("<cword>")
9675 else
9676 let fname= ""
9677 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009678" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9679" 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 +00009680
9681 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009682" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009683 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009684" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009685
9686 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9687 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009688" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009689 1d
9690 endwhile
9691
Bram Moolenaar13600302014-05-22 18:26:40 +02009692 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009693
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009694" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009695 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009696 endif
9697endfun
9698
9699" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009700" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009701" Normally, treetop is w:netrw_treetop, but a
9702" user of the function ( netrw#SetTreetop() )
9703" wipes that out prior to calling this function
9704fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009705" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9706 if line(".") < w:netrw_bannercnt + 2
9707 let treedir= a:treetop
9708 if treedir !~ '/$'
9709 let treedir= treedir.'/'
9710 endif
9711" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9712 return treedir
9713 endif
9714
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009715 let svpos = winsaveview()
9716" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009717 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009718" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009719 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009720" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9721 let curline= getline('.')
9722" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9723 if curline =~ '/$'
9724" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9725 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9726" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9727 elseif curline =~ '@\s\+-->'
9728" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9729 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9730 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9731" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009732 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009733" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009734 let treedir= ""
9735 endif
9736 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009737" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9738" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009739 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9740 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9741 let treedir= dirname.treedir
9742 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009743" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009744 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009745" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009746 if a:treetop =~ '/$'
9747 let treedir= a:treetop.treedir
9748 else
9749 let treedir= a:treetop.'/'.treedir
9750 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009751" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009752 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009753" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009754" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9755 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009756" call Dret("s:NetrwTreePath <".treedir.">")
9757 return treedir
9758endfun
9759
9760" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009761" s:NetrwWideListing: {{{2
9762fun! s:NetrwWideListing()
9763
9764 if w:netrw_liststyle == s:WIDELIST
9765" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9766 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009767 " cpf: characters per filename
9768 " fpl: filenames per line
9769 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009770 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009771 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009772" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009773 let b:netrw_cpf= 0
9774 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009775 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009776 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9777 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009778 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009779 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009780" call Dret("NetrwWideListing")
9781 return
9782 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009783 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009784 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009785" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009786
9787 " determine qty files per line (fpl)
9788 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9789 if w:netrw_fpl <= 0
9790 let w:netrw_fpl= 1
9791 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009792" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009793
9794 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009795 " fpc: files per column of wide listing
9796 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009797 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009798 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9799 let newcolstart = w:netrw_bannercnt + fpc
9800 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009801" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009802 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009803" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009804 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009805 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009806 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009807 while line("$") >= newcolstart
9808 if newcolend > line("$") | let newcolend= line("$") | endif
9809 let newcolqty= newcolend - newcolstart
9810 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009811 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009812 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009813 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009814 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009815 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009816 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009817 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009818 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009819 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009820 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009821" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009822 if @* != keepregstar | sil! let @* = keepregstar | endif
9823 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009824 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009825 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9826 NetrwKeepj call histdel("/",-1)
9827 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9828 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009829" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009830 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009831 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009832" 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 +00009833" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009834 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009835 else
9836 if hasmapto("w","n")
9837 sil! nunmap <buffer> w
9838 endif
9839 if hasmapto("b","n")
9840 sil! nunmap <buffer> b
9841 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009842 endif
9843
9844endfun
9845
9846" ---------------------------------------------------------------------
9847" s:PerformListing: {{{2
9848fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009849" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9850" 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 +02009851" 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>"))
9852 sil! NetrwKeepj %d _
9853" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009854
Bram Moolenaar15146672011-10-20 22:22:38 +02009855 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009856" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009857 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009858
Bram Moolenaar85850f32019-07-19 22:05:51 +02009859 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009860 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009861" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009862
9863" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009864" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009865" endif " Decho
9866
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009867" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009868 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9869 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009870" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9871 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009872 endif
9873
9874 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009875 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009876
9877 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009878 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009879" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009880 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009881 if exists("g:netrw_pchk")
9882 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9883 " failure detections.
9884 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009885 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009886 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9887 endif
9888 if exists("g:netrw_pchk")
9889 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9890 else
9891 let curdir= b:netrw_curdir
9892 endif
9893 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9894 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9895 else
9896 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009897 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009898 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009899 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009900 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009901" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009902 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009903 let w:netrw_bannercnt= 1
9904 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009905" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9906" 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 +00009907
Bram Moolenaar85850f32019-07-19 22:05:51 +02009908 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009909 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009910 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009911 let sortby= sortby." reversed"
9912 endif
9913
9914 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009915 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009916" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009917 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009918" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009919 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009920 NetrwKeepj put ='\" Sorted by '.sortby
9921 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009922 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9923 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009924" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009925 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009926 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009927 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9928 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009929 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009930" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009931" 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 +00009932 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009933
Bram Moolenaar85850f32019-07-19 22:05:51 +02009934 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009935 if g:netrw_banner
9936 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009937" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009938 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009939 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009940 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009941 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009942 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009943 endif
9944 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009945 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009946" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009947 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009948 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009949 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009950
9951 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009952 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009953" 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 +01009954 if g:netrw_list_hide != "" && g:netrw_hide
9955 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009956 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009957 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009958 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009959 endif
9960 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009961 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009962 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009963
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009964" 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 +01009965 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009966" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009967 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009968" 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 +01009969 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009970 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009971" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009972" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009973 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009974
9975 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009976 if g:netrw_banner
9977 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009978 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009979" 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 +01009980" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009981" 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 +01009982 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009983
Bram Moolenaar446cb832008-06-24 21:56:24 +00009984 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009985" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009986 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009987 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009988 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009989 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009990 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009991" 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 +01009992" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9993 return
9994 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009995 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009996
9997 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009998 if !exists("w:netrw_bannercnt")
9999 let w:netrw_bannercnt= 0
10000 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010001" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10002" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10003" 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 +010010004
Bram Moolenaar5c736222010-01-06 20:54:52 +010010005 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010006" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010007" 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 +000010008 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010009 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010010 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010011 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010012" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010013
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010014 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010015 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010016" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010017 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018
Bram Moolenaar5c736222010-01-06 20:54:52 +010010019 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010020" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010021 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010022 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010023 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010024 else
10025 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010026 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010027 endif
10028 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010029
Bram Moolenaar446cb832008-06-24 21:56:24 +000010030 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010031" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010032 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10033 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010034
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010035 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010036 " exten: sort by extension
10037 " The histdel(...,-1) calls remove the last search from the search history
10038" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010039 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10040 NetrwKeepj call histdel("/",-1)
10041 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10042 NetrwKeepj call histdel("/",-1)
10043 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10044 NetrwKeepj call histdel("/",-1)
10045 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10046" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010047 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010048 " normal direction sorting
10049 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10050 else
10051 " reverse direction sorting
10052 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10053 endif
10054 endif
10055 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10056 NetrwKeepj call histdel("/",-1)
10057
Bram Moolenaar446cb832008-06-24 21:56:24 +000010058 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010059 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010060" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010061 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010062" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010063 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010064 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010065" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010066 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010067 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010068" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010069 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10070 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010071 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010072 endif
10073
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010074 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010075" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010076 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010077 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010078 call histdel("/",-1)
10079 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010080 endif
10081 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010082" 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 +000010083
10084 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010085" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10086" 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 +010010087 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010088" 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 +010010089 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010090" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#3)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010091
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010092 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010093 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010094" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010095 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010096 endif
10097
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010098 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010099 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010100" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10101 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010102 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010103" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10104 else
10105" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10106" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10107" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10108" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010109 endif
10110
10111 " record previous current directory
10112 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010113" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010114
10115 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010116" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10117" 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 +010010118 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010119" 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 +020010120 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010121" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#6)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010122
10123 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010124" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010125 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010126" 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 +010010127 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010128" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010129 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10130 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010131" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010132" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010133
Bram Moolenaar8d043172014-01-23 14:24:41 +010010134 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010135" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10136" 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 +010010137" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10138 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010139 unlet s:treecurpos
10140 endif
10141
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010142" 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>"))
10143" 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 +000010144" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10145endfun
10146
10147" ---------------------------------------------------------------------
10148" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010149fun! s:SetupNetrwStatusLine(statline)
10150" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10151
10152 if !exists("s:netrw_setup_statline")
10153 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010154" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010155
10156 if !exists("s:netrw_users_stl")
10157 let s:netrw_users_stl= &stl
10158 endif
10159 if !exists("s:netrw_users_ls")
10160 let s:netrw_users_ls= &laststatus
10161 endif
10162
10163 " set up User9 highlighting as needed
10164 let keepa= @a
10165 redir @a
10166 try
10167 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010168 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010169 if &bg == "dark"
10170 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10171 else
10172 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10173 endif
10174 endtry
10175 redir END
10176 let @a= keepa
10177 endif
10178
10179 " set up status line (may use User9 highlighting)
10180 " insure that windows have a statusline
10181 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010182 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010183 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010184" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010185 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010186
10187" call Dret("SetupNetrwStatusLine : stl=".&stl)
10188endfun
10189
Bram Moolenaar85850f32019-07-19 22:05:51 +020010190" =========================================
10191" Remote Directory Browsing Support: {{{1
10192" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010193
10194" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010195" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10196" This function assumes that a long listing will be received. Size, time,
10197" and reverse sorts will be requested of the server but not otherwise
10198" enforced here.
10199fun! s:NetrwRemoteFtpCmd(path,listcmd)
10200" 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 +010010201" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010202 " sanity check: {{{3
10203 if !exists("w:netrw_method")
10204 if exists("b:netrw_method")
10205 let w:netrw_method= b:netrw_method
10206 else
10207 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10208" call Dret("NetrwRemoteFtpCmd")
10209 return
10210 endif
10211 endif
10212
10213 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10214 let ffkeep= &ff
10215 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010216" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010217
10218 " clear off any older non-banner lines " {{{3
10219 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010220" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10221 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010222
10223 ".........................................
10224 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10225 " ftp + <.netrc>: Method #2
10226 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010227 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010228 endif
10229 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010230 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010231" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010232 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010233 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010234" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010235 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010236" 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>"))
10237 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 +010010238 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010239" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10240 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 +010010241 endif
10242
10243 ".........................................
10244 elseif w:netrw_method == 3 " {{{3
10245 " ftp + machine,id,passwd,filename: Method #3
10246 setl ff=unix
10247 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010248 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010249 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010250 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010251 endif
10252
10253 " handle userid and password
10254 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010255" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010256 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10257 call NetUserPass("ftp:".host)
10258 endif
10259 if exists("g:netrw_uid") && g:netrw_uid != ""
10260 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010261 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010262 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010263 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010264 endif
10265 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010266 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010267 endif
10268 endif
10269
10270 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010271 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010272 endif
10273 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010274 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010275" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010276 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010277 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010278
10279 " perform ftp:
10280 " -i : turns off interactive prompting from ftp
10281 " -n unix : DON'T use <.netrc>, even though it exists
10282 " -n win32: quit being obnoxious about password
10283 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010284" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010285 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010286" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010287" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10288" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010289 endif
10290
10291 ".........................................
10292 elseif w:netrw_method == 9 " {{{3
10293 " sftp username@machine: Method #9
10294 " s:netrw_sftp_cmd
10295 setl ff=unix
10296
10297 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010298 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010299" call Dret("NetrwRemoteFtpCmd")
10300 return
10301
10302 ".........................................
10303 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010304 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010305 endif
10306
10307 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010308 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010309 sil! NetrwKeepj %s/\r$//e
10310 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010311 endif
10312 if a:listcmd == "dir"
10313 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010314 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10315 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10316 NetrwKeepj call histdel("/",-1)
10317 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010318 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 +010010319 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10320 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010321 endif
10322 endif
10323
10324 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10325 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010326 exe 'NetrwKeepj '.w:netrw_bannercnt
10327 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010328 endif
10329 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010330 exe 'NetrwKeepj '.w:netrw_bannercnt
10331 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010332 endif
10333
10334 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010335 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010336" call Dret("NetrwRemoteFtpCmd")
10337endfun
10338
10339" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010340" s:NetrwRemoteListing: {{{2
10341fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010342" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010343
Bram Moolenaara6878372014-03-22 21:02:50 +010010344 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10345 let w:netrw_bannercnt= s:bannercnt
10346 endif
10347 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010348 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010349 endif
10350
Bram Moolenaar446cb832008-06-24 21:56:24 +000010351 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010352
Bram Moolenaar446cb832008-06-24 21:56:24 +000010353 " sanity check:
10354 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010355" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010356 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010357" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010358 if !exists("g:netrw_quiet")
10359 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10360 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010361 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010362" call Dret("s:NetrwRemoteListing -1")
10363 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010364 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010365
Bram Moolenaar8d043172014-01-23 14:24:41 +010010366 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010367" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010368 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010369 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010370 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 +000010371 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010372 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 +000010373 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010374 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010375
Bram Moolenaar85850f32019-07-19 22:05:51 +020010376 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010377" call Dret("s:NetrwRemoteListing -1")
10378 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010379 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010380" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010381
Bram Moolenaar446cb832008-06-24 21:56:24 +000010382 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010383" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010384 let w:netrw_method= b:netrw_method
10385 endif
10386
Bram Moolenaar13600302014-05-22 18:26:40 +020010387 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010388 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010389" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010390 let s:method = "ftp"
10391 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010392 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010393 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010394 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010395 let listcmd= g:netrw_ftp_sizelist_cmd
10396 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010397" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010398 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010399" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010400
Bram Moolenaara6878372014-03-22 21:02:50 +010010401 " report on missing file or directory messages
10402 if search('[Nn]o such file or directory\|Failed to change directory')
10403 let mesg= getline(".")
10404 if exists("w:netrw_bannercnt")
10405 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010406 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010407 setl noma
10408 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010409 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010410 call netrw#ErrorMsg(s:WARNING,mesg,96)
10411" call Dret("s:NetrwRemoteListing : -1")
10412 return -1
10413 endif
10414
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010415 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 +000010416 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010417" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010418 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010419
10420 " cleanup
10421 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010422 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10423 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010424 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010425 sil! NetrwKeepj %s/\r$//e
10426 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010427
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010428 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010429 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010430 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010431 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010432" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010433 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010434" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010435 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010436 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010437 exe "sil! NetrwKeepj ".line1
10438 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010439
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010440" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010441 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010442" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010443 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10444 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010445 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010446" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010447 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10448 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10449 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10450 NetrwKeepj call histdel("/",-1)
10451 NetrwKeepj call histdel("/",-1)
10452 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010453 endif
10454 endif
10455
Bram Moolenaar13600302014-05-22 18:26:40 +020010456 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010457 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010458" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010459 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010460" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010461 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010462" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10463 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010464 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010465 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10466 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10467 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10468 NetrwKeepj call histdel("/",-1)
10469 NetrwKeepj call histdel("/",-1)
10470 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010471 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010472 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10473 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010474 endif
10475 else
10476 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010477" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010478 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010480" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10481 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10482" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010483 endif
10484 endif
10485
10486 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010487 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010488" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010489 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10490 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010491 endif
10492 endif
10493
10494 if w:netrw_liststyle == s:LONGLIST
10495 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010496" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497
10498 if s:method == "ftp"
10499 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010500 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010501 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010502 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010503 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010504 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010505 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010506 sil! NetrwKeepj 1
10507 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010508 let line2= line(".")
10509 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010510 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010511 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010512 endif
10513 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010514 exe "sil! NetrwKeepj ".line1
10515 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010516 endif
10517
10518 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010519" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010520 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 +000010521 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010522" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010523 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010524 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010525 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10526 NetrwKeepj call histdel("/",-1)
10527 NetrwKeepj call histdel("/",-1)
10528 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010529 endif
10530 endif
10531
10532" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010533" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010534" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010535
10536" call Dret("s:NetrwRemoteListing 0")
10537 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010538endfun
10539
Bram Moolenaar446cb832008-06-24 21:56:24 +000010540" ---------------------------------------------------------------------
10541" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10542fun! s:NetrwRemoteRm(usrhost,path) range
10543" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010544" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010545 let svpos= winsaveview()
10546" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010547
10548 let all= 0
10549 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10550 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010551" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010552 for fname in s:netrwmarkfilelist_{bufnr("%")}
10553 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010554 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010555 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010556 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010557 let all= 1
10558 endif
10559 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010560 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010561
10562 else
10563 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010564" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010565
10566 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010567 let keepsol = &l:sol
10568 setl nosol
10569 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570
10571 " remove multiple files and directories
10572 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010573 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010574 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010575 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010576 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010577 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578 let all= 1
10579 endif
10580 let ctr= ctr + 1
10581 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010582 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010583 endif
10584
10585 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010586" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010587 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010588" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10589 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010590
10591" call Dret("s:NetrwRemoteRm")
10592endfun
10593
10594" ---------------------------------------------------------------------
10595" s:NetrwRemoteRmFile: {{{2
10596fun! s:NetrwRemoteRmFile(path,rmfile,all)
10597" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10598
10599 let all= a:all
10600 let ok = ""
10601
10602 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10603 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010604" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010605 if !all
10606 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010607" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010608 call inputsave()
10609 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10610 call inputrestore()
10611 echohl NONE
10612 if ok == ""
10613 let ok="no"
10614 endif
10615 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010616 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010617 let all= 1
10618 endif
10619 endif
10620
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010621 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010622" 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 +000010623 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010624" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010625 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010626 if path =~ '^\a\{3,}://'
10627 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010628 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010629 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010630 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10631 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010632" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010633 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010634" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010635 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010636 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010637 let ok="q"
10638 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010639 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010640" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10641" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10642" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010643 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010644 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010645 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010646 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010647 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010648" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010649 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010650 if v:shell_error != 0
10651 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010652 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 +010010653 else
10654 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10655 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010656 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010657 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010658 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010659" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010660 endif
10661 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010662 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010663" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010664 endif
10665
10666 else
10667 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010669 if !all
10670 call inputsave()
10671 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10672 call inputrestore()
10673 if ok == ""
10674 let ok="no"
10675 endif
10676 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010677 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010678 let all= 1
10679 endif
10680 endif
10681
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010682 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010683 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010684 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010685 else
10686 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010687 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10688" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010689 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010690" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010691
10692 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010693" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10694 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10695" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010696 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010697" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010698
10699 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010700 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010701 endif
10702 endif
10703 endif
10704
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010705 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010706" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010707 endif
10708 endif
10709
10710" call Dret("s:NetrwRemoteRmFile ".ok)
10711 return ok
10712endfun
10713
10714" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010715" s:NetrwRemoteRename: rename a remote file or directory {{{2
10716fun! s:NetrwRemoteRename(usrhost,path) range
10717" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10718
10719 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010720 let svpos = winsaveview()
10721" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010722 let ctr = a:firstline
10723 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10724
10725 " rename files given by the markfilelist
10726 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10727 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010728" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010729 if exists("subfrom")
10730 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010731" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010732 else
10733 call inputsave()
10734 let newname= input("Moving ".oldname." to : ",oldname)
10735 call inputrestore()
10736 if newname =~ '^s/'
10737 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10738 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10739 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010740" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010741 endif
10742 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010743
Bram Moolenaar446cb832008-06-24 21:56:24 +000010744 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010745 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010746 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010747 let oldname= s:ShellEscape(a:path.oldname)
10748 let newname= s:ShellEscape(a:path.newname)
10749" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010750 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010751 endif
10752
10753 endfor
10754 call s:NetrwUnMarkFile(1)
10755
10756 else
10757
10758 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010759 let keepsol= &l:sol
10760 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010761 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010762 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010763
10764 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010766
10767 call inputsave()
10768 let newname= input("Moving ".oldname." to : ",oldname)
10769 call inputrestore()
10770
10771 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10772 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10773 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010774 let oldname= s:ShellEscape(a:path.oldname)
10775 let newname= s:ShellEscape(a:path.newname)
10776" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010777 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010778 endif
10779
10780 let ctr= ctr + 1
10781 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010782 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010783 endif
10784
10785 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010786 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010787" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10788 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010789
10790" call Dret("NetrwRemoteRename")
10791endfun
10792
Bram Moolenaar85850f32019-07-19 22:05:51 +020010793" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010794" Local Directory Browsing Support: {{{1
10795" ==========================================
10796
10797" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010798" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010799" Should accept: file://localhost/etc/fstab
10800" file:///etc/fstab
10801" file:///c:/WINDOWS/clock.avi
10802" file:///c|/WINDOWS/clock.avi
10803" file://localhost/c:/WINDOWS/clock.avi
10804" file://localhost/c|/WINDOWS/clock.avi
10805" file://c:/foo.txt
10806" file:///c:/foo.txt
10807" 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 +020010808fun! netrw#FileUrlEdit(fname)
10809" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010810 let fname = a:fname
10811 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010812" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010813 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010814" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010815 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010816 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010817 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010818" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010819 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010820" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010821 endif
10822 endif
10823 let fname2396 = netrw#RFC2396(fname)
10824 let fname2396e= fnameescape(fname2396)
10825 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010826 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010827" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010828 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010829" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010830 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10831 endif
10832 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010833
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010834" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10835" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010836 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010837 exe 'NetrwKeepj keepalt edit '.plainfname
10838 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10839
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010840" 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 +020010841" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010842 exe "sil doau BufReadPost ".fname2396e
10843endfun
10844
10845" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010846" netrw#LocalBrowseCheck: {{{2
10847fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010848 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010849 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10850 "
10851 " unfortunate interaction -- split window debugging can't be used here, must use
10852 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10853 " another call to LocalBrowseCheck() when attempts to write
10854 " to the DBG buffer are made.
10855 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010856 " The &ft == "netrw" test was installed because the BufEnter event
10857 " would hit when re-entering netrw windows, creating unexpected
10858 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010859" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010860" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010861" 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 +010010862 " getting E930: Cannot use :redir inside execute
10863"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010864" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10865" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010866
Bram Moolenaar97d62492012-11-15 21:28:22 +010010867 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010868 if isdirectory(s:NetrwFile(a:dirname))
10869" 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 +010010870
Bram Moolenaar97d62492012-11-15 21:28:22 +010010871 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010872" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10873" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010874 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010875
Bram Moolenaar446cb832008-06-24 21:56:24 +000010876 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010877" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010878 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010879
Bram Moolenaar5c736222010-01-06 20:54:52 +010010880 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010881" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010882 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010883 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010884 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010885" 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 +010010886" call Dret("netrw#LocalBrowseCheck")
10887 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010888 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010889
Bram Moolenaar85850f32019-07-19 22:05:51 +020010890 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010891 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10892 " AND IF the listing style is not a tree listing
10893 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010894" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010895 let ibuf = 1
10896 let buflast = bufnr("$")
10897 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010898 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10899 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010900 endif
10901 let ibuf= ibuf + 1
10902 endwhile
10903 endif
10904 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010905" 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>"))
10906" 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 +000010907 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010908" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010909endfun
10910
10911" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010912" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010913" performed any shell command. The idea is to cause all local-browsing
10914" buffers to be refreshed after a user has executed some shell command,
10915" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010916fun! s:LocalBrowseRefresh()
10917" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010918" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10919" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010920
Bram Moolenaar446cb832008-06-24 21:56:24 +000010921 " determine which buffers currently reside in a tab
10922 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010923" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010924 return
10925 endif
10926 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010927" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010928 return
10929 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010930 if !empty(getcmdwintype())
10931 " cannot move away from cmdline window, see :h E11
10932 return
10933 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010934 if exists("s:netrw_events") && s:netrw_events == 1
10935 " s:LocalFastBrowser gets called (indirectly) from a
10936 let s:netrw_events= 2
10937" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10938 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010939 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010940 let itab = 1
10941 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010942 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010943 while itab <= tabpagenr("$")
10944 let buftablist = buftablist + tabpagebuflist()
10945 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010946 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010947 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010948" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10949" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010950 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10951 " | refresh any netrw window
10952 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010953 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010954 let ibl = 0
10955 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010956" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010957 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10958 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010959 " (ibuf not shown in a current window AND
10960 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010961" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10962 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010963 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010964" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 continue
10966 elseif index(tabpagebuflist(),ibuf) != -1
10967 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010968" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010969 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010970 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010971 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10972 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10973 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10974 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010975" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010976 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10977 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10978 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010979 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010980 endif
10981 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010982" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010983 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010984" call Decho("restore window: win_gotoid(".curwinid.")")
10985 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010986 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010987
Bram Moolenaara6878372014-03-22 21:02:50 +010010988" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010989endfun
10990
10991" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010992" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10993"
10994" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010995" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010996" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10997" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010998" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010999"
11000" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11001" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011002" (re-using a buffer may not be as accurate)
11003"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011004" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011005" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11006" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11007" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11008" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011009fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011010" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11011" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11012" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11013" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011014
11015 " initialize browselist, a list of buffer numbers that the local browser has used
11016 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011017" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011018 let s:netrw_browselist= []
11019 endif
11020
11021 " append current buffer to fastbrowse list
11022 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011023" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011024 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011025" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011026 endif
11027
11028 " enable autocmd events to handle refreshing/removing local browser buffers
11029 " If local browse buffer is currently showing: refresh it
11030 " If local browse buffer is currently hidden : wipe it
11031 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11032 " =1 : medium speed, re-use directory listing for remote only
11033 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011034 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11035 let s:netrw_events= 1
11036 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011037 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011038 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011039" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011040 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011041 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011042" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011043 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011044 endif
11045 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011046
11047 " user must have changed fastbrowse to its fast setting, so remove
11048 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011049 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011050" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011051 unlet s:netrw_events
11052 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011053 au!
11054 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011055 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011056 endif
11057
Bram Moolenaar85850f32019-07-19 22:05:51 +020011058" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011059endfun
11060
11061" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011062" s:LocalListing: does the job of "ls" for local directories {{{2
11063fun! s:LocalListing()
11064" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011065" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11066" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11067" 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 +010011068
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011069" 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
11070" 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
11071" 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 +010011072
11073 " get the list of files contained in the current directory
11074 let dirname = b:netrw_curdir
11075 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011076 let filelist = s:NetrwGlob(dirname,"*",0)
11077 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011078" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011079
Nir Lichtman1e34b952024-05-08 19:19:34 +020011080 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011081" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011082 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11083 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011084" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011085 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011086" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011087 endif
11088
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011089" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011090" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011091" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011092
11093 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11094 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11095 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011096" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11097" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011098 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011099" 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 +010011100
11101 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011102" call Decho(" ",'~'.expand("<slnum>"))
11103" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011104
11105 if getftype(filename) == "link"
11106 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011107" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011108 let pfile= filename."@"
11109
11110 elseif getftype(filename) == "socket"
11111 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011112" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011113 let pfile= filename."="
11114
11115 elseif getftype(filename) == "fifo"
11116 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011117" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011118 let pfile= filename."|"
11119
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011120 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011121 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011122" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011123 let pfile= filename."/"
11124
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011125 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011126 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011127 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11128 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011129" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011130 let pfile= filename."*"
11131 else
11132 " normal file
11133 let pfile= filename
11134 endif
11135 elseif executable(filename)
11136 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011137" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011138 let pfile= filename."*"
11139 else
11140 " normal file
11141 let pfile= filename
11142 endif
11143
11144 else
11145 " normal file
11146 let pfile= filename
11147 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011148" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011149
11150 if pfile =~ '//$'
11151 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011152" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011153 endif
11154 let pfile= strpart(pfile,dirnamelen)
11155 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011156" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11157" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011158
11159 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011160 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11161 let sz = getfsize(filename)
11162 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11163 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011164
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011165 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011166 let sz= s:NetrwHumanReadable(sz)
11167 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011168 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011169 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011170" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011171 endif
11172
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011173 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011174 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011175 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011176" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011177" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011178 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011179 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011180" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011181 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011182 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011183
11184 elseif g:netrw_sort_by =~ "^s"
11185 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011186" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011187" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011188 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011189 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011190" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011191 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011192 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011193
11194 else
11195 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011196" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011197" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011198 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011199 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011200" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011201 endfor
11202
11203 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011204 sil! NetrwKeepj g/^$/d
11205 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011206 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011207" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011208 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11209
11210" call Dret("s:LocalListing")
11211endfun
11212
11213" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011214" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11215fun! s:NetrwLocalExecute(cmd)
11216" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11217 let ykeep= @@
11218 " sanity check
11219 if !executable(a:cmd)
11220 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11221 let @@= ykeep
11222" call Dret("s:NetrwLocalExecute")
11223 return
11224 endif
11225
11226 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011227" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011228 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011229" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011230
11231 " strip any ansi escape sequences off
11232 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11233
11234 " show user the result(s)
11235 echomsg result
11236 let @@= ykeep
11237
11238" call Dret("s:NetrwLocalExecute")
11239endfun
11240
11241" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011242" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011243fun! s:NetrwLocalRename(path) range
11244" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11245
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011246 if !exists("w:netrw_bannercnt")
11247 let w:netrw_bannercnt= b:netrw_bannercnt
11248 endif
11249
Bram Moolenaar97d62492012-11-15 21:28:22 +010011250 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011251 let ykeep = @@
11252 let ctr = a:firstline
11253 let svpos = winsaveview()
11254 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011255" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011256
11257 " rename files given by the markfilelist
11258 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11259 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011260" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011261 if exists("subfrom")
11262 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011263" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011264 else
11265 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011266 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011267 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011268 if newname =~ ''
11269 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11270 let newname = substitute(newname,'^.*','','')
11271 elseif newname =~ ''
11272 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11273 let newname = substitute(newname,'[^/]*','','')
11274 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011275 if newname =~ '^s/'
11276 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11277 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011278" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011279 let newname = substitute(oldname,subfrom,subto,'')
11280 endif
11281 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011282 if !all && filereadable(newname)
11283 call inputsave()
11284 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11285 call inputrestore()
11286 if response == "all"
11287 let all= 1
11288 elseif response != "y" && response != "yes"
11289 " refresh the directory
11290" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11291 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11292" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11293 NetrwKeepj call winrestview(svpos)
11294 let @@= ykeep
11295" call Dret("NetrwLocalRename")
11296 return
11297 endif
11298 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011299 call rename(oldname,newname)
11300 endfor
11301 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011302
Bram Moolenaar97d62492012-11-15 21:28:22 +010011303 else
11304
11305 " attempt to rename files/directories
11306 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011307 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011308
11309 " sanity checks
11310 if line(".") < w:netrw_bannercnt
11311 let ctr= ctr + 1
11312 continue
11313 endif
11314 let curword= s:NetrwGetWord()
11315 if curword == "./" || curword == "../"
11316 let ctr= ctr + 1
11317 continue
11318 endif
11319
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011320 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011321 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011322" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011323
11324 call inputsave()
11325 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11326 call inputrestore()
11327
11328 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011329" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011330
11331 let ctr= ctr + 1
11332 endwhile
11333 endif
11334
11335 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011336" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011337 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011338" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11339 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011340 let @@= ykeep
11341
11342" call Dret("NetrwLocalRename")
11343endfun
11344
11345" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011346" s:NetrwLocalRm: {{{2
11347fun! s:NetrwLocalRm(path) range
11348" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011349" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011350
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011351 if !exists("w:netrw_bannercnt")
11352 let w:netrw_bannercnt= b:netrw_bannercnt
11353 endif
11354
Bram Moolenaar446cb832008-06-24 21:56:24 +000011355 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011356 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011357 let ret = 0
11358 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011359 let svpos = winsaveview()
11360" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011361
11362 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11363 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011364" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011365 for fname in s:netrwmarkfilelist_{bufnr("%")}
11366 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011367 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011368 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011369 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011370 let all= 1
11371 endif
11372 endfor
11373 call s:NetrwUnMarkFile(1)
11374
11375 else
11376 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011377" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011378
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011379 let keepsol= &l:sol
11380 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011381 let ctr = a:firstline
11382 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011383 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011384
11385 " sanity checks
11386 if line(".") < w:netrw_bannercnt
11387 let ctr= ctr + 1
11388 continue
11389 endif
11390 let curword= s:NetrwGetWord()
11391 if curword == "./" || curword == "../"
11392 let ctr= ctr + 1
11393 continue
11394 endif
11395 let ok= s:NetrwLocalRmFile(a:path,curword,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 let ctr= ctr + 1
11402 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011403 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011404 endif
11405
11406 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011407" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011408 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011409 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011410" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11411 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011412 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011413 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011414
11415" call Dret("s:NetrwLocalRm")
11416endfun
11417
11418" ---------------------------------------------------------------------
11419" s:NetrwLocalRmFile: remove file fname given the path {{{2
11420" Give confirmation prompt unless all==1
11421fun! s:NetrwLocalRmFile(path,fname,all)
11422" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011423
Bram Moolenaar446cb832008-06-24 21:56:24 +000011424 let all= a:all
11425 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011426 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011427 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11428" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011429
11430 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11431 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011432" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011433 if !all
11434 echohl Statement
11435 call inputsave()
11436 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11437 call inputrestore()
11438 echohl NONE
11439 if ok == ""
11440 let ok="no"
11441 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011442" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011443 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011444" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011445 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011446 let all= 1
11447 endif
11448 endif
11449
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011450 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011451 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011452" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011453 endif
11454
11455 else
11456 " attempt to remove directory
11457 if !all
11458 echohl Statement
11459 call inputsave()
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011460 let ok= input("Confirm *recursive* deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011461 call inputrestore()
11462 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11463 if ok == ""
11464 let ok="no"
11465 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011466 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011467 let all= 1
11468 endif
11469 endif
11470 let rmfile= substitute(rmfile,'[\/]$','','e')
11471
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011472 if all || ok =~# 'y\%[es]' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011473 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011474 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011475 endif
11476 endif
11477 endif
11478
11479" call Dret("s:NetrwLocalRmFile ".ok)
11480 return ok
11481endfun
11482
Bram Moolenaar85850f32019-07-19 22:05:51 +020011483" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011484" Support Functions: {{{1
11485
Bram Moolenaar488c6512005-08-11 20:09:58 +000011486" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011487" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11488" 0: marked file list of current buffer
11489" 1: marked file target
11490fun! netrw#Access(ilist)
11491 if a:ilist == 0
11492 if exists("s:netrwmarkfilelist_".bufnr('%'))
11493 return s:netrwmarkfilelist_{bufnr('%')}
11494 else
11495 return "no-list-buf#".bufnr('%')
11496 endif
11497 elseif a:ilist == 1
11498 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011499 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011500endfun
11501
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011502" ---------------------------------------------------------------------
11503" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11504fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011505 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011506endfun
11507
Bram Moolenaara6878372014-03-22 21:02:50 +010011508" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011509" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11510" I expect this function to be used in
11511" :PChkAssert netrw#Expose("netrwmarkfilelist")
11512" for example.
11513fun! netrw#Expose(varname)
11514" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011515 if exists("s:".a:varname)
11516 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011517" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011518 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011519" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011520 if type(retval) == 3
11521 let retval = copy(retval)
11522 let i = 0
11523 while i < len(retval)
11524 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11525 let i = i + 1
11526 endwhile
11527 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011528" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011529 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011530 else
11531" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011532 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011533 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011534" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011535 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011536 endif
11537
11538" call Dret("netrw#Expose ".string(retval))
11539 return retval
11540endfun
11541
11542" ---------------------------------------------------------------------
11543" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11544fun! netrw#Modify(varname,newvalue)
11545" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11546 exe "let s:".a:varname."= ".string(a:newvalue)
11547" call Dret("netrw#Modify")
11548endfun
11549
11550" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011551" netrw#RFC2396: converts %xx into characters {{{2
11552fun! netrw#RFC2396(fname)
11553" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011554 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011555" call Dret("netrw#RFC2396 ".fname)
11556 return fname
11557endfun
11558
11559" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011560" netrw#UserMaps: supports user-specified maps {{{2
11561" see :help function()
11562"
11563" g:Netrw_UserMaps is a List with members such as:
11564" [[keymap sequence, function reference],...]
11565"
11566" The referenced function may return a string,
11567" refresh : refresh the display
11568" -other- : this string will be executed
11569" or it may return a List of strings.
11570"
11571" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011572" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011573" Related functions:
11574" netrw#Expose(varname) -- see s:varname variables
11575" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11576" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11577fun! netrw#UserMaps(islocal)
11578" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11579" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11580
11581 " set up usermaplist
11582 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11583" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11584 for umap in g:Netrw_UserMaps
11585" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11586" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11587 " if umap[0] is a string and umap[1] is a string holding a function name
11588 if type(umap[0]) == 1 && type(umap[1]) == 1
11589" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11590 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11591 else
11592 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11593 endif
11594 endfor
11595 endif
11596" call Dret("netrw#UserMaps")
11597endfun
11598
11599" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011600" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11601fun! netrw#WinPath(path)
11602" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011603 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011604 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011605 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011606 " remove trailing slash (Win95)
11607 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11608 " remove escaped spaces
11609 let path = substitute(path, '\ ', ' ', 'g')
11610 " convert slashes to backslashes
11611 let path = substitute(path, '/', '\', 'g')
11612 else
11613 let path= a:path
11614 endif
11615" call Dret("netrw#WinPath <".path.">")
11616 return path
11617endfun
11618
11619" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011620" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11621" cb : bl2mf=0 add marked files to buffer list
11622" cB : bl2mf=1 use bufferlist to mark files
11623" (mnemonic: cb = copy (marked files) to buffer list)
11624fun! s:NetrwBadd(islocal,bl2mf)
11625" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11626 if a:bl2mf
11627 " cB: add buffer list to marked files
11628 redir => bufl
11629 ls
11630 redir END
11631 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11632 for fname in bufl
11633 call s:NetrwMarkFile(a:islocal,fname)
11634 endfor
11635 else
11636 " cb: add marked files to buffer list
11637 for fname in s:netrwmarkfilelist_{bufnr("%")}
11638" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11639 exe "badd ".fnameescape(fname)
11640 endfor
11641 let curbufnr = bufnr("%")
11642 let curdir = s:NetrwGetCurdir(a:islocal)
11643 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11644 endif
11645" call Dret("s:NetrwBadd")
11646endfun
11647
11648" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011649" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11650fun! s:ComposePath(base,subdir)
11651" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11652
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011653 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011654" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011655 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011656 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011657 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011658 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011659 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011660 endif
11661
Bram Moolenaar85850f32019-07-19 22:05:51 +020011662 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011663 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011664" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011665 let ret= a:subdir
11666
Nir Lichtman1e34b952024-05-08 19:19:34 +020011667 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011668" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011669 if a:base =~ '[/\\]$'
11670 let ret= a:base.a:subdir
11671 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011672 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011673 endif
11674
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011675 elseif a:base =~ '^\a\{3,}://'
11676" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011677 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11678 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11679 if a:subdir == '../'
11680 if curpath =~ '[^/]/[^/]\+/$'
11681 let curpath= substitute(curpath,'[^/]\+/$','','')
11682 else
11683 let curpath=""
11684 endif
11685 let ret= urlbase.curpath
11686 else
11687 let ret= urlbase.curpath.a:subdir
11688 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011689" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11690" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11691" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011692
11693 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011694" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011695 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11696 if a:base =~ '^//'
11697 " keeping initial '//' for the benefit of network share listing support
11698 let ret= '/'.ret
11699 endif
11700 let ret= simplify(ret)
11701 endif
11702
11703" call Dret("s:ComposePath ".ret)
11704 return ret
11705endfun
11706
11707" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011708" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11709" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11710fun! s:DeleteBookmark(fname)
11711" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11712 call s:MergeBookmarks()
11713
11714 if exists("g:netrw_bookmarklist")
11715 let indx= index(g:netrw_bookmarklist,a:fname)
11716 if indx == -1
11717 let indx= 0
11718 while indx < len(g:netrw_bookmarklist)
11719 if g:netrw_bookmarklist[indx] =~ a:fname
11720 call remove(g:netrw_bookmarklist,indx)
11721 let indx= indx - 1
11722 endif
11723 let indx= indx + 1
11724 endwhile
11725 else
11726 " remove exact match
11727 call remove(g:netrw_bookmarklist,indx)
11728 endif
11729 endif
11730
11731" call Dret("s:DeleteBookmark")
11732endfun
11733
11734" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011735" s:FileReadable: o/s independent filereadable {{{2
11736fun! s:FileReadable(fname)
11737" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11738
11739 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011740 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011741 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011742 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011743 endif
11744
11745" call Dret("s:FileReadable ".ret)
11746 return ret
11747endfun
11748
11749" ---------------------------------------------------------------------
11750" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11751" Places correct suffix on end of temporary filename,
11752" using the suffix provided with fname
11753fun! s:GetTempfile(fname)
11754" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11755
11756 if !exists("b:netrw_tmpfile")
11757 " get a brand new temporary filename
11758 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011759" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011760
Bram Moolenaarc236c162008-07-13 17:41:49 +000011761 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011762" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011763
Bram Moolenaar9964e462007-05-05 17:54:07 +000011764 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011765 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11766" 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 +010011767 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011768" call Dret("s:GetTempfile getcwd<".getcwd().">")
11769 return ""
11770 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011771
Bram Moolenaar9964e462007-05-05 17:54:07 +000011772 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011773 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011774" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011775
Bram Moolenaar9964e462007-05-05 17:54:07 +000011776 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011777 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011778 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011779 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011780 if !exists("+shellslash") || !&ssl
11781 let tmpfile = substitute(tmpfile,'/','\','g')
11782 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011783 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011784 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011785 endif
11786 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011787" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011788 else
11789 " re-use temporary filename
11790 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011791" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011792 endif
11793
11794 " use fname's suffix for the temporary file
11795 if a:fname != ""
11796 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011797" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011798 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011799 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011800 elseif a:fname =~ '.txz$'
11801 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011802 else
11803 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11804 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011805" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011806 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011807" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011808 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011809" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011810 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11811 endif
11812 endif
11813
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011814" 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 +000011815" call Dret("s:GetTempfile <".tmpfile.">")
11816 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011817endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011818
11819" ---------------------------------------------------------------------
11820" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011821" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011822fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011823" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011824 if s:user == ""
11825 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11826 else
11827 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11828 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011829 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011830 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011831 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011832 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011833 else
11834 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11835 endif
11836" call Dret("s:MakeSshCmd <".sshcmd.">")
11837 return sshcmd
11838endfun
11839
11840" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011841" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11842fun! s:MakeBookmark(fname)
11843" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11844
11845 if !exists("g:netrw_bookmarklist")
11846 let g:netrw_bookmarklist= []
11847 endif
11848
11849 if index(g:netrw_bookmarklist,a:fname) == -1
11850 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011851 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011852 call add(g:netrw_bookmarklist,a:fname.'/')
11853 elseif a:fname !~ '/'
11854 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11855 else
11856 call add(g:netrw_bookmarklist,a:fname)
11857 endif
11858 call sort(g:netrw_bookmarklist)
11859 endif
11860
11861" call Dret("s:MakeBookmark")
11862endfun
11863
11864" ---------------------------------------------------------------------
11865" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11866fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011867" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011868 " get bookmarks from .netrwbook file
11869 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011870 if filereadable(s:NetrwFile(savefile))
11871" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011872 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011873" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011874 NetrwKeepj call delete(savefile)
11875 endif
11876" call Dret("s:MergeBookmarks")
11877endfun
11878
11879" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011880" s:NetrwBMShow: {{{2
11881fun! s:NetrwBMShow()
11882" call Dfunc("s:NetrwBMShow()")
11883 redir => bmshowraw
11884 menu
11885 redir END
11886 let bmshowlist = split(bmshowraw,'\n')
11887 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011888 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011889 if bmshowfuncs != []
11890 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011891 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011892 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011893 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011894 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011895 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011896" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11897endfun
11898
11899" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011900" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011901fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011902 if !exists("w:netrw_liststyle")
11903 let w:netrw_liststyle= g:netrw_liststyle
11904 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011905" 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 +020011906
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011907" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11908
Bram Moolenaaradc21822011-04-01 18:03:16 +020011909 if &ft != "netrw"
11910 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11911 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011912" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011913
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011914 elseif g:netrw_cursor == 8
11915 if w:netrw_liststyle == s:WIDELIST
11916 setl cursorline
11917 setl cursorcolumn
11918 else
11919 setl cursorline
11920 endif
11921 elseif g:netrw_cursor == 7
11922 setl cursorline
11923 elseif g:netrw_cursor == 6
11924 if w:netrw_liststyle == s:WIDELIST
11925 setl cursorline
11926 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011927 elseif g:netrw_cursor == 4
11928 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011929" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011930 setl cursorline
11931 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011932
11933 elseif g:netrw_cursor == 3
11934 " thin-long-tree: cursorline, user's cursorcolumn
11935 " wide : cursorline, cursorcolumn
11936 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011937" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011938 setl cursorline
11939 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011940 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011941" 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 +020011942 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011943 endif
11944
11945 elseif g:netrw_cursor == 2
11946 " thin-long-tree: cursorline, user's cursorcolumn
11947 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011948" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011949 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011950
11951 elseif g:netrw_cursor == 1
11952 " thin-long-tree: user's cursorline, user's cursorcolumn
11953 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011954 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011955" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011956 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011957 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011958" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011959 endif
11960
11961 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011962 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011963" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011964 let &l:cursorline = s:netrw_usercul
11965 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011966 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011967
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011968" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011969" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011970endfun
11971
11972" ---------------------------------------------------------------------
11973" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11974fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011975" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011976 if exists("s:netrw_usercul")
11977 let &l:cursorline = s:netrw_usercul
11978 endif
11979 if exists("s:netrw_usercuc")
11980 let &l:cursorcolumn = s:netrw_usercuc
11981 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011982" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011983" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11984endfun
11985
11986" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011987" s:NetrwDelete: Deletes a file. {{{2
11988" Uses Steve Hall's idea to insure that Windows paths stay
11989" acceptable. No effect on Unix paths.
11990" Examples of use: let result= s:NetrwDelete(path)
11991fun! s:NetrwDelete(path)
11992" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11993
Bram Moolenaar5c736222010-01-06 20:54:52 +010011994 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011995 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011996 if exists("+shellslash")
11997 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011998 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011999 let result = delete(path)
12000 let &shellslash = sskeep
12001 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012002" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012003 let result= delete(path)
12004 endif
12005 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012006" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012007 let result= delete(path)
12008 endif
12009 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012010 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012011 endif
12012
12013" call Dret("s:NetrwDelete ".result)
12014 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012015endfun
12016
12017" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012018" s:NetrwBufRemover: removes a buffer that: {{{2s
12019" has buffer-id > 1
12020" is unlisted
12021" is unnamed
12022" does not appear in any window
12023fun! s:NetrwBufRemover(bufid)
12024" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12025" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12026" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12027" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12028" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12029
yasuda4dbb2662023-10-04 20:50:35 +020012030 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012031" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012032 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012033 endif
12034
12035" call Dret("s:NetrwBufRemover")
12036endfun
12037
12038" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012039" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012040fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012041" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012042" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012043
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012044 " Clean out the last buffer:
12045 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12046 " If so, delete it.
12047 call s:NetrwBufRemover(bufnr("$"))
12048
Bram Moolenaar446cb832008-06-24 21:56:24 +000012049 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012050" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012051 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12052 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12053 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12054 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12055 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12056 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12057 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12058 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12059 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12060 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12061 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12062 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12063 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12064 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12065 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12066 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12067
Bram Moolenaar85850f32019-07-19 22:05:51 +020012068 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012069" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012070 " when tree listing uses file TreeListing... a new buffer is made.
12071 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012072 " COMBAK: this causes a problem, see P43
12073" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012074 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012075 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012076 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012077" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012078 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012079
Bram Moolenaar446cb832008-06-24 21:56:24 +000012080 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012081" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012082 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12083 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12084 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12085 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12086 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12087 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12088 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12089 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12090 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12091 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12092 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12093 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12094 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12095 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12096 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12097 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12098
Bram Moolenaar5c736222010-01-06 20:54:52 +010012099 if a:0 > 0
12100 let b:netrw_curdir= a:1
12101 if b:netrw_curdir =~ '/$'
12102 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012103 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012104 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012105 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012106 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12107 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012108 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012109 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012110 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012111 endif
12112 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012113 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12114 let &l:bexpr = "netrw#BalloonHelp()"
12115 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012116
Bram Moolenaar8d043172014-01-23 14:24:41 +010012117" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012118endfun
12119
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012120" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012121" s:NetrwExe: executes a string using "!" {{{2
12122fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012123" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012124 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012125" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012126 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12127 set shell& shellcmdflag& shellxquote& shellxescape&
12128 set shellquote& shellpipe& shellredir& shellslash&
12129 exe a:cmd
12130 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12131 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012132" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012133 exe a:cmd
12134 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012135 if v:shell_error
12136 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12137 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012138" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012139endfun
12140
12141" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012142" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12143fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012144 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012145" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012146 let curbuf = bufnr("%")
12147 let curwin = winnr()
12148 let iwin = 1
12149 while iwin <= winnr("$")
12150 exe iwin."wincmd w"
12151 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12152 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12153 let winvars= w:
12154 break
12155 endif
12156 let iwin= iwin + 1
12157 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012158 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012159 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012160" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012161 for k in keys(winvars)
12162 let w:{k}= winvars[k]
12163 endfor
12164 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012165" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012166 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012167endfun
12168
Bram Moolenaara6878372014-03-22 21:02:50 +010012169" ---------------------------------------------------------------------
12170" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012171" Returns: 0=success
12172" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012173fun! s:NetrwLcd(newdir)
12174" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012175" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012176
Bram Moolenaar85850f32019-07-19 22:05:51 +020012177 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012178 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012179 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012180 catch /^Vim\%((\a\+)\)\=:E344/
12181 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12182 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012183 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012184 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12185 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012186 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012187 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12188 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012189 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012190 endif
12191 endif
12192 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012193 let err472= 1
12194 endtry
12195
12196 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012197 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12198 if exists("w:netrw_prvdir")
12199 let a:newdir= w:netrw_prvdir
12200 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012201 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012202" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012203 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012204" 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 +010012205 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012206 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012207" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12208 return -1
12209 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012210
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012211" call Decho("getcwd <".getcwd().">")
12212" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012213" call Dret("s:NetrwLcd 0")
12214 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012215endfun
12216
Bram Moolenaar9964e462007-05-05 17:54:07 +000012217" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012218" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12219" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12220fun! s:NetrwSaveWordPosn()
12221" call Dfunc("NetrwSaveWordPosn()")
12222 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12223" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12224endfun
12225
12226" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012227" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12228" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12229fun! s:NetrwHumanReadable(sz)
12230" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12231
12232 if g:netrw_sizestyle == 'h'
12233 if a:sz >= 1000000000
12234 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12235 elseif a:sz >= 10000000
12236 let sz = printf("%d",a:sz/1000000)."m"
12237 elseif a:sz >= 1000000
12238 let sz = printf("%.1f",a:sz/1000000.0)."m"
12239 elseif a:sz >= 10000
12240 let sz = printf("%d",a:sz/1000)."k"
12241 elseif a:sz >= 1000
12242 let sz = printf("%.1f",a:sz/1000.0)."k"
12243 else
12244 let sz= a:sz
12245 endif
12246
12247 elseif g:netrw_sizestyle == 'H'
12248 if a:sz >= 1073741824
12249 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12250 elseif a:sz >= 10485760
12251 let sz = printf("%d",a:sz/1048576)."M"
12252 elseif a:sz >= 1048576
12253 let sz = printf("%.1f",a:sz/1048576.0)."M"
12254 elseif a:sz >= 10240
12255 let sz = printf("%d",a:sz/1024)."K"
12256 elseif a:sz >= 1024
12257 let sz = printf("%.1f",a:sz/1024.0)."K"
12258 else
12259 let sz= a:sz
12260 endif
12261
12262 else
12263 let sz= a:sz
12264 endif
12265
12266" call Dret("s:NetrwHumanReadable ".sz)
12267 return sz
12268endfun
12269
12270" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012271" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12272" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12273fun! s:NetrwRestoreWordPosn()
12274" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012275 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012276" call Dret("NetrwRestoreWordPosn")
12277endfun
12278
12279" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012280" s:RestoreBufVars: {{{2
12281fun! s:RestoreBufVars()
12282" call Dfunc("s:RestoreBufVars()")
12283
12284 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12285 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12286 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12287 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12288 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12289 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12290
12291" call Dret("s:RestoreBufVars")
12292endfun
12293
12294" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012295" s:RemotePathAnalysis: {{{2
12296fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012297" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012298
Bram Moolenaara6878372014-03-22 21:02:50 +010012299 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012300 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012301 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012302 let s:user = substitute(a:dirname,dirpat,'\3','')
12303 let s:machine = substitute(a:dirname,dirpat,'\4','')
12304 let s:port = substitute(a:dirname,dirpat,'\5','')
12305 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012306 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012307 if s:machine =~ '@'
12308 let dirpat = '^\(.*\)@\(.\{-}\)$'
12309 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12310 let s:machine = substitute(s:machine,dirpat,'\2','')
12311 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012312
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012313" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12314" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12315" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12316" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12317" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12318" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012319
12320" call Dret("s:RemotePathAnalysis")
12321endfun
12322
12323" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012324" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12325" Returns status
12326" Runs system() on
12327" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012328" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012329fun! s:RemoteSystem(cmd)
12330" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12331 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012332 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 +000012333 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012334 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012335 else
12336 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12337 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12338 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012339 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012340 else
12341 let cmd= cmd.' '
12342 endif
12343 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012344" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012345 let ret= system(cmd)
12346 endif
12347" call Dret("s:RemoteSystem ".ret)
12348 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012349endfun
12350
12351" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012352" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012353fun! s:RestoreWinVars()
12354" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012355 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012356 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12357 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12358 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12359 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12360 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12361 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12362 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12363 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12364 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12365 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12366 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12367 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012368 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12369 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012370 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12371 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12372 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12373" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012374endfun
12375
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012376" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012377" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12378"
12379" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12380" is true) and a command, :Rexplore, which call this function.
12381"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012382" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012383"
12384" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012385fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012386 if exists("s:netrwdrag")
12387 return
12388 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012389" 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 +010012390" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12391" 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 +010012392
12393 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012394 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012395" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012396 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012397 unlet w:netrw_rexfile
12398" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012399 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012400" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012401" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12402" 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 +020012403 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012404
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012405 " ---------------------------
12406 " :Rex issued while in a file
12407 " ---------------------------
12408
Bram Moolenaara6878372014-03-22 21:02:50 +010012409 " record current file so :Rex can return to it from netrw
12410 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012411" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012412
12413 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012414" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012415 return
12416 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012417" 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 +020012418 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012419 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012420 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012421 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012422 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012423 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012424 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012425 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012426 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012427" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12428 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012429" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12430 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012431 if exists("s:rexposn_".bufnr('%'))
12432 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012433 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012434 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012435" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012436 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012437
Bram Moolenaar85850f32019-07-19 22:05:51 +020012438 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12439 if exists("s:explore_match")
12440 exe "2match netrwMarkFile /".s:explore_match."/"
12441 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012442 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012443
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012444" 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 +010012445" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012446endfun
12447
12448" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012449" s:SaveBufVars: save selected b: variables to s: variables {{{2
12450" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012451fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012452" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012453
12454 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12455 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12456 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12457 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12458 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12459 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12460
12461" call Dret("s:SaveBufVars")
12462endfun
12463
12464" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012465" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12466fun! s:SavePosn(posndict)
12467" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12468
Bram Moolenaar85850f32019-07-19 22:05:51 +020012469 if !exists("a:posndict[bufnr('%')]")
12470 let a:posndict[bufnr("%")]= []
12471 endif
12472" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12473 call add(a:posndict[bufnr("%")],winsaveview())
12474" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012475
12476" call Dret("s:SavePosn posndict")
12477 return a:posndict
12478endfun
12479
12480" ---------------------------------------------------------------------
12481" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12482fun! s:RestorePosn(posndict)
12483" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012484 if exists("a:posndict")
12485 if has_key(a:posndict,bufnr("%"))
12486" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12487 let posnlen= len(a:posndict[bufnr("%")])
12488 if posnlen > 0
12489 let posnlen= posnlen - 1
12490" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12491 call winrestview(a:posndict[bufnr("%")][posnlen])
12492 call remove(a:posndict[bufnr("%")],posnlen)
12493" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12494 endif
12495 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012496 endif
12497" call Dret("s:RestorePosn")
12498endfun
12499
12500" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012501" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012502fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012503" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012504 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12505 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12506 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12507 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12508 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12509 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12510 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12511 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12512 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12513 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12514 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12515 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12516 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12517 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12518 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12519 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12520 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12521 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12522" call Dret("s:SaveWinVars")
12523endfun
12524
12525" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012526" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012527" To allow separate windows to have their own activities, such as
12528" Explore **/pattern, several variables have been made window-oriented.
12529" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012530" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012531" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012532fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012533" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012534 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12535 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12536 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12537 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12538 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12539 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12540 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12541 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12542 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12543 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12544" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012545endfun
12546
12547" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012548" s:SetRexDir: set directory for :Rexplore {{{2
12549fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012550" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012551 let w:netrw_rexdir = a:dirname
12552 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012553 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012554" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12555" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012556" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012557" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012558" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012559endfun
12560
12561" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012562" s:ShowLink: used to modify thin and tree listings to show links {{{2
12563fun! s:ShowLink()
12564" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012565" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12566" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012567 if exists("b:netrw_curdir")
12568 norm! $?\a
12569 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12570 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012571" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12572" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12573" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12574 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012575 let dirlen = strlen(b:netrw_curdir)
12576 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012577" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012578 endif
12579 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012580" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12581" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012582 setl noro ma
12583 call setline(".",modline)
12584 setl ro noma nomod
12585 endif
12586" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12587endfun
12588
12589" ---------------------------------------------------------------------
12590" s:ShowStyle: {{{2
12591fun! s:ShowStyle()
12592 if !exists("w:netrw_liststyle")
12593 let liststyle= g:netrw_liststyle
12594 else
12595 let liststyle= w:netrw_liststyle
12596 endif
12597 if liststyle == s:THINLIST
12598 return s:THINLIST.":thin"
12599 elseif liststyle == s:LONGLIST
12600 return s:LONGLIST.":long"
12601 elseif liststyle == s:WIDELIST
12602 return s:WIDELIST.":wide"
12603 elseif liststyle == s:TREELIST
12604 return s:TREELIST.":tree"
12605 else
12606 return 'n/a'
12607 endif
12608endfun
12609
12610" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012611" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12612" Solution from Nicolai Weibull, vim docs (:help strlen()),
12613" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012614fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012615" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12616
12617 if v:version >= 703 && exists("*strdisplaywidth")
12618 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012619
Bram Moolenaar8d043172014-01-23 14:24:41 +010012620 elseif type(g:Align_xstrlen) == 1
12621 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12622 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012623
Bram Moolenaar8d043172014-01-23 14:24:41 +010012624 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012625 " number of codepoints (Latin a + combining circumflex is two codepoints)
12626 " (comment from TM, solution from NW)
12627 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012628
Bram Moolenaar8d043172014-01-23 14:24:41 +010012629 elseif g:Align_xstrlen == 2
12630 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012631 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12632 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012633 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012634
Bram Moolenaar8d043172014-01-23 14:24:41 +010012635 elseif g:Align_xstrlen == 3
12636 " virtual length (counting, for instance, tabs as anything between 1 and
12637 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012638 " preceded by lam, one otherwise, etc.)
12639 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012640 let modkeep= &l:mod
12641 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012642 call setline(line("."),a:x)
12643 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012644 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012645 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012646 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012647
Bram Moolenaar446cb832008-06-24 21:56:24 +000012648 else
12649 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012650 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012651 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012652" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012653 return ret
12654endfun
12655
12656" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012657" s:ShellEscape: shellescape(), or special windows handling {{{2
12658fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012659 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012660 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12661 endif
12662 let f = a:0 > 0 ? a:1 : 0
12663 return shellescape(a:s, f)
12664endfun
12665
12666" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012667" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012668fun! s:TreeListMove(dir)
12669" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012670 let curline = getline('.')
12671 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12672 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12673 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12674 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12675 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12676 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12677" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12678" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12679" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12680" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12681" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12682 " COMBAK : need to handle when on a directory
12683 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012684 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012685 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012686 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012687 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012688" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012689 elseif a:dir == '[]' && nxtline != ''
12690 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012691" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012692 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12693 if nl != 0
12694 NetrwKeepj norm! k
12695 else
12696 NetrwKeepj norm! G
12697 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012698" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012699 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012700 endif
12701
12702" call Dret("s:TreeListMove")
12703endfun
12704
12705" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012706" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12707" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12708" can't be called except via emenu. But due to locale, that menu line may not be called
12709" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12710fun! s:UpdateBuffersMenu()
12711" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012712 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012713 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012714 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012715 catch /^Vim\%((\a\+)\)\=:E/
12716 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012717 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012718 endtry
12719 endif
12720" call Dret("s:UpdateBuffersMenu")
12721endfun
12722
12723" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012724" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012725" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012726fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012727" call Dfunc("s:UseBufWinVars()")
12728 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012729 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12730 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12731 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12732 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12733 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12734 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12735 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12736 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12737 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 +000012738" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012739endfun
12740
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012741" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012742" s:UserMaps: supports user-defined UserMaps {{{2
12743" * calls a user-supplied funcref(islocal,curdir)
12744" * interprets result
12745" See netrw#UserMaps()
12746fun! s:UserMaps(islocal,funcname)
12747" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12748
12749 if !exists("b:netrw_curdir")
12750 let b:netrw_curdir= getcwd()
12751 endif
12752 let Funcref = function(a:funcname)
12753 let result = Funcref(a:islocal)
12754
12755 if type(result) == 1
12756 " if result from user's funcref is a string...
12757" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12758 if result == "refresh"
12759" call Decho("refreshing display",'~'.expand("<slnum>"))
12760 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12761 elseif result != ""
12762" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12763 exe result
12764 endif
12765
12766 elseif type(result) == 3
12767 " if result from user's funcref is a List...
12768" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12769 for action in result
12770 if action == "refresh"
12771" call Decho("refreshing display",'~'.expand("<slnum>"))
12772 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12773 elseif action != ""
12774" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12775 exe action
12776 endif
12777 endfor
12778 endif
12779
12780" call Dret("s:UserMaps")
12781endfun
12782
Bram Moolenaar85850f32019-07-19 22:05:51 +020012783" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012784" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012785" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012786let &cpo= s:keepcpo
12787unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012788
Bram Moolenaar85850f32019-07-19 22:05:51 +020012789" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012790" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012791" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012792" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012793" doing autoload/netrw.vim version v172g ~57
12794" varname<g:netrw_dirhistcnt> value=0 ~1
12795" varname<s:THINLIST> value=0 ~1
12796" varname<s:LONGLIST> value=1 ~1
12797" varname<s:WIDELIST> value=2 ~1
12798" varname<s:TREELIST> value=3 ~1
12799" varname<s:MAXLIST> value=4 ~1
12800" varname<g:netrw_use_errorwindow> value=2 ~1
12801" varname<g:netrw_http_xcmd> value=-q -O ~1
12802" varname<g:netrw_http_put_cmd> value=curl -T ~1
12803" varname<g:netrw_keepj> value=keepj ~1
12804" varname<g:netrw_rcp_cmd> value=rcp ~1
12805" varname<g:netrw_rsync_cmd> value=rsync ~1
12806" varname<g:netrw_rsync_sep> value=/ ~1
12807" varname<g:netrw_scp_cmd> value=scp -q ~1
12808" varname<g:netrw_sftp_cmd> value=sftp ~1
12809" varname<g:netrw_ssh_cmd> value=ssh ~1
12810" varname<g:netrw_alto> value=0 ~1
12811" varname<g:netrw_altv> value=1 ~1
12812" varname<g:netrw_banner> value=1 ~1
12813" varname<g:netrw_browse_split> value=0 ~1
12814" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12815" varname<g:netrw_chgwin> value=-1 ~1
12816" varname<g:netrw_clipboard> value=1 ~1
12817" varname<g:netrw_compress> value=gzip ~1
12818" varname<g:netrw_ctags> value=ctags ~1
12819" varname<g:netrw_cursor> value=2 ~1
12820" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12821" varname<g:netrw_cygdrive> value=/cygdrive ~1
12822" varname<s:didstarstar> value=0 ~1
12823" varname<g:netrw_dirhistcnt> value=0 ~1
12824" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12825" varname<g:netrw_dirhistmax> value=10 ~1
12826" varname<g:netrw_errorlvl> value=0 ~1
12827" varname<g:netrw_fastbrowse> value=1 ~1
12828" 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
12829" varname<g:netrw_ftpmode> value=binary ~1
12830" varname<g:netrw_hide> value=1 ~1
12831" varname<g:netrw_keepdir> value=1 ~1
12832" varname<g:netrw_list_hide> value= ~1
12833" varname<g:netrw_localmkdir> value=mkdir ~1
12834" varname<g:netrw_remote_mkdir> value=mkdir ~1
12835" varname<g:netrw_liststyle> value=0 ~1
12836" varname<g:netrw_markfileesc> value=*./[\~ ~1
12837" varname<g:netrw_maxfilenamelen> value=32 ~1
12838" varname<g:netrw_menu> value=1 ~1
12839" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12840" varname<g:netrw_mousemaps> value=1 ~1
12841" varname<g:netrw_retmap> value=0 ~1
12842" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12843" varname<g:netrw_preview> value=0 ~1