blob: 7b7081b0ca7eaa75021680d002919ec20ba98965 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
6" Last Change:
7" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
K.Takata8750e3c2023-11-22 18:20:01 +09008" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Christian Brabandtf9ca1392024-02-19 20:37:11 +010019" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000020" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010021" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000022" Permission is hereby granted to use and distribute this code,
23" with or without modifications, provided that this copyright
24" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000025" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000026" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000027" expressed or implied. By using this plugin, you agree that
28" in no event will the copyright holder be liable for any damages
29" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010030"
31" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
32" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
33"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020034"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000035"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000036" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000037" (James 1:22 RSV)
38" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000039" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000040if &cp || exists("g:loaded_netrw")
41 finish
42endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020043
44" Check that vim has patches that netrw requires.
45" Patches needed for v7.4: 1557, and 213.
46" (netrw will benefit from vim's having patch#656, too)
47let s:needspatches=[1557,213]
48if exists("s:needspatches")
49 for ptch in s:needspatches
50 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
51 if !exists("s:needpatch{ptch}")
52 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
53 endif
54 let s:needpatch{ptch}= 1
55 finish
56 endif
57 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020058endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020059
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010060let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000061if !exists("s:NOTE")
62 let s:NOTE = 0
63 let s:WARNING = 1
64 let s:ERROR = 2
65endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000066
Bram Moolenaar1afcace2005-11-25 19:54:28 +000067let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010068setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020069"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010070"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010071"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000072
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000073" ======================
74" Netrw Variables: {{{1
75" ======================
76
Bram Moolenaar071d4272004-06-13 20:20:40 +000077" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020078" netrw#ErrorMsg: {{{2
79" 0=note = s:NOTE
80" 1=warning = s:WARNING
81" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010082" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
83" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
84" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010085" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020086fun! netrw#ErrorMsg(level,msg,errnum)
87" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
88
89 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020090" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020091 return
92 endif
93
94 if a:level == 1
95 let level= "**warning** (netrw) "
96 elseif a:level == 2
97 let level= "**error** (netrw) "
98 else
99 let level= "**note** (netrw) "
100 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100101" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200102
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200103 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
104 " use popup window
105 if type(a:msg) == 3
106 let msg = [level]+a:msg
107 else
108 let msg= level.a:msg
109 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200110 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200111 let s:popuperr_text= ""
112 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200113 " (default) netrw creates a one-line window to show error/warning
114 " messages (reliably displayed)
115
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100116 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200117 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100118" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200119
120 " getting messages out reliably is just plain difficult!
121 " This attempt splits the current window, creating a one line window.
122 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100123" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200124 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100125" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200126 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100127 if type(a:msg) == 3
128 for msg in a:msg
129 NetrwKeepj call setline(line("$")+1,level.msg)
130 endfor
131 else
132 NetrwKeepj call setline(line("$")+1,level.a:msg)
133 endif
134 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200135 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100136" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200137 bo 1split
138 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200139 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200140 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100141 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100142" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200143 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100144 if type(a:msg) == 3
145 for msg in a:msg
146 NetrwKeepj call setline(line("$")+1,level.msg)
147 endfor
148 else
149 NetrwKeepj call setline(line("$"),level.a:msg)
150 endif
151 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200152 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100153" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200154 if &fo !~ '[ta]'
155 syn clear
156 syn match netrwMesgNote "^\*\*note\*\*"
157 syn match netrwMesgWarning "^\*\*warning\*\*"
158 syn match netrwMesgError "^\*\*error\*\*"
159 hi link netrwMesgWarning WarningMsg
160 hi link netrwMesgError Error
161 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100162" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200163 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200164
165 else
166 " (optional) netrw will show messages using echomsg. Even if the
167 " message doesn't appear, at least it'll be recallable via :messages
168" redraw!
169 if a:level == s:WARNING
170 echohl WarningMsg
171 elseif a:level == s:ERROR
172 echohl Error
173 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100174
175 if type(a:msg) == 3
176 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100177 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100178 endfor
179 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100180 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100181 endif
182
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100183" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200184 echohl None
185 endif
186
187" call Dret("netrw#ErrorMsg")
188endfun
189
190" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100191" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100192" Loosely, varname = value.
193fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100194" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100195 if !exists(a:varname)
196 if type(a:value) == 0
197 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200198 elseif type(a:value) == 1 && a:value =~ '^[{[]'
199 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100200 elseif type(a:value) == 1
201 exe "let ".a:varname."="."'".a:value."'"
202 else
203 exe "let ".a:varname."=".a:value
204 endif
205 endif
206endfun
207
208" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000209" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200210call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000211if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100212 call s:NetrwInit("s:THINLIST",0)
213 call s:NetrwInit("s:LONGLIST",1)
214 call s:NetrwInit("s:WIDELIST",2)
215 call s:NetrwInit("s:TREELIST",3)
216 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000217endif
218
219" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200220" Default option values: {{{2
221let g:netrw_localcopycmdopt = ""
222let g:netrw_localcopydircmdopt = ""
223let g:netrw_localmkdiropt = ""
224let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200225
226" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000227" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200228if (v:version > 802 || (v:version == 802 && has("patch486"))) && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on") && has("mouse")
229 call s:NetrwInit("g:netrw_use_errorwindow",2)
230else
231 call s:NetrwInit("g:netrw_use_errorwindow",1)
232endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200233
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000234if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100235 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000236 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100237 elseif executable("curl")
238 let g:netrw_dav_cmd = "curl"
239 else
240 let g:netrw_dav_cmd = ""
241 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000242endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000243if !exists("g:netrw_fetch_cmd")
244 if executable("fetch")
245 let g:netrw_fetch_cmd = "fetch -o"
246 else
247 let g:netrw_fetch_cmd = ""
248 endif
249endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100250if !exists("g:netrw_file_cmd")
251 if executable("elinks")
252 call s:NetrwInit("g:netrw_file_cmd","elinks")
253 elseif executable("links")
254 call s:NetrwInit("g:netrw_file_cmd","links")
255 endif
256endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000257if !exists("g:netrw_ftp_cmd")
258 let g:netrw_ftp_cmd = "ftp"
259endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200260let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200261if !exists("g:netrw_ftp_options")
262 let g:netrw_ftp_options= "-i -n"
263endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000264if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100265 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100266 let g:netrw_http_cmd = "wget"
267 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100268 elseif executable("curl")
269 let g:netrw_http_cmd = "curl"
270 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200271 elseif executable("elinks")
272 let g:netrw_http_cmd = "elinks"
273 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000274 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100275 let g:netrw_http_cmd = "fetch"
276 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200277 elseif executable("links")
278 let g:netrw_http_cmd = "links"
279 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000280 else
281 let g:netrw_http_cmd = ""
282 endif
283endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100284call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100285call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100286call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
287call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200288call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200289if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200290 if executable("scp")
291 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
292 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200293 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200294 else
295 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
296 endif
297endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100298call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
299call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000300
Nir Lichtman1e34b952024-05-08 19:19:34 +0200301if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000302 \ && exists("g:netrw_use_nt_rcp")
303 \ && g:netrw_use_nt_rcp
304 \ && executable( $SystemRoot .'/system32/rcp.exe')
305 let s:netrw_has_nt_rcp = 1
306 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000307else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000308 let s:netrw_has_nt_rcp = 0
309 let s:netrw_rcpmode = ''
310endif
311
312" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000313" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000314" Cygwin Detection ------- {{{3
315if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200316 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
317 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000318 else
319 let g:netrw_cygwin= 0
320 endif
321endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000322" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100323call s:NetrwInit("g:netrw_alto" , &sb)
324call s:NetrwInit("g:netrw_altv" , &spr)
325call s:NetrwInit("g:netrw_banner" , 1)
326call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200327call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100328call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200329call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100330call s:NetrwInit("g:netrw_compress" , "gzip")
331call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200332if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
333 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
334 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000335endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200336call s:NetrwInit("g:netrw_cursor" , 2)
337let s:netrw_usercul = &cursorline
338let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200339"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100340call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000341" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200342call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200343call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200344call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100345call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200346call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100347call s:NetrwInit("g:netrw_fastbrowse" , 1)
348call s:NetrwInit("g:netrw_ftp_browse_reject", '^total\s\+\d\+$\|^Trying\s\+\d\+.*$\|^KERBEROS_V\d rejected\|^Security extensions not\|No such file\|: connect to address [0-9a-fA-F:]*: No route to host$')
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000349if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000350 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
351 let g:netrw_ftp_list_cmd = "ls -lF"
352 let g:netrw_ftp_timelist_cmd = "ls -tlF"
353 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000354 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000355 let g:netrw_ftp_list_cmd = "dir"
356 let g:netrw_ftp_timelist_cmd = "dir"
357 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000358 endif
359endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100360call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000361" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100362call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000363if !exists("g:netrw_ignorenetrc")
364 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
365 let g:netrw_ignorenetrc= 1
366 else
367 let g:netrw_ignorenetrc= 0
368 endif
369endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100370call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000371if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000372 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100373 if exists("g:netrw_list_cmd_options")
374 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
375 else
376 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
377 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000378 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200379 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100380 if exists("g:netrw_list_cmd_options")
381 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
382 else
383 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
384 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000385 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100386" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000387 let g:netrw_list_cmd= ""
388 endif
389endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100390call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000391" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200392if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200393 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200394 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
395endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100396if !exists("g:netrw_localcmdshell")
397 let g:netrw_localcmdshell= ""
398endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000399if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200400 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000401 if g:netrw_cygwin
402 let g:netrw_localcopycmd= "cp"
403 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000404 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200405 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000406 endif
407 elseif has("unix") || has("macunix")
408 let g:netrw_localcopycmd= "cp"
409 else
410 let g:netrw_localcopycmd= ""
411 endif
412endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100413if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200414 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100415 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200416 let g:netrw_localcopydircmd = "cp"
417 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100418 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000419 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200420 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100421 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200422 elseif has("unix")
423 let g:netrw_localcopydircmd = "cp"
424 let g:netrw_localcopydircmdopt= " -R"
425 elseif has("macunix")
426 let g:netrw_localcopydircmd = "cp"
427 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100428 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200429 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100430 endif
431endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200432if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100433 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200434 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
435endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200436if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200437 if g:netrw_cygwin
438 call s:NetrwInit("g:netrw_localmkdir","mkdir")
439 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000440 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200441 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200442 endif
443else
444 call s:NetrwInit("g:netrw_localmkdir","mkdir")
445endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200446call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200447if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200448 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200449 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
450endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000451if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200452 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000453 if g:netrw_cygwin
454 let g:netrw_localmovecmd= "mv"
455 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000456 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200457 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000458 endif
459 elseif has("unix") || has("macunix")
460 let g:netrw_localmovecmd= "mv"
461 else
462 let g:netrw_localmovecmd= ""
463 endif
464endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100465" following serves as an example for how to insert a version&patch specific test
466"if v:version < 704 || (v:version == 704 && !has("patch1107"))
467"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100468call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
469" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000470if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000471 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000472endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000473if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000474 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
475endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000476" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100477call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
478call s:NetrwInit("g:netrw_maxfilenamelen", 32)
479call s:NetrwInit("g:netrw_menu" , 1)
480call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200481call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100482call s:NetrwInit("g:netrw_retmap" , 0)
483if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
484 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200485elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100486 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
487else
488 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000489endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100490call s:NetrwInit("g:netrw_preview" , 0)
491call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100492call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100493call s:NetrwInit("g:netrw_sshport" , "-p")
494call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
495call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
496call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100497call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
498" Default values - q-s ---------- {{{3
499call s:NetrwInit("g:netrw_quickhelp",0)
500let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100501 \ "(create new) %:file d:directory",
502 \ "(windows split&open) o:horz v:vert p:preview",
503 \ "i:style qf:file info O:obtain r:reverse",
504 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
505 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
506 \ "(history) qb:list u:go up U:go down",
507 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100508" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
509call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100510if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
511 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
512else
513 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
514endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100515call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
516call s:NetrwInit("g:netrw_sort_options" , "")
517call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000518if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100519 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200520 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100521 else
522 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000523 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000524endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100525call s:NetrwInit("g:netrw_special_syntax" , 0)
526call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200527call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100528call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100529call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000530" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100531call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200532if !exists("g:netrw_xstrlen")
533 if exists("g:Align_xstrlen")
534 let g:netrw_xstrlen= g:Align_xstrlen
535 elseif exists("g:drawit_xstrlen")
536 let g:netrw_xstrlen= g:drawit_xstrlen
537 elseif &enc == "latin1" || !has("multi_byte")
538 let g:netrw_xstrlen= 0
539 else
540 let g:netrw_xstrlen= 1
541 endif
542endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100543call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200544call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100545call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200546if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000547" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000548" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100549call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200550if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200551 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200552else
Bram Moolenaarff034192013-04-24 18:51:19 +0200553 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200554endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200555call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100556call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
557call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100558if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100559 let s:treedepthstring= "│ "
560else
561 let s:treedepthstring= "| "
562endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200563call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000564
565" BufEnter event ignored by decho when following variable is true
566" Has a side effect that doau BufReadPost doesn't work, so
567" files read by network transfer aren't appropriately highlighted.
568"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569
Bram Moolenaaradc21822011-04-01 18:03:16 +0200570" ======================
571" Netrw Initialization: {{{1
572" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200573if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100574" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100575 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200576" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100577 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100578 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
579 au VimEnter * let s:initbeval= &beval
580"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100581" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
582" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
583" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
584" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
585" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
586" if exists("g:syntax_on") | call Decho("did not install beval events: g:syntax_on exists","~".expand("<slnum>")) | endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200587endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200588au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200589
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200590if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100591 com! -nargs=* NetrwKeepj keepj <args>
592else
593 let g:netrw_keepj= ""
594 com! -nargs=* NetrwKeepj <args>
595endif
596
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000597" ==============================
598" Netrw Utility Functions: {{{1
599" ==============================
600
Bram Moolenaaradc21822011-04-01 18:03:16 +0200601" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100602" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100603if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100604" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100605 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100606 if &ft != "netrw"
607 return ""
608 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200609 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
610 " popup error window is still showing
611 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
612 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
613 " text under mouse hasn't changed; only close window when it changes
614 call popup_close(s:popuperr_id)
615 unlet s:popuperr_text
616 else
617 let s:popuperr_text= v:beval_text
618 endif
619 let mesg= ""
620 elseif !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval)
Bram Moolenaar8d043172014-01-23 14:24:41 +0100621 let mesg= ""
622 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
623 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
624 elseif getline(v:beval_lnum) =~ '^"\s*/'
625 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
626 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100627 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100628 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
629 let mesg = "S: edit sorting sequence"
630 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
631 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
632 elseif v:beval_text == "Quick" || v:beval_text == "Help"
633 let mesg = "Help: press <F1>"
634 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
635 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
636 else
637 let mesg= ""
638 endif
639 return mesg
640 endfun
641"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100642" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
643" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
644" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
645" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
646" if exists("g:netrw_nobeval") |call Decho("did not load netrw#BalloonHelp(): g:netrw_nobeval exists","~".expand("<slnum>")) |endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200647endif
648
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200650" netrw#Explore: launch the local browser in the directory of the current file {{{2
651" indx: == -1: Nexplore
652" == -2: Pexplore
653" == +: this is overloaded:
654" * If Nexplore/Pexplore is in use, then this refers to the
655" indx'th item in the w:netrw_explore_list[] of items which
656" matched the */pattern **/pattern *//pattern **//pattern
657" * If Hexplore or Vexplore, then this will override
658" g:netrw_winsize to specify the qty of rows or columns the
659" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100660" dosplit==0: the window will be split iff the current file has been modified and hidden not set
Bram Moolenaarff034192013-04-24 18:51:19 +0200661" dosplit==1: the window will be split before running the local browser
662" style == 0: Explore style == 1: Explore!
663" == 2: Hexplore style == 3: Hexplore!
664" == 4: Vexplore style == 5: Vexplore!
665" == 6: Texplore
666fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100667" call Dfunc("netrw#Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.",a:1<".a:1.">) &modified=".&modified." modifiable=".&modifiable." a:0=".a:0." win#".winnr()." buf#".bufnr("%")." ft=".&ft)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100668" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200669 if !exists("b:netrw_curdir")
670 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100671" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200672 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100673
674 " record current file for Rexplore's benefit
675 if &ft != "netrw"
676 let w:netrw_rexfile= expand("%:p")
677 endif
678
679 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200680 let curdir = simplify(b:netrw_curdir)
681 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200682 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200683 let curdir= substitute(curdir,'\','/','g')
684 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100685" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100686
687 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
688 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
689 " try Explore again.
690 if a:0 > 0
691" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100692 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
693 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
694 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
695 \ '~'.expand("<slnum>"))
696 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
697" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100698 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
699" call Dret("netrw#Explore : returning from retry")
700 return
701" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100702" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100703 endif
704 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200705
706 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200707 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100708" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100709 sil! let keepregstar = @*
710 sil! let keepregplus = @+
711 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200712 sil! let keepregslash= @/
713
Bram Moolenaar8d043172014-01-23 14:24:41 +0100714 " if dosplit
715 " -or- file has been modified AND file not hidden when abandoned
716 " -or- Texplore used
717 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100718" call Decho("case dosplit=".a:dosplit." modified=".&modified." a:style=".a:style.": dosplit or file has been modified",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200719 call s:SaveWinVars()
720 let winsz= g:netrw_winsize
721 if a:indx > 0
722 let winsz= a:indx
723 endif
724
725 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100726" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200727 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200728 if winsz == 0|let winsz= ""|endif
729 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100730" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200731
732 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100733" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200734 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200735 if winsz == 0|let winsz= ""|endif
736 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100737" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200738
739 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100740" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200741 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200742 if winsz == 0|let winsz= ""|endif
743 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100744" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200745
746 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100747" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200748 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200749 if winsz == 0|let winsz= ""|endif
750 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100751" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200752
753 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100754" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200755 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200756 if winsz == 0|let winsz= ""|endif
757 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100758" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200759
760 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100761" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200762 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200763 if winsz == 0|let winsz= ""|endif
764 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100765" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200766
767 elseif a:style == 6 " Texplore
768 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100769" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200770 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100771" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200772 call s:RestoreBufVars()
773 endif
774 call s:RestoreWinVars()
775" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100776" call Decho("case a:dosplit=".a:dosplit." AND modified=".&modified." AND a:style=".a:style." is not 6",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100778 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200779
780 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100783" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100785" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100787" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200788 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
789 if dirname !~ '/$'
790 let dirname= dirname."/"
791 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100796" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200797 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100798" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200799 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100800" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200801 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100802" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200803 let dirname= a:1
804 endif
805 else
806 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100807" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200808 call s:NetrwClearExplore()
809" call Dret("netrw#Explore : cleared list")
810 return
811 endif
812
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100813" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200814 if dirname =~ '\.\./\=$'
815 let dirname= simplify(fnamemodify(dirname,':p:h'))
816 elseif dirname =~ '\.\.' || dirname == '.'
817 let dirname= simplify(fnamemodify(dirname,':p'))
818 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100819" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200820
821 if dirname =~ '^\*//'
822 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100823" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200824 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
825 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100826" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200827 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
828
829 elseif dirname =~ '^\*\*//'
830 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100831" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200832 let pattern= substitute(dirname,'^\*\*//','','')
833 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100834" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200835
836 elseif dirname =~ '/\*\*/'
837 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100838" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200839 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200840 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200841 let b:netrw_curdir = prefixdir
842 else
843 let b:netrw_curdir= getcwd().'/'.prefixdir
844 endif
845 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
846 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100847" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
848" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200849
850 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200851 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200852 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100853" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200854
855 elseif dirname=~ '^\*\*/'
856 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
857 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100858" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200859
860 else
861 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100862" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200863 endif
864
865 if starpat == 0 && a:indx >= 0
866 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100867" call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname.">, handles Explore Hexplore Vexplore Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200868 if dirname == ""
869 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100870" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200871 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200872 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200873 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200874 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200875 if dirname == ""
876 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200877 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100878 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100879 " depending on whether backslashes have been converted to forward slashes by earlier code).
880 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200881 let dirname= b:netrw_curdir."/".dirname
882 endif
883 elseif dirname !~ '^/'
884 let dirname= b:netrw_curdir."/".dirname
885 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100886" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200887 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100888" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
889" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200890 endif
891 if exists("w:netrw_bannercnt")
892 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
893 " If one wants to return the same place in the netrw window, use :Rex instead.
894 exe w:netrw_bannercnt
895 endif
896
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100897" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200898 " ---------------------------------------------------------------------
899 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
900" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100901" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200902" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100903" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200904" endif
905 " ---------------------------------------------------------------------
906
907 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
908 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
909 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
910 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
911 elseif a:indx <= 0
912 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100913" call Decho("case a:indx<=0: Nexplore, Pexplore, <s-down>, <s-up> starpat=".starpat." a:indx=".a:indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200914 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100915" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200916 let s:didstarstar= 1
917 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
918 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
919 endif
920
921 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100922" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200923 if !exists("w:netrw_explore_indx")
924 let w:netrw_explore_indx= 0
925 endif
926
927 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100928" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200929
930 if indx == -1
931 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100932" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200933 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100934 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200935 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100936" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100937 if @* != keepregstar | sil! let @* = keepregstar | endif
938 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100939 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200940 sil! let @/ = keepregslash
941" call Dret("netrw#Explore")
942 return
943 endif
944 let indx= w:netrw_explore_indx
945 if indx < 0 | let indx= 0 | endif
946 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
947 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100948" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200949 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
950 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100951" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200952 endwhile
953 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100954" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200955
956 elseif indx == -2
957 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100958" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200959 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100960 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200961 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100962" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100963 if @* != keepregstar | sil! let @* = keepregstar | endif
964 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100965 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200966 sil! let @/ = keepregslash
967" call Dret("netrw#Explore")
968 return
969 endif
970 let indx= w:netrw_explore_indx
971 if indx < 0 | let indx= 0 | endif
972 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
973 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100974" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200975 while indx >= 0 && curfile == w:netrw_explore_list[indx]
976 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100977" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200978 endwhile
979 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100980" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200981
982 else
983 " Explore -- initialize
984 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100985" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100986 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200987 let w:netrw_explore_indx= 0
988 if !exists("b:netrw_curdir")
989 let b:netrw_curdir= getcwd()
990 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100991" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200992
993 " switch on starpat to build the w:netrw_explore_list of files
994 if starpat == 1
995 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100996" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
997" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200998 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100999 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001000 catch /^Vim\%((\a\+)\)\=:E480/
1001 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1002" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1003 return
1004 endtry
1005 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1006 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1007
1008 elseif starpat == 2
1009 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001010" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1011" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001012 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001013 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001014 catch /^Vim\%((\a\+)\)\=:E480/
1015 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1016 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001017 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001018" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001019 if @* != keepregstar | sil! let @* = keepregstar | endif
1020 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001021 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001022 sil! let @/ = keepregslash
1023" call Dret("netrw#Explore : no files matched pattern")
1024 return
1025 endtry
1026 let s:netrw_curdir = b:netrw_curdir
1027 let w:netrw_explore_list = getqflist()
1028 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1029 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1030
1031 elseif starpat == 3
1032 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001033" call Decho("..case starpat=".starpat.": build */filepat list (curdir-only srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001034 let filepat= substitute(dirname,'^\*/','','')
1035 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001036" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1037" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001038 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1039 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1040
1041 elseif starpat == 4
1042 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001043" call Decho("..case starpat=".starpat.": build **/filepat list (recursive descent srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001044 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1045 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1046 endif " switch on starpat to build w:netrw_explore_list
1047
1048 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001049" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1050" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001051
1052 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001053 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001054 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001055" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001056 if @* != keepregstar | sil! let @* = keepregstar | endif
1057 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001058 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001059 sil! let @/ = keepregslash
1060" call Dret("netrw#Explore : no files matched")
1061 return
1062 endif
1063 endif " if indx ... endif
1064
1065 " NetrwStatusLine support - for exploring support
1066 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001067" call Decho("....w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001068
1069 " wrap the indx around, but issue a note
1070 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001071" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001072 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1073 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001074 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 endif
1076
1077 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001078" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001079 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001080" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001081
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001082" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001083 call netrw#LocalBrowseCheck(newdir)
1084 if !exists("w:netrw_liststyle")
1085 let w:netrw_liststyle= g:netrw_liststyle
1086 endif
1087 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001088 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001089 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001090 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001091 endif
1092 let w:netrw_explore_mtchcnt = indx + 1
1093 let w:netrw_explore_bufnr = bufnr("%")
1094 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001095 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001096" call Decho("....explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001097
1098 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001099" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001100 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001101 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your vim needs the +path_extra feature for Exploring with **!",44)
Bram Moolenaarff034192013-04-24 18:51:19 +02001102 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001103 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001104" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001105 if @* != keepregstar | sil! let @* = keepregstar | endif
1106 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001107 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001108 sil! let @/ = keepregslash
1109" call Dret("netrw#Explore : missing +path_extra")
1110 return
1111 endif
1112
1113 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001114" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001115 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1116 sil! unlet w:netrw_treedict
1117 sil! unlet w:netrw_treetop
1118 endif
1119 let newdir= dirname
1120 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001121 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001122 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001123 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001124 endif
1125 endif
1126
1127 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001128" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1129" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001130 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001131" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001132 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001133 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001134" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001135 let s:explore_prvdir = b:netrw_curdir
1136 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001137 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001138 if b:netrw_curdir !~ '/$'
1139 let dirlen= dirlen + 1
1140 endif
1141 let prvfname= ""
1142 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001143" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001144 if fname =~ '^'.b:netrw_curdir
1145 if s:explore_match == ""
1146 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1147 else
1148 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1149 endif
1150 elseif fname !~ '^/' && fname != prvfname
1151 if s:explore_match == ""
1152 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1153 else
1154 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1155 endif
1156 endif
1157 let prvfname= fname
1158 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001159" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001160 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1161 exe "2match netrwMarkFile /".s:explore_match."/"
1162 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001163 endif
1164 echo "<s-up>==Pexplore <s-down>==Nexplore"
1165 else
1166 2match none
1167 if exists("s:explore_match") | unlet s:explore_match | endif
1168 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001169" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001170 endif
1171
Bram Moolenaara6878372014-03-22 21:02:50 +01001172 " since Explore may be used to initialize netrw's browser,
1173 " there's no danger of a late FocusGained event on initialization.
1174 " Consequently, set s:netrw_events to 2.
1175 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001176 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001177" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001178 if @* != keepregstar | sil! let @* = keepregstar | endif
1179 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001180 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001181 sil! let @/ = keepregslash
1182" call Dret("netrw#Explore : @/<".@/.">")
1183endfun
1184
1185" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001186" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001187" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1188" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1189" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1190" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1191" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001192fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001193" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001194 let curwin= winnr()
1195
Bram Moolenaara6878372014-03-22 21:02:50 +01001196 if a:0 > 0 && a:1 != ""
1197 " if a netrw window is already on the left-side of the tab
1198 " and a directory has been specified, explore with that
1199 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001200" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001201 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001202" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001203 exe "1wincmd w"
1204 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001205" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001206 exe "Explore ".fnameescape(a1)
1207 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001208 let s:lexplore_win= curwin
1209 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001210 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001211" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001212 unlet t:netrw_lexposn
1213 endif
1214" call Dret("netrw#Lexplore")
1215 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001216 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001217 exe curwin."wincmd w"
1218 else
1219 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001220" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001221 endif
1222
Bram Moolenaar8d043172014-01-23 14:24:41 +01001223 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001224 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001225 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001226" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001227 else
1228 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001229" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001230 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001231" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001232
1233 if lexwinnr > 0
1234 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001235" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001236 exe lexwinnr."wincmd w"
1237 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001238 let t:netrw_lexposn = winsaveview()
1239" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001240" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001241 close
1242 if lexwinnr < curwin
1243 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001244 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001245 if lexwinnr != curwin
1246 exe curwin."wincmd w"
1247 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001248 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001249" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001250
1251 else
1252 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001253" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001254 exe "1wincmd w"
1255 let keep_altv = g:netrw_altv
1256 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001257 if a:count != 0
1258 let netrw_winsize = g:netrw_winsize
1259 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001260 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001261 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001262" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001263 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001264" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001265 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001266" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001267 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001268 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001269 elseif curfile =~ '^\a\{3,}://'
1270" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001271 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001272 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001273" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001274 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001275 endif
1276 if a:count != 0
1277 let g:netrw_winsize = netrw_winsize
1278 endif
1279 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001280 let g:netrw_altv = keep_altv
1281 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001282 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1283 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001284 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001285 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001286" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1287" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001288 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001289" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001290" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1291 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001292 unlet t:netrw_lexposn
1293 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001294 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001295
1296 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001297 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001298 if a:rightside
1299 let g:netrw_chgwin= 1
1300 else
1301 let g:netrw_chgwin= 2
1302 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001303" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001304 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001305
Bram Moolenaar8d043172014-01-23 14:24:41 +01001306" call Dret("netrw#Lexplore")
1307endfun
1308
1309" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001310" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001311" supports :NetrwClean -- remove netrw from first directory on runtimepath
1312" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001313fun! netrw#Clean(sys)
1314" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001315
1316 if a:sys
1317 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1318 else
1319 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1320 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001321" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001322 let diddel= 0
1323 let diddir= ""
1324
1325 if choice == 1
1326 for dir in split(&rtp,',')
1327 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001328" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001329 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1330 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1331 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1332 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1333 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1334 if s:NetrwDelete(dir."/syntax/netrwlist.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrwlist.vim",55) |endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00001335 let diddir= dir
1336 let diddel= diddel + 1
1337 if !a:sys|break|endif
1338 endif
1339 endfor
1340 endif
1341
1342 echohl WarningMsg
1343 if diddel == 0
1344 echomsg "netrw is either not installed or not removable"
1345 elseif diddel == 1
1346 echomsg "removed one copy of netrw from <".diddir.">"
1347 else
1348 echomsg "removed ".diddel." copies of netrw"
1349 endif
1350 echohl None
1351
Bram Moolenaara6878372014-03-22 21:02:50 +01001352" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001353endfun
1354
Bram Moolenaar5c736222010-01-06 20:54:52 +01001355" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001356" netrw#MakeTgt: make a target out of the directory name provided {{{2
1357fun! netrw#MakeTgt(dname)
1358" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1359 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001360 let svpos = winsaveview()
1361" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001362 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1363" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001364 if s:netrwmftgt_islocal
1365 let netrwmftgt= simplify(a:dname)
1366 else
1367 let netrwmftgt= a:dname
1368 endif
1369 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1370 " re-selected target, so just clear it
1371 unlet s:netrwmftgt s:netrwmftgt_islocal
1372 else
1373 let s:netrwmftgt= netrwmftgt
1374 endif
1375 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001376 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001377 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001378" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1379 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001380" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001381endfun
1382
Bram Moolenaara6878372014-03-22 21:02:50 +01001383" ---------------------------------------------------------------------
1384" netrw#Obtain: {{{2
1385" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001386" islocal=0 obtain from remote source
1387" =1 obtain from local source
1388" fname : a filename or a list of filenames
1389" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001390fun! netrw#Obtain(islocal,fname,...)
1391" call Dfunc("netrw#Obtain(islocal=".a:islocal." fname<".((type(a:fname) == 1)? a:fname : string(a:fname)).">) a:0=".a:0)
Bram Moolenaarff034192013-04-24 18:51:19 +02001392 " NetrwStatusLine support - for obtaining support
1393
1394 if type(a:fname) == 1
1395 let fnamelist= [ a:fname ]
1396 elseif type(a:fname) == 3
1397 let fnamelist= a:fname
1398 else
1399 call netrw#ErrorMsg(s:ERROR,"attempting to use NetrwObtain on something not a filename or a list",62)
Bram Moolenaara6878372014-03-22 21:02:50 +01001400" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001401 return
1402 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001403" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001404 if a:0 > 0
1405 let tgtdir= a:1
1406 else
1407 let tgtdir= getcwd()
1408 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001409" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001410
1411 if exists("b:netrw_islocal") && b:netrw_islocal
1412 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001413" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001414 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1415 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001416 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001417 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001418" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001419 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001420" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001421 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001422 if v:shell_error != 0
1423 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001424" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001425 return
1426 endif
1427 endfor
1428 else
1429 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001430" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1431 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1432" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001433 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001434 if v:shell_error != 0
1435 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001436" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001437 return
1438 endif
1439 endif
1440 elseif !exists("b:netrw_curdir")
1441 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1442 else
1443 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1444 endif
1445
1446 else
1447 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001448" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001449 if type(a:fname) == 1
1450 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1451 endif
1452 call s:NetrwMethod(b:netrw_curdir)
1453
1454 if b:netrw_method == 4
1455 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001456" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001457 if exists("g:netrw_port") && g:netrw_port != ""
1458 let useport= " ".g:netrw_scpport." ".g:netrw_port
1459 else
1460 let useport= ""
1461 endif
1462 if b:netrw_fname =~ '/'
1463 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1464 else
1465 let path= ""
1466 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001467 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001468 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".filelist." ".s:ShellEscape(tgtdir,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001469
1470 elseif b:netrw_method == 2
1471 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001472" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001473 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001474 let tmpbufnr= bufnr("%")
1475 setl ff=unix
1476 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001477 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001478" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001479 endif
1480
1481 if exists("b:netrw_fname") && b:netrw_fname != ""
1482 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001483" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001484 endif
1485
1486 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001487 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001488" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001489 endif
1490 for fname in fnamelist
1491 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001492" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001493 endfor
1494 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001495 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001496 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001497 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001498 endif
1499 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1500 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1501 let debugkeep= &debug
1502 setl debug=msg
1503 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1504 let &debug= debugkeep
1505 endif
1506
1507 elseif b:netrw_method == 3
1508 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001509" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001510 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001511 let tmpbufnr= bufnr("%")
1512 setl ff=unix
1513
1514 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001515 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001516" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001517 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001518 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001519" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001520 endif
1521
1522 if exists("g:netrw_uid") && g:netrw_uid != ""
1523 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001524 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001525" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001526 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001527 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001528 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001529" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001530 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001531 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001532" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001533 endif
1534 endif
1535
1536 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001537 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001538" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001539 endif
1540
1541 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001542 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001543" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001544 endif
1545
1546 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001547 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001548" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001549 endif
1550
1551 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001552 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001553" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001554 endif
1555 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001556 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001557 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001558" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001559
1560 " perform ftp:
1561 " -i : turns off interactive prompting from ftp
1562 " -n unix : DON'T use <.netrc>, even though it exists
1563 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001564 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1565 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001566 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001567 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1568 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001569" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001570 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001571 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001572 endif
1573 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001574
1575 elseif b:netrw_method == 9
1576 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001577" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001578 if a:fname =~ '/'
1579 let localfile= substitute(a:fname,'^.*/','','')
1580 else
1581 let localfile= a:fname
1582 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001583 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1).s:ShellEscape(localfile)." ".s:ShellEscape(tgtdir))
Bram Moolenaar13600302014-05-22 18:26:40 +02001584
Bram Moolenaarff034192013-04-24 18:51:19 +02001585 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001586 " probably a badly formed url; protocol not recognized
1587" call Dret("netrw#Obtain : unsupported method")
1588 return
1589
1590 else
1591 " protocol recognized but not supported for Obtain (yet?)
1592 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001593 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001594 endif
1595" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001596 return
1597 endif
1598
1599 " restore status line
1600 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001601 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001602 endif
1603
1604 endif
1605
1606 " cleanup
1607 if exists("tmpbufnr")
1608 if bufnr("%") != tmpbufnr
1609 exe tmpbufnr."bw!"
1610 else
1611 q!
1612 endif
1613 endif
1614
Bram Moolenaara6878372014-03-22 21:02:50 +01001615" call Dret("netrw#Obtain")
1616endfun
1617
1618" ---------------------------------------------------------------------
1619" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1620fun! netrw#Nread(mode,fname)
1621" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001622 let svpos= winsaveview()
1623" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001624 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001625" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1626 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001627
1628 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1629 if exists("w:netrw_bannercnt")
1630 " start with cursor just after the banner
1631 exe w:netrw_bannercnt
1632 endif
1633 endif
1634" call Dret("netrw#Nread")
1635endfun
1636
1637" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001638" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1639" Options get restored by s:NetrwOptionsRestore()
1640"
1641" Option handling:
1642" * save user's options (s:NetrwOptionsSave)
1643" * set netrw-safe options (s:NetrwOptionsSafe)
1644" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1645" * restore user's options (s:netrwOPtionsRestore)
1646" - restore a user option when != safe option (s:NetrwRestoreSetting)
1647" vt: (variable type) normally its either "w:" or "s:"
1648fun! s:NetrwOptionsSave(vt)
1649" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1650" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001651" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt." hid=".&hid,'~'.expand("<slnum>"))
1652" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001653
1654 if !exists("{a:vt}netrw_optionsave")
1655 let {a:vt}netrw_optionsave= 1
1656 else
1657" call Dret("s:NetrwOptionsSave : options already saved")
1658 return
1659 endif
1660" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1661
1662 " Save current settings and current directory
1663" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1664 let s:yykeep = @@
1665 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1666 let {a:vt}netrw_aikeep = &l:ai
1667 let {a:vt}netrw_awkeep = &l:aw
1668 let {a:vt}netrw_bhkeep = &l:bh
1669 let {a:vt}netrw_blkeep = &l:bl
1670 let {a:vt}netrw_btkeep = &l:bt
1671 let {a:vt}netrw_bombkeep = &l:bomb
1672 let {a:vt}netrw_cedit = &cedit
1673 let {a:vt}netrw_cikeep = &l:ci
1674 let {a:vt}netrw_cinkeep = &l:cin
1675 let {a:vt}netrw_cinokeep = &l:cino
1676 let {a:vt}netrw_comkeep = &l:com
1677 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001678 let {a:vt}netrw_cuckeep = &l:cuc
1679 let {a:vt}netrw_culkeep = &l:cul
1680" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001681 let {a:vt}netrw_diffkeep = &l:diff
1682 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001683 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1684 let {a:vt}netrw_ffkeep = &l:ff
1685 endif
1686 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1687 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001688 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001689 let {a:vt}netrw_hidkeep = &l:hidden
1690 let {a:vt}netrw_imkeep = &l:im
1691 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001692 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001693 let {a:vt}netrw_lskeep = &l:ls
1694 let {a:vt}netrw_makeep = &l:ma
1695 let {a:vt}netrw_magickeep = &l:magic
1696 let {a:vt}netrw_modkeep = &l:mod
1697 let {a:vt}netrw_nukeep = &l:nu
1698 let {a:vt}netrw_rnukeep = &l:rnu
1699 let {a:vt}netrw_repkeep = &l:report
1700 let {a:vt}netrw_rokeep = &l:ro
1701 let {a:vt}netrw_selkeep = &l:sel
1702 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001703 if !g:netrw_use_noswf
1704 let {a:vt}netrw_swfkeep = &l:swf
1705 endif
1706 let {a:vt}netrw_tskeep = &l:ts
1707 let {a:vt}netrw_twkeep = &l:tw " textwidth
1708 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1709 let {a:vt}netrw_wrapkeep = &l:wrap
1710 let {a:vt}netrw_writekeep = &l:write
1711
1712 " save a few selected netrw-related variables
1713" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1714 if g:netrw_keepdir
1715 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001716" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001717 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001718 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001719 sil! let {a:vt}netrw_starkeep = @*
1720 sil! let {a:vt}netrw_pluskeep = @+
1721 endif
1722 sil! let {a:vt}netrw_slashkeep= @/
1723
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001724" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001725" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
1726" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1727endfun
1728
1729" ---------------------------------------------------------------------
1730" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1731" Use s:NetrwSaveOptions() to save user settings
1732" Use s:NetrwOptionsRestore() to restore user settings
1733fun! s:NetrwOptionsSafe(islocal)
1734" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1735" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1736" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
1737 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1738 call s:NetrwSetSafeSetting("&l:ai",0)
1739 call s:NetrwSetSafeSetting("&l:aw",0)
1740 call s:NetrwSetSafeSetting("&l:bl",0)
1741 call s:NetrwSetSafeSetting("&l:bomb",0)
1742 if a:islocal
1743 call s:NetrwSetSafeSetting("&l:bt","nofile")
1744 else
1745 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1746 endif
1747 call s:NetrwSetSafeSetting("&l:ci",0)
1748 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001749 if g:netrw_fastbrowse > a:islocal
1750 call s:NetrwSetSafeSetting("&l:bh","hide")
1751 else
1752 call s:NetrwSetSafeSetting("&l:bh","delete")
1753 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001754 call s:NetrwSetSafeSetting("&l:cino","")
1755 call s:NetrwSetSafeSetting("&l:com","")
1756 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1757 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1758 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001759 if &go =~ 'a' | set go-=a | endif
1760 if &go =~ 'A' | set go-=A | endif
1761 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001762 call s:NetrwSetSafeSetting("&l:hid",0)
1763 call s:NetrwSetSafeSetting("&l:im",0)
1764 setl isk+=@ isk+=* isk+=/
1765 call s:NetrwSetSafeSetting("&l:magic",1)
1766 if g:netrw_use_noswf
1767 call s:NetrwSetSafeSetting("swf",0)
1768 endif
1769 call s:NetrwSetSafeSetting("&l:report",10000)
1770 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1771 call s:NetrwSetSafeSetting("&l:spell",0)
1772 call s:NetrwSetSafeSetting("&l:tw",0)
1773 call s:NetrwSetSafeSetting("&l:wig","")
1774 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001775
1776 " set up cuc and cul based on g:netrw_cursor and listing style
1777 " COMBAK -- cuc cul related
1778 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001779
1780 " allow the user to override safe options
1781" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1782 if &ft == "netrw"
1783" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1784 keepalt NetrwKeepj doau FileType netrw
1785 endif
1786
1787" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1788" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
1789" call Dret("s:NetrwOptionsSafe")
1790endfun
1791
1792" ---------------------------------------------------------------------
1793" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1794fun! s:NetrwOptionsRestore(vt)
1795" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001796" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001797" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001798 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001799" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001800
1801 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1802 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001803" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001804 filetype detect
1805" call Decho("..settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
1806 else
1807 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001808 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001809" call Decho("..ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001810" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001811 return
1812 endif
1813 unlet {a:vt}netrw_optionsave
1814
1815 if exists("+acd")
1816 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001817" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001818 let curdir = getcwd()
1819 let &l:acd = {a:vt}netrw_acdkeep
1820 unlet {a:vt}netrw_acdkeep
1821 if &l:acd
1822 call s:NetrwLcd(curdir)
1823 endif
1824 endif
1825 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001826" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001827 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1828 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1829 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1830 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1831 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001832" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001833 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1834 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1835 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1836 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1837 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001838" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001839 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1840 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1841 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1842 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1843 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001844 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001845" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1846 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1847 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001848 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001849 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1850" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1851 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1852 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1853" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1854 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1855" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1856 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1857 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001858 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001859 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1860 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1861" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1862 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1863 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1864 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1865 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1866" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001867 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001868 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1869 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1870 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001871 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001872" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001873 call s:NetrwRestoreSetting("s:yykeep","@@")
1874 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1875 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1876 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1877 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1878
Bram Moolenaara6878372014-03-22 21:02:50 +01001879 if exists("{a:vt}netrw_swfkeep")
1880 if &directory == ""
1881 " user hasn't specified a swapfile directory;
1882 " netrw will temporarily set the swapfile directory
1883 " to the current directory as returned by getcwd().
1884 let &l:directory= getcwd()
1885 sil! let &l:swf = {a:vt}netrw_swfkeep
1886 setl directory=
1887 unlet {a:vt}netrw_swfkeep
1888 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001889 if !g:netrw_use_noswf
1890 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1891 sil! let &l:swf= {a:vt}netrw_swfkeep
1892 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001893 unlet {a:vt}netrw_swfkeep
1894 endif
1895 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001896 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001897 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1898 if exists("{a:vt}netrw_dirkeep")
1899 call s:NetrwLcd(dirkeep)
1900 unlet {a:vt}netrw_dirkeep
1901 endif
1902 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001903 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001904" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001905 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1906 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001907 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001908 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001909
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001910" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1911" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1912" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1913" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1914" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001915 " Moved the filetype detect here from NetrwGetFile() because remote files
1916 " were having their filetype detect-generated settings overwritten by
1917 " NetrwOptionRestore.
1918 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001919" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1920 filetype detect
1921" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001922 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001923" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001924" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001925" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001926endfun
1927
1928" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001929" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1930" but only when the options' value and the safe setting differ
1931" Doing this means that netrw will not come up as having changed a
1932" setting last when it really didn't actually change it.
1933"
1934" Called from s:NetrwOptionsSafe
1935" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1936fun! s:NetrwSetSafeSetting(setting,safesetting)
1937" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001938
Bram Moolenaar85850f32019-07-19 22:05:51 +02001939 if a:setting =~ '^&'
1940" call Decho("fyi: a:setting starts with &")
1941 exe "let settingval= ".a:setting
1942" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001943
Bram Moolenaar85850f32019-07-19 22:05:51 +02001944 if settingval != a:safesetting
1945" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1946 if type(a:safesetting) == 0
1947 exe "let ".a:setting."=".a:safesetting
1948 elseif type(a:safesetting) == 1
1949 exe "let ".a:setting."= '".a:safesetting."'"
1950 else
1951 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1952 endif
1953 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001954 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001955
Bram Moolenaar85850f32019-07-19 22:05:51 +02001956" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001957endfun
1958
1959" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001960" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1961" but only if the setting value differs from the associated keepvar.
1962" Doing this means that netrw will not come up as having changed a
1963" setting last when it really didn't actually change it.
1964"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001965" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001966" keepvars are set up by s:NetrwOptionsSave
1967fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001968""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001969
Bram Moolenaar85850f32019-07-19 22:05:51 +02001970 " typically called from s:NetrwOptionsRestore
1971 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1972 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001973 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001974 if exists(a:keepvar)
1975 exe "let keepvarval= ".a:keepvar
1976 exe "let setting= ".a:setting
1977
1978"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1979"" call Decho("fyi: keepvarval=".keepvarval)
1980"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1981
1982 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001983"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001984 if type(a:setting) == 0
1985 exe "let ".a:setting."= ".keepvarval
1986 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001987 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001988 else
1989 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1990 endif
1991 endif
1992
1993 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001994 endif
1995
Bram Moolenaar85850f32019-07-19 22:05:51 +02001996"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001997endfun
1998
1999" ---------------------------------------------------------------------
2000" NetrwStatusLine: {{{2
2001fun! NetrwStatusLine()
2002
2003" vvv NetrwStatusLine() debugging vvv
2004" let g:stlmsg=""
2005" if !exists("w:netrw_explore_bufnr")
2006" let g:stlmsg="!X<explore_bufnr>"
2007" elseif w:netrw_explore_bufnr != bufnr("%")
2008" let g:stlmsg="explore_bufnr!=".bufnr("%")
2009" endif
2010" if !exists("w:netrw_explore_line")
2011" let g:stlmsg=" !X<explore_line>"
2012" elseif w:netrw_explore_line != line(".")
2013" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2014" endif
2015" if !exists("w:netrw_explore_list")
2016" let g:stlmsg=" !X<explore_list>"
2017" endif
2018" ^^^ NetrwStatusLine() debugging ^^^
2019
2020 if !exists("w:netrw_explore_bufnr") || w:netrw_explore_bufnr != bufnr("%") || !exists("w:netrw_explore_line") || w:netrw_explore_line != line(".") || !exists("w:netrw_explore_list")
2021 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002022 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002023 let &laststatus = s:netrw_users_ls
2024 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2025 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2026 return ""
2027 else
2028 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2029 endif
2030endfun
2031
Bram Moolenaar85850f32019-07-19 22:05:51 +02002032" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002033" Netrw Transfer Functions: {{{1
2034" ===============================
2035
Bram Moolenaar071d4272004-06-13 20:20:40 +00002036" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002037" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002038" mode: =0 read remote file and insert before current line
2039" =1 read remote file and insert after current line
2040" =2 replace with remote file
2041" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002042fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002043" call Dfunc("netrw#NetRead(mode=".a:mode.",...) a:0=".a:0." ".g:loaded_netrw.((a:0 > 0)? " a:1<".a:1.">" : ""))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002044
Bram Moolenaar5c736222010-01-06 20:54:52 +01002045 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002046 call s:NetrwOptionsSave("w:")
2047 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002048 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002049 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2050 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2051 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002052" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002053
Bram Moolenaar5c736222010-01-06 20:54:52 +01002054 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002055 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002056 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002057 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002058 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002059 elseif a:mode == 2 " replace with remote file
2060 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002061 elseif a:mode == 3 " skip read of file (leave as temporary)
2062 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002063 else
2064 exe a:mode
2065 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002066 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002067 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002068" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002069
Bram Moolenaar5c736222010-01-06 20:54:52 +01002070 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002071 let tmpfile= s:GetTempfile("")
2072 if tmpfile == ""
2073" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002074 return
2075 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002076
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002078
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002079 " attempt to repeat with previous host-file-etc
2080 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002081" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002082 let choice = b:netrw_lastfile
2083 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002084
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002085 else
2086 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002087" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002088
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002089 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002090 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002091 echomsg 'NetRead Usage:'
2092 echomsg ':Nread machine:path uses rcp'
2093 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2094 echomsg ':Nread "machine id password path" uses ftp'
2095 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2096 echomsg ':Nread fetch://machine/path uses fetch'
2097 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2098 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002099 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002100 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002101 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2102 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2103 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2104 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002105 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002106 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002107
Bram Moolenaar9964e462007-05-05 17:54:07 +00002108 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002109 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002110" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002111 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002113 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002114 else
2115 " case "... ... ..."
2116 let choice = strpart(choice,1,strlen(choice)-1)
2117 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002118
Bram Moolenaar9964e462007-05-05 17:54:07 +00002119 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002120 let wholechoice = wholechoice . " " . choice
2121 let ichoice = ichoice + 1
2122 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002123 if !exists("g:netrw_quiet")
2124 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2125 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002126" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002127 return
2128 endif
2129 let choice= a:{ichoice}
2130 endwhile
2131 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2132 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002133 endif
2134 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002136" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002137 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002138
Bram Moolenaar5c736222010-01-06 20:54:52 +01002139 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002140 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002141 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002142" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002143 return
2144 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002145 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002146
Bram Moolenaar8d043172014-01-23 14:24:41 +01002147 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002148" call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02002149 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002150" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002151 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002152" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002153 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002155
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002156 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002157 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002158 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002159 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2160 echo "(netrw) Processing your read request..."
2161 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002162
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002163 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002164 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002165 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002166" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002167 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002168 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002169 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002170 " ER: the tmpfile is full path: rcp sees C:\... as host C
2171 if s:netrw_has_nt_rcp == 1
2172 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2173 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2174 else
2175 " Any way needed it machine contains a '.'
2176 let uid_machine = g:netrw_machine .'.'. $USERNAME
2177 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002178 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002179 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2180 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2181 else
2182 let uid_machine = g:netrw_machine
2183 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002184 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002185 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".s:ShellEscape(uid_machine.":".b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002186 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002187 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002188
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002189 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002190 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002191 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002192" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002193 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002194 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002195 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002196 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002197 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002198" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002199 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002200 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002201" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002202 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002203 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002204" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002205 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002206 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002207 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002208 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002209 endif
2210 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar83bab712005-08-01 21:58:57 +00002211 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002212 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002213 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002214 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002215 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002216 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002217 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002218 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002219 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2220 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002221 q!
2222 endif
2223 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002224 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002225 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002226
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002227 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002228 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2230 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002231" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002232 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002233 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002234 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002235 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002236 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002237 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002238" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002239 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002240 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002241" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002242 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002243
Bram Moolenaar97d62492012-11-15 21:28:22 +01002244 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002245 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002246 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002247" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002248 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002249 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002250 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002251" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002252 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002253 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002255 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002256 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002257
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002258 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002259 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002260" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002261 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002262 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002263 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002264" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002265 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002266 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002267" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002268
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002269 " perform ftp:
2270 " -i : turns off interactive prompting from ftp
2271 " -n unix : DON'T use <.netrc>, even though it exists
2272 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002273 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002274 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002275 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2276 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002277" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002278 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002279 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002280 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002281 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002282 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002283 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002285
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002286 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002287 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002288 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002289" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002290 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002291 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002292 else
2293 let useport= ""
2294 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002295 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2296 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002297 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002298 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2299 else
2300 let tmpfile_get = tmpfile
2301 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002302 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".escape(s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1),' ')." ".s:ShellEscape(tmpfile_get,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002303 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002304 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002305
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002306 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002307 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002308 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002309" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002310 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002311 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002312 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002313 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002314" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002315 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002316 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002317
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002318 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2319 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002320" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002321 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002322 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".s:ShellEscape(tmpfile,1))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002323 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002324 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002325 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002326 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002327
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002328 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002329 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002330" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002331 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2332 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002333" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2334" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2335 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.netrw_html,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002336 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002337" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002338 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002339 endif
2340 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002341" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002342 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002343
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002344 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002345 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002346 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002347" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002348
Bram Moolenaar5c736222010-01-06 20:54:52 +01002349 if !executable(g:netrw_dav_cmd)
2350 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2351" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2352 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002353 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002354 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002355 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_dav_cmd." ".s:ShellEscape("dav://".g:netrw_machine.b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002356 else
2357 " Construct execution string (four lines) which will be passed through filter
2358 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2359 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002360 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002361 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002362 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002363 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002364 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002365 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002366 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002367 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002368 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002369 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2370 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002371
Bram Moolenaar5c736222010-01-06 20:54:52 +01002372 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002373 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002374 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002375 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002376 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002377 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002378 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002379
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002380 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002381 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002382 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002383" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002384 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".s:ShellEscape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002385 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002387
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002388 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002389 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002390 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002391 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002392" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002394 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002395 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002396 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002397" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002398 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002399 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002400 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002401 let netrw_option= "http"
2402 else
2403 let netrw_option= "ftp"
2404 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002405" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002406
Bram Moolenaar446cb832008-06-24 21:56:24 +00002407 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002408 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002409 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002410 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002411 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002412
Bram Moolenaar446cb832008-06-24 21:56:24 +00002413 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002414 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002415" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002416 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002417
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002418 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002419 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002420 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002421" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2422 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002423 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002424 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002425
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002426 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002427 " NetRead: (file) NetRead Method #10 {{{3
2428 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002429" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2430 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002431 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2432 let b:netrw_lastfile = choice
2433
2434 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002435 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002436 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002437 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002438 endif
2439 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002440
Bram Moolenaar5c736222010-01-06 20:54:52 +01002441 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002442 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002443" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002444 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002445 unlet b:netrw_fname
2446 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002447 if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' && tmpfile !~ '.tar.xz$' && tmpfile !~ '.txz'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002448" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002449 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002450 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002451 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002452
Bram Moolenaar9964e462007-05-05 17:54:07 +00002453" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002454endfun
2455
2456" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002457" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002458fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002459" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002460
Bram Moolenaar5c736222010-01-06 20:54:52 +01002461 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002462 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002463 call s:NetrwOptionsSave("w:")
2464 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002465
Bram Moolenaar5c736222010-01-06 20:54:52 +01002466 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002467 let tmpfile= s:GetTempfile("")
2468 if tmpfile == ""
2469" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002470 return
2471 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002472
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002473 if a:0 == 0
2474 let ichoice = 0
2475 else
2476 let ichoice = 1
2477 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002478
Bram Moolenaar9964e462007-05-05 17:54:07 +00002479 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002480" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002481 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002482 " For binary writes, always write entire file.
2483 " (line numbers don't really make sense for that).
2484 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002485" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002486 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002487 elseif g:netrw_cygwin
2488 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002489 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002490" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002491 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002492 else
2493 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002494" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002495 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002496 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002497
Bram Moolenaar9964e462007-05-05 17:54:07 +00002498 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002499 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002500 " on the temporary file's name. Deletion of the temporary file during
2501 " cleanup then causes an error message.
2502 0file!
2503 endif
2504
Bram Moolenaar5c736222010-01-06 20:54:52 +01002505 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002506 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002507
Bram Moolenaar9964e462007-05-05 17:54:07 +00002508 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002509 " attempt to repeat with previous host-file-etc
2510 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002511" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002512 let choice = b:netrw_lastfile
2513 let ichoice= ichoice + 1
2514 else
2515 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002516
Bram Moolenaar8d043172014-01-23 14:24:41 +01002517 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002518 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002519 echomsg 'NetWrite Usage:"'
2520 echomsg ':Nwrite machine:path uses rcp'
2521 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2522 echomsg ':Nwrite "machine id password path" uses ftp'
2523 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2524 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2525 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2526 echomsg ':Nwrite rcp://machine/path uses rcp'
2527 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2528 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2529 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002530 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002531 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002532
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002533 elseif match(choice,"^\"") != -1
2534 if match(choice,"\"$") != -1
2535 " case "..."
2536 let choice=strpart(choice,1,strlen(choice)-2)
2537 else
2538 " case "... ... ..."
2539 let choice = strpart(choice,1,strlen(choice)-1)
2540 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002541
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002542 while match(choice,"\"$") == -1
2543 let wholechoice= wholechoice . " " . choice
2544 let ichoice = ichoice + 1
2545 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002546 if !exists("g:netrw_quiet")
2547 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2548 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002549" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002550 return
2551 endif
2552 let choice= a:{ichoice}
2553 endwhile
2554 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2555 endif
2556 endif
2557 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002558 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002559" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002560
Bram Moolenaar9964e462007-05-05 17:54:07 +00002561 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002562 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002563 if !exists("b:netrw_method") || b:netrw_method < 0
2564" call Dfunc("netrw#NetWrite : unsupported method")
2565 return
2566 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002567
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002568 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002569 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002570 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002571 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2572 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002573" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002574 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002575
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002576 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002577 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002578 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002579" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002580 if s:netrw_has_nt_rcp == 1
2581 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2582 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2583 else
2584 let uid_machine = g:netrw_machine .'.'. $USERNAME
2585 endif
2586 else
2587 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2588 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2589 else
2590 let uid_machine = g:netrw_machine
2591 endif
2592 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002593 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(uid_machine.":".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002594 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002595
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002596 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002597 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002598 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002599" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002600 let netrw_fname = b:netrw_fname
2601
2602 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2603 let bhkeep = &l:bh
2604 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002605 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002607
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002608" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002609 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002610 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002612 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002613 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002614" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002615 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002616 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002617" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002619 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002621" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2622 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 endif
2624 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2625 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002626 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002627 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002628 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002629 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002631
2632 " remove enew buffer (quietly)
2633 let filtbuf= bufnr("%")
2634 exe curbuf."b!"
2635 let &l:bh = bhkeep
2636 exe filtbuf."bw!"
2637
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002639
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002640 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002641 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002642 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002643 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002644" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002645 let netrw_fname = b:netrw_fname
2646 let bhkeep = &l:bh
2647
2648 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2649 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002650 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002651 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002652 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002653
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002654 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002655 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002656" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002657 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002658 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002659" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002660 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002661 if exists("g:netrw_uid") && g:netrw_uid != ""
2662 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002663 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002664" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002665 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002666 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002667 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002668" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002669 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002670 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002671" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002672 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002673 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002674 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002675" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002676 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002677 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002678" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002679 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002680 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002681" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002682 " save choice/id/password for future use
2683 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002684
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002685 " perform ftp:
2686 " -i : turns off interactive prompting from ftp
2687 " -n unix : DON'T use <.netrc>, even though it exists
2688 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002689 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002690 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002691 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2692 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002693 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002694 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002695 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002696 let mod=1
2697 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002698
2699 " remove enew buffer (quietly)
2700 let filtbuf= bufnr("%")
2701 exe curbuf."b!"
2702 let &l:bh= bhkeep
2703 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002704
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002705 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002706 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002707 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002708" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002709 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002710 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002711 else
2712 let useport= ""
2713 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002714 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002715 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002716
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002717 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002718 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002719 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002720" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002721 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2722 if executable(curl)
2723 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002724 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_put_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(url,1) )
Bram Moolenaar8d043172014-01-23 14:24:41 +01002725 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002726 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002727 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002728
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002729 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002730 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002731 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002732" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002733
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002734 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002735 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2736 let bhkeep = &l:bh
2737
2738 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2739 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002740 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002741 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002742
Bram Moolenaarff034192013-04-24 18:51:19 +02002743 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002744 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002745 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002746 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002747 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002748 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002749 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002750 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002751 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002752 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002753
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002754 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002755 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002756 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002757
2758 " remove enew buffer (quietly)
2759 let filtbuf= bufnr("%")
2760 exe curbuf."b!"
2761 let &l:bh = bhkeep
2762 exe filtbuf."bw!"
2763
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002764 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002765
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002766 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002767 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002768 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002769" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002770 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002771 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002772
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002773 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002774 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002775 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002776" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002777 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2779 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2780 else
2781 let uid_machine = g:netrw_machine
2782 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002783
2784 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2785 let bhkeep = &l:bh
2786 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002787 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002788 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002789
Bram Moolenaarff034192013-04-24 18:51:19 +02002790 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002791 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002792" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002793 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002794 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002795 let filtbuf= bufnr("%")
2796 exe curbuf."b!"
2797 let &l:bh = bhkeep
2798 exe filtbuf."bw!"
2799 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002800
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002801 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002802 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002803 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002804 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002805 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002807 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002808
Bram Moolenaar5c736222010-01-06 20:54:52 +01002809 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002810" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002811 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002812" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002813 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002814 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002815 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002816
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002817 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002818 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002819 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002820" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02002821 elseif !exists("leavemod")
2822 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002823" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002824 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002825" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002827
Bram Moolenaar9964e462007-05-05 17:54:07 +00002828" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002829endfun
2830
2831" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002832" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002833" uses NetRead to get a copy of the file into a temporarily file,
2834" then sources that file,
2835" then removes that file.
2836fun! netrw#NetSource(...)
2837" call Dfunc("netrw#NetSource() a:0=".a:0)
2838 if a:0 > 0 && a:1 == '?'
2839 " give help
2840 echomsg 'NetSource Usage:'
2841 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2842 echomsg ':Nsource fetch://machine/path uses fetch'
2843 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002844 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002845 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2846 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2847 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2848 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2849 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002850 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002851 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002852 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002853 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002854" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002855 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002856" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002857 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002858" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002859 if delete(s:netrw_tmpfile)
2860 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2861 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002862 unlet s:netrw_tmpfile
2863 else
2864 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2865 endif
2866 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002867 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002868 endif
2869" call Dret("netrw#NetSource")
2870endfun
2871
Bram Moolenaar8d043172014-01-23 14:24:41 +01002872" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002873" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2874" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002875fun! netrw#SetTreetop(iscmd,...)
2876" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2877" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002878
Bram Moolenaar85850f32019-07-19 22:05:51 +02002879 " iscmd==0: netrw#SetTreetop called using gn mapping
2880 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2881" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002882 " clear out the current tree
2883 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002884" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002885 let inittreetop= w:netrw_treetop
2886 unlet w:netrw_treetop
2887 endif
2888 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002889" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002890 unlet w:netrw_treedict
2891 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002892" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002893
Bram Moolenaar85850f32019-07-19 22:05:51 +02002894 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002895 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002896" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002897 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002898 if isdirectory(s:NetrwFile(a:1))
2899" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002900 let treedir = a:1
2901 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002902 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002903 let treedir = b:netrw_curdir."/".a:1
2904 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002905" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002906 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002907 " normally the cursor is left in the message window.
2908 " However, here this results in the directory being listed in the message window, which is not wanted.
2909 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002910 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002911 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002912 let treedir = "."
2913 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002914 endif
2915 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002916" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002917
2918 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002919 let islocal= expand("%") !~ '^\a\{3,}://'
2920" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002921
2922 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002923 if islocal
2924 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2925 else
2926 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2927 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002928
Bram Moolenaara6878372014-03-22 21:02:50 +01002929" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002930endfun
2931
Bram Moolenaar9964e462007-05-05 17:54:07 +00002932" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002933" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002934" readcmd == %r : replace buffer with newly read file
2935" == 0r : read file at top of buffer
2936" == r : read file after current line
2937" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002938fun! s:NetrwGetFile(readcmd, tfile, method)
2939" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002940
2941 " readcmd=='t': simply do nothing
2942 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002943" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01002944" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002945 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002946 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002947
Bram Moolenaar9964e462007-05-05 17:54:07 +00002948 " get name of remote filename (ie. url and all)
2949 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002950" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002951
Bram Moolenaar9964e462007-05-05 17:54:07 +00002952 if exists("*NetReadFixup")
2953 " for the use of NetReadFixup (not otherwise used internally)
2954 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002955 endif
2956
Bram Moolenaar9964e462007-05-05 17:54:07 +00002957 if a:readcmd[0] == '%'
2958 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002959" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002960
2961 " rename the current buffer to the temp file (ie. tfile)
2962 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002963 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002964 else
2965 let tfile= a:tfile
2966 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002967 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002968
2969 " edit temporary file (ie. read the temporary file in)
2970 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002971" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002972 call zip#Browse(tfile)
2973 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002974" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002975 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002976 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002977" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002978 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002979 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002981 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002982 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002983" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002984 call tar#Browse(tfile)
2985 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002986" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002987 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002988 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002989" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002990 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002991 endif
2992
2993 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002994 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002995
Bram Moolenaar71badf92023-04-22 22:40:14 +01002996 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002997 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002998 " Note that isk must not include a "/" for scripts.vim
2999 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01003000" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
3001" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003002" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003003" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3004 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003005 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003006 filetype detect
3007" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003008 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003009" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003010 let line1 = 1
3011 let line2 = line("$")
3012
Bram Moolenaar8d043172014-01-23 14:24:41 +01003013 elseif !&ma
3014 " attempting to read a file after the current line in the file, but the buffer is not modifiable
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003015 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003016" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003017 return
3018
Bram Moolenaar9964e462007-05-05 17:54:07 +00003019 elseif s:FileReadable(a:tfile)
3020 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003021" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003022 let curline = line(".")
3023 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003024" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003025 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003026 let line1= curline + 1
3027 let line2= line("$") - lastline + 1
3028
3029 else
3030 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003031" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3032" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003033 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003034" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003035 return
3036 endif
3037
3038 " User-provided (ie. optional) fix-it-up command
3039 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003040" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003041 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003042" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003043" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003044 endif
3045
Bram Moolenaaradc21822011-04-01 18:03:16 +02003046 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003047 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003048 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003049 endif
3050
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003051" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003052
3053 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003054" redraw!
3055
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003056" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003057" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003058endfun
3059
Bram Moolenaar9964e462007-05-05 17:54:07 +00003060" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003061" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003062" Input:
3063" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3064" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003065" b:netrw_method= 1: rcp
3066" 2: ftp + <.netrc>
3067" 3: ftp + machine, id, password, and [path]filename
3068" 4: scp
3069" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003070" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003071" 7: rsync
3072" 8: fetch
3073" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003074" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003075" g:netrw_machine= hostname
3076" b:netrw_fname = filename
3077" g:netrw_port = optional port number (for ftp)
3078" g:netrw_choice = copy of input url (choice)
3079fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003080" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003081
Bram Moolenaar251e1912011-06-19 05:09:16 +02003082 " sanity check: choice should have at least three slashes in it
3083 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3084 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3085 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003086" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003087 return
3088 endif
3089
Bram Moolenaar5c736222010-01-06 20:54:52 +01003090 " record current g:netrw_machine, if any
3091 " curmachine used if protocol == ftp and no .netrc
3092 if exists("g:netrw_machine")
3093 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003094" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003095 else
3096 let curmachine= "N O T A HOST"
3097 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003098 if exists("g:netrw_port")
3099 let netrw_port= g:netrw_port
3100 endif
3101
3102 " insure that netrw_ftp_cmd starts off every method determination
3103 " with the current g:netrw_ftp_cmd
3104 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003105
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003106 " initialization
3107 let b:netrw_method = 0
3108 let g:netrw_machine = ""
3109 let b:netrw_fname = ""
3110 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003111 let g:netrw_choice = a:choice
3112
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003113 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003114 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003115 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3116 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003117 " rcpurm : rcp://[user@]host/filename Use rcp
3118 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003119 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003120 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003121 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003122 " rsyncurm : rsync://host[:port]/path Use rsync
3123 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3124 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003125 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3127 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003128 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3129 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003130 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003131 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003132 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003133 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003135 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003136 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003137 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003138
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003139" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003140 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003141 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003142 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003143" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003144 let b:netrw_method = 1
3145 let userid = substitute(a:choice,rcpurm,'\1',"")
3146 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3147 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003148 if userid != ""
3149 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003151
Bram Moolenaaradc21822011-04-01 18:03:16 +02003152 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003153 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003154" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003155 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003156 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3157 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3158 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003159
Bram Moolenaar15146672011-10-20 22:22:38 +02003160 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003161 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003162" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003163 let b:netrw_method = 5
3164 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3165 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003166 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003167
Bram Moolenaaradc21822011-04-01 18:03:16 +02003168 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003169 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003170" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003171 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003172 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003173 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3174 else
3175 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3176 endif
3177 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003178
Bram Moolenaaradc21822011-04-01 18:03:16 +02003179 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003180 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003181" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003182 let b:netrw_method = 7
3183 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3184 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003185
Bram Moolenaaradc21822011-04-01 18:03:16 +02003186 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003187 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003188" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003189 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003190 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3191 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3192 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003193" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003194 if userid != ""
3195 let g:netrw_uid= userid
3196 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003197
Bram Moolenaaradc21822011-04-01 18:03:16 +02003198 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003199 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003200 call NetUserPass("ftp:".g:netrw_machine)
3201 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003202 " if there's a change in hostname, require password re-entry
3203 unlet s:netrw_passwd
3204 endif
3205 if exists("netrw_port")
3206 unlet netrw_port
3207 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003208 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003209
Bram Moolenaar446cb832008-06-24 21:56:24 +00003210 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003211 let b:netrw_method = 3
3212 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003213 let host= substitute(g:netrw_machine,'\..*$','','')
3214 if exists("s:netrw_hup[host]")
3215 call NetUserPass("ftp:".host)
3216
Nir Lichtman1e34b952024-05-08 19:19:34 +02003217 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003218" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3219" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003220 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003221 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003222" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003223 endif
3224 let b:netrw_method= 2
3225 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003226" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003227 let b:netrw_method= 2
3228 else
3229 if !exists("g:netrw_uid") || g:netrw_uid == ""
3230 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003231 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003232 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003233 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003234 endif
3235 let b:netrw_method= 3
3236 endif
3237 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003238
Bram Moolenaaradc21822011-04-01 18:03:16 +02003239 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003240 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003241" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003242 let b:netrw_method = 8
3243 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3244 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3245 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3246 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003247
Bram Moolenaaradc21822011-04-01 18:03:16 +02003248 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003249 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003250" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003252 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3253 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003254 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003255 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003256 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003257
Bram Moolenaaradc21822011-04-01 18:03:16 +02003258 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003259 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003260" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003261 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003262 let b:netrw_method = 3
3263 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3264 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003265
Bram Moolenaar9964e462007-05-05 17:54:07 +00003266 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003267 let b:netrw_method = 2
3268 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3269 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3270 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003271
Bram Moolenaaradc21822011-04-01 18:03:16 +02003272 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003273 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003274" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003275 let b:netrw_method = 9
3276 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3277 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003278
Bram Moolenaaradc21822011-04-01 18:03:16 +02003279 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003280 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003281" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003282 let b:netrw_method = 1
3283 let userid = substitute(a:choice,rcphf,'\2',"")
3284 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3285 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003286" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3287" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3288" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3289" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003290 if userid != ""
3291 let g:netrw_uid= userid
3292 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003293
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003294 " Method#10: file://user@hostname/...path-to-file {{{3
3295 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003296" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003297 let b:netrw_method = 10
3298 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003299" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003300
Bram Moolenaaradc21822011-04-01 18:03:16 +02003301 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003302 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003303 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003304 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003305 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003306 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003308 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003309
Bram Moolenaar81695252004-12-29 20:58:21 +00003310 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003311 " remove any leading [:#] from port number
3312 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3313 elseif exists("netrw_port")
3314 " retain port number as implicit for subsequent ftp operations
3315 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003316 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003317
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003318" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3319" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3320" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3321" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003322" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003323" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003324" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003325" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003326" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003327" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003328" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003329" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331
Bram Moolenaar9964e462007-05-05 17:54:07 +00003332" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003333" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003334" Usage: :call NetUserPass() -- will prompt for userid and password
3335" :call NetUserPass("uid") -- will prompt for password
3336" :call NetUserPass("uid","password") -- sets global userid and password
3337" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3338" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339fun! NetUserPass(...)
3340
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003341" call Dfunc("NetUserPass() a:0=".a:0)
3342
3343 if !exists('s:netrw_hup')
3344 let s:netrw_hup= {}
3345 endif
3346
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003348 " case: no input arguments
3349
3350 " change host and username if not previously entered; get new password
3351 if !exists("g:netrw_machine")
3352 let g:netrw_machine= input('Enter hostname: ')
3353 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003355 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356 let g:netrw_uid= input('Enter username: ')
3357 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003358 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003359 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003360
3361 " set up hup database
3362 let host = substitute(g:netrw_machine,'\..*$','','')
3363 if !exists('s:netrw_hup[host]')
3364 let s:netrw_hup[host]= {}
3365 endif
3366 let s:netrw_hup[host].uid = g:netrw_uid
3367 let s:netrw_hup[host].passwd = s:netrw_passwd
3368
3369 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003370 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003371
3372 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003373 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003374 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003375" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003376 let host = substitute(a:1,'^ftp:','','')
3377 let host = substitute(host,'\..*','','')
3378 if exists("s:netrw_hup[host]")
3379 let g:netrw_uid = s:netrw_hup[host].uid
3380 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003381" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3382" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003383 else
3384 let g:netrw_uid = input("Enter UserId: ")
3385 let s:netrw_passwd = inputsecret("Enter Password: ")
3386 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003387
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003388 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003389 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003390" call Decho("case a:0=1: a:1<".a:1."> (get host from input argument, not an url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003391 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003392 if g:netrw_machine =~ '[0-9.]\+'
3393 let host= g:netrw_machine
3394 else
3395 let host= substitute(g:netrw_machine,'\..*$','','')
3396 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003397 else
3398 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003399 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003400 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003401" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003402 if exists("g:netrw_passwd")
3403 " ask for password if one not previously entered
3404 let s:netrw_passwd= g:netrw_passwd
3405 else
3406 let s:netrw_passwd = inputsecret("Enter Password: ")
3407 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003408 endif
3409
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003410" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003411 if exists("host")
3412 if !exists('s:netrw_hup[host]')
3413 let s:netrw_hup[host]= {}
3414 endif
3415 let s:netrw_hup[host].uid = g:netrw_uid
3416 let s:netrw_hup[host].passwd = s:netrw_passwd
3417 endif
3418
3419 elseif a:0 == 2
3420 let g:netrw_uid = a:1
3421 let s:netrw_passwd = a:2
3422
3423 elseif a:0 == 3
3424 " enter hostname, user-id, and password into the hup dictionary
3425 let host = substitute(a:1,'^\a\+:','','')
3426 let host = substitute(host,'\..*$','','')
3427 if !exists('s:netrw_hup[host]')
3428 let s:netrw_hup[host]= {}
3429 endif
3430 let s:netrw_hup[host].uid = a:2
3431 let s:netrw_hup[host].passwd = a:3
3432 let g:netrw_uid = s:netrw_hup[host].uid
3433 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003434" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3435" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003436 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003437
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003438" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440
Bram Moolenaar85850f32019-07-19 22:05:51 +02003441" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003442" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003443" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003444
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003445" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003446" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3447fun! s:ExplorePatHls(pattern)
3448" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3449 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003450" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003451 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003452" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003453 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3454" call Dret("s:ExplorePatHls repat<".repat.">")
3455 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003456endfun
3457
3458" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003459" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003460" 0: (user: <mb>) bookmark current directory
3461" 1: (user: <gb>) change to the bookmarked directory
3462" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003463" 3: (browsing) records current directory history
3464" 4: (user: <u>) go up (previous) directory, using history
3465" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003466" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003467fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003468" call Dfunc("s:NetrwBookHistHandler(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count." histcnt=".g:netrw_dirhistcnt." histmax=".g:netrw_dirhistmax)
Bram Moolenaarff034192013-04-24 18:51:19 +02003469 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3470" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3471 return
3472 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003473
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003474 let ykeep = @@
3475 let curbufnr = bufnr("%")
3476
Bram Moolenaar9964e462007-05-05 17:54:07 +00003477 if a:chg == 0
3478 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003479" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003480 if exists("s:netrwmarkfilelist_{curbufnr}")
3481 call s:NetrwBookmark(0)
3482 echo "bookmarked marked files"
3483 else
3484 call s:MakeBookmark(a:curdir)
3485 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003486 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003487
KSR-Yasudaf4498252023-10-06 03:34:17 +09003488 try
3489 call s:NetrwBookHistSave()
3490 catch
3491 endtry
3492
Bram Moolenaar9964e462007-05-05 17:54:07 +00003493 elseif a:chg == 1
3494 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003495" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003496 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003497" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003498 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003499 else
3500 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3501 endif
3502
3503 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003504" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003505 let didwork= 0
3506 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003507" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003508 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003509" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003510 let cnt= 1
3511 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003512" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003513 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003514 let didwork = 1
3515 let cnt = cnt + 1
3516 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003517 endif
3518
3519 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003520 " Note: history is saved only when PerformListing is done;
3521 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3522 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003523 let first = 1
3524 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003525 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003526 while ( first || cnt != g:netrw_dirhistcnt )
3527" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003528 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003529" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003530 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003531 let didwork= 1
3532 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003533 let histcnt = histcnt + 1
3534 let first = 0
3535 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003536 if cnt < 0
3537 let cnt= cnt + g:netrw_dirhistmax
3538 endif
3539 endwhile
3540 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003541 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003542 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003543 if didwork
3544 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3545 endif
3546
3547 elseif a:chg == 3
3548 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003549" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003550 if !exists("g:netrw_dirhistcnt") || !exists("g:netrw_dirhist_{g:netrw_dirhistcnt}") || g:netrw_dirhist_{g:netrw_dirhistcnt} != a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003551 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003552 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3553 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003554 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003555" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003556 endif
3557
3558 elseif a:chg == 4
3559 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003560" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003561 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003562 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3563 if g:netrw_dirhistcnt < 0
3564 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003565 endif
3566 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003567 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003568 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003569 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3570" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003571 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003572 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003573" call Decho("setl ma noro",'~'.expand("<slnum>"))
3574 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003575 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003576" call Decho("setl nomod",'~'.expand("<slnum>"))
3577" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003578 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003579" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3580 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003581 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003582 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003583 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003584 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003585 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003586 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003587 echo "Sorry, no predecessor directory exists yet"
3588 endif
3589
3590 elseif a:chg == 5
3591 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003592" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003593 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003594 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3595 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3596" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003597 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003598" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003599 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003600 sil! NetrwKeepj %d _
3601" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3602" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003603 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003604" call Decho("(set nomod) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003605 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003606" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3607 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003608 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003609 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3610 if g:netrw_dirhistcnt < 0
3611 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003612 endif
3613 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003614 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003615 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003616 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003617 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003618 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003619
3620 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003621" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003622 if exists("s:netrwmarkfilelist_{curbufnr}")
3623 call s:NetrwBookmark(1)
3624 echo "removed marked files from bookmarks"
3625 else
3626 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003627 let iremove = v:count
3628 let dremove = g:netrw_bookmarklist[iremove - 1]
3629" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003630 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003631" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3632 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3633 echo "removed ".dremove." from g:netrw_bookmarklist"
3634" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003635 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003636" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003637
3638 try
3639 call s:NetrwBookHistSave()
3640 catch
3641 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003642 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003643 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003644 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003645 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003646" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003647endfun
3648
3649" ---------------------------------------------------------------------
3650" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003651" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003652" Sister function: s:NetrwBookHistSave()
3653fun! s:NetrwBookHistRead()
3654" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003655 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003656" call Dret("s:NetrwBookHistRead - nothing read (suppressed due to dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a").")")
Bram Moolenaarff034192013-04-24 18:51:19 +02003657 return
3658 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003659 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003660
3661 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003662 if !exists("s:netrw_initbookhist")
3663 let home = s:NetrwHome()
3664 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003665 if filereadable(s:NetrwFile(savefile))
3666" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003667 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003668 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003669
3670 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003671 if g:netrw_dirhistmax > 0
3672 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003673 if filereadable(s:NetrwFile(savefile))
3674" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003675 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003676 endif
3677 let s:netrw_initbookhist= 1
3678 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003679 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003680 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003681
Bram Moolenaar97d62492012-11-15 21:28:22 +01003682 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003683" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3684" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003685" call Dret("s:NetrwBookHistRead")
3686endfun
3687
3688" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003689" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003690" Sister function: s:NetrwBookHistRead()
3691" I used to do this via viminfo but that appears to
3692" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003693" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3694" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003695" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003696fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003697" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003698 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003699" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003700 return
3701 endif
3702
Bram Moolenaar5c736222010-01-06 20:54:52 +01003703 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003704" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003705 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003706
3707 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003708 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003709" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003710 if g:netrw_use_noswf
3711 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3712 else
3713 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3714 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003715 setl nocin noai noci magic nospell nohid wig= noaw
3716 setl ma noro write
3717 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003718 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003719
Bram Moolenaar85850f32019-07-19 22:05:51 +02003720 " rename enew'd file: .netrwhist -- no attempt to merge
3721 " record dirhistmax and current dirhistcnt
3722 " save history
3723" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003724 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003725 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003726 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3727 if g:netrw_dirhistmax > 0
3728 let lastline = line("$")
3729 let cnt = g:netrw_dirhistcnt
3730 let first = 1
3731 while ( first || cnt != g:netrw_dirhistcnt )
3732 let lastline= lastline + 1
3733 if exists("g:netrw_dirhist_{cnt}")
3734 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3735" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3736 endif
3737 let first = 0
3738 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3739 if cnt < 0
3740 let cnt= cnt + g:netrw_dirhistmax
3741 endif
3742 endwhile
3743 exe "sil! w! ".savefile
3744" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3745 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003746
Bram Moolenaar85850f32019-07-19 22:05:51 +02003747 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003748 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003749 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003750" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003751 " merge and write .netrwbook
3752 let savefile= s:NetrwHome()."/.netrwbook"
3753
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003754 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003755 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003756 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003757 for bdm in booklist
3758 if index(g:netrw_bookmarklist,bdm) == -1
3759 call add(g:netrw_bookmarklist,bdm)
3760 endif
3761 endfor
3762 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003763 endif
3764
3765 " construct and save .netrwbook
3766 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003767 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003768" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003769 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003770
3771 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003772 let bgone= bufnr("%")
3773 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003774 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003775
3776" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003777endfun
3778
3779" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003780" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3781" list of the contents of a local or remote directory. It is assumed that the
3782" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3783" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003784" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003785fun! s:NetrwBrowse(islocal,dirname)
3786 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003787" call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
Bram Moolenaar85850f32019-07-19 22:05:51 +02003788" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3789" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3790" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003791
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003792 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3793 " This is useful when one edits a local file, then :e ., then :Rex
3794 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3795 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003796" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003797 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003798
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003799 " s:NetrwBrowse : initialize history {{{3
3800 if !exists("s:netrw_initbookhist")
3801 NetrwKeepj call s:NetrwBookHistRead()
3802 endif
3803
3804 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003805 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003806 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003807" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003808 else
3809 let dirname= a:dirname
3810 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003811
Bram Moolenaar85850f32019-07-19 22:05:51 +02003812 " repoint t:netrw_lexbufnr if appropriate
3813 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3814" call Decho("set repointlexbufnr to true!")
3815 let repointlexbufnr= 1
3816 endif
3817
3818 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003819 if exists("s:netrw_skipbrowse")
3820 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003821" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." filename<".expand("%")."> win#".winnr()." ft<".&ft.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01003822" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003823 return
3824 endif
3825 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003826 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003827" call Dret("s:NetrwBrowse : missing shellescape()")
3828 return
3829 endif
3830 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003831 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003832" call Dret("s:NetrwBrowse : missing fnameescape()")
3833 return
3834 endif
3835
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003836 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003837 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003838
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003839 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003840 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3841 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3842" call Decho("clearing marked files",'~'.expand("<slnum>"))
3843 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3844 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003845 endif
3846
3847 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003848 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003849" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3850" call Decho("NetrwKeepj lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003851 if s:NetrwLcd(dirname)
3852" call Dret("s:NetrwBrowse : lcd failure")
3853 return
3854 endif
3855 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003856" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003857
Bram Moolenaar5c736222010-01-06 20:54:52 +01003858 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003859 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003860" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003861 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003862" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003863 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003864 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003865 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003866" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003867
3868 " remove any filetype indicator from end of dirname, except for the
3869 " "this is a directory" indicator (/).
3870 " There shouldn't be one of those here, anyway.
3871 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003872" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003873 call s:RemotePathAnalysis(dirname)
3874
3875 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3876 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003877 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003878 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003879" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003880 let b:netrw_curdir = dirname
3881 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003882 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003883 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3884 sil call netrw#NetRead(2,url)
3885 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003886" call Decho("url<".url.">",'~'.expand("<slnum>"))
3887" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3888" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003889 if s:path =~ '.bz2'
3890 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3891 elseif s:path =~ '.gz'
3892 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3893 elseif s:path =~ '.gz'
3894 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3895 else
3896 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3897 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003898 endif
3899
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003900 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003901 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003902 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003903" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003904 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003905" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003906
Bram Moolenaar446cb832008-06-24 21:56:24 +00003907" call Dret("s:NetrwBrowse : file<".s:fname.">")
3908 return
3909 endif
3910
Bram Moolenaaradc21822011-04-01 18:03:16 +02003911 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003912 call s:UseBufWinVars()
3913
3914 " set up some variables {{{3
3915 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003916 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003917 let s:last_sort_by = g:netrw_sort_by
3918
3919 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003920 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003921
Bram Moolenaar97d62492012-11-15 21:28:22 +01003922 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003923" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003924 let svpos = winsaveview()
3925" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003926 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003927
Bram Moolenaar446cb832008-06-24 21:56:24 +00003928 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003929 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3930 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3931" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3932" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3933 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3934 else
3935" " call Decho("2match none",'~'.expand("<slnum>"))
3936 2match none
3937 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003938 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003939 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003940 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003941" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003942 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003943" call Decho("(set noma nomod nowrap) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003944" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003945 return
3946 endif
3947
3948 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003949" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003950 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003951 if b:netrw_curdir =~ '[/\\]$'
3952 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3953 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003954 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003955 let b:netrw_curdir= b:netrw_curdir."/"
3956 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003957 if b:netrw_curdir == ''
3958 if has("amiga")
3959 " On the Amiga, the empty string connotes the current directory
3960 let b:netrw_curdir= getcwd()
3961 else
3962 " under unix, when the root directory is encountered, the result
3963 " from the preceding substitute is an empty string.
3964 let b:netrw_curdir= '/'
3965 endif
3966 endif
3967 if !a:islocal && b:netrw_curdir !~ '/$'
3968 let b:netrw_curdir= b:netrw_curdir.'/'
3969 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003970" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003971
3972 " ------------
3973 " (local only) {{{3
3974 " ------------
3975 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003976" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003977
3978 " Set up ShellCmdPost handling. Append current buffer to browselist
3979 call s:LocalFastBrowser()
3980
3981 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3982 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003983" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3984" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003985 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003986 if s:NetrwLcd(b:netrw_curdir)
3987" call Dret("s:NetrwBrowse : lcd failure")
3988 return
3989 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003990 endif
3991 endif
3992
3993 " --------------------------------
3994 " remote handling: {{{3
3995 " --------------------------------
3996 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003997" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003998
Bram Moolenaar97d62492012-11-15 21:28:22 +01003999 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004000" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004001 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004002 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004003" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004004 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4005 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4006 if dirname !~ '/$'
4007 let dirname= dirname.'/'
4008 endif
4009 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004010" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004011 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004012 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004013" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004014 endif
4015
4016 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4017 if dirname !~ dirpat
4018 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004019 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004020 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004021 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004022" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004023 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004024" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004025" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4026 return
4027 endif
4028 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004029" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004030 endif " (additional remote handling)
4031
Bram Moolenaar85850f32019-07-19 22:05:51 +02004032 " -------------------------------
4033 " Perform Directory Listing: {{{3
4034 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004035 NetrwKeepj call s:NetrwMaps(a:islocal)
4036 NetrwKeepj call s:NetrwCommands(a:islocal)
4037 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004038
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004039 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004040 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004041" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4042
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004043 " If there is a rexposn: restore position with rexposn
4044 " Otherwise : set rexposn
4045 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004046" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4047 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4048 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4049 NetrwKeepj exe w:netrw_bannercnt
4050 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004051 else
4052 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4053 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004054 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004055 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004056" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004057 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004058 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004059
Bram Moolenaar85850f32019-07-19 22:05:51 +02004060 " repoint t:netrw_lexbufnr if appropriate
4061 if exists("repointlexbufnr")
4062 let t:netrw_lexbufnr= bufnr("%")
4063" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4064 endif
4065
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004066 " restore position
4067 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004068" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4069 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004070 endif
4071
Bram Moolenaara6878372014-03-22 21:02:50 +01004072 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004073 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4074 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004075" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4076" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004077" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004078 return
4079endfun
4080
4081" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004082" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4083" may not apply correctly; ie. netrw's idea of the current directory may
4084" differ from vim's. This function insures that netrw's idea of the current
4085" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004086" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004087fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004088" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4089" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4090" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4091" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4092" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004093
4094 " clean up any leading treedepthstring
4095 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4096 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004097" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004098 else
4099 let fname= a:fname
4100 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004101
4102 if g:netrw_keepdir
4103 " vim's idea of the current directory possibly may differ from netrw's
4104 if !exists("b:netrw_curdir")
4105 let b:netrw_curdir= getcwd()
4106 endif
4107
Nir Lichtman1e34b952024-05-08 19:19:34 +02004108 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004109 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004110 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004111 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004112" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113 else
4114 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004115 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004116" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004117 endif
4118
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004119 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004120 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004121 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004122" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004123 else
4124 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004125 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004126" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004127 endif
4128 else
4129 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004130 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004131" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4132" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4133" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004134 endif
4135
Bram Moolenaar85850f32019-07-19 22:05:51 +02004136" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004137 return ret
4138endfun
4139
4140" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004141" s:NetrwFileInfo: supports qf (query for file information) {{{2
4142fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004143" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004144 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004145 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004146 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004147 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004148 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004149 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004150 let lsopt= "-lsadh --si"
4151 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004152" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004153 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004154
4155 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004156 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004157" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004158
Bram Moolenaara6878372014-03-22 21:02:50 +01004159 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004160 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004161" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004162
4163 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004164 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004165" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004166
Bram Moolenaar446cb832008-06-24 21:56:24 +00004167 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004168" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004169 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004170" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004171 endif
4172 else
4173 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004174" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4175 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004176 let fname= substitute(a:fname,".$","","")
4177 else
4178 let fname= a:fname
4179 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004180 let t = getftime(s:NetrwFile(fname))
4181 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004182 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004183 let sz= s:NetrwHumanReadable(sz)
4184 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004185 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4186" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004187 endif
4188 else
4189 echo "sorry, \"qf\" not supported yet for remote files"
4190 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004191 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004192" call Dret("s:NetrwFileInfo")
4193endfun
4194
4195" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004196" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4197fun! s:NetrwFullPath(filename)
4198" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4199 let filename= a:filename
4200 if filename !~ '^/'
4201 let filename= resolve(getcwd().'/'.filename)
4202 endif
4203 if filename != "/" && filename =~ '/$'
4204 let filename= substitute(filename,'/$','','')
4205 endif
4206" " call Dret("s:NetrwFullPath <".filename.">")
4207 return filename
4208endfun
4209
4210" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004211" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004212" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004213" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004214" Nov 09, 2020: tst952 shows that when user does :set hidden that NetrwGetBuffer will come up with a [No Name] buffer (hid fix)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004215fun! s:NetrwGetBuffer(islocal,dirname)
4216" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004217" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." hid=".&hid,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004218" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4219" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004220 let dirname= a:dirname
4221
4222 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004223" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004224 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004225" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004226 let s:netrwbuf= {}
4227 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004228" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4229" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4230
4231 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4232 let bufnum = -1
4233
4234 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4235 if has_key(s:netrwbuf,"NetrwTreeListing")
4236 let bufnum= s:netrwbuf["NetrwTreeListing"]
4237 else
4238 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4239 endif
4240" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4241 if !bufexists(bufnum)
4242 call remove(s:netrwbuf,"NetrwTreeListing"])
4243 let bufnum= -1
4244 endif
4245 elseif bufnr("NetrwTreeListing") != -1
4246 let bufnum= bufnr("NetrwTreeListing")
4247" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4248 else
4249" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4250 let bufnum= -1
4251 endif
4252
4253 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004254 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004255" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004256 if !bufexists(bufnum)
4257 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4258 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004259 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004260
Bram Moolenaar446cb832008-06-24 21:56:24 +00004261 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004262" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004263 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004264 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004265" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4266
Bram Moolenaar71badf92023-04-22 22:40:14 +01004267 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004268 " IF the buffer already has the desired name
4269 " AND it is empty
4270 let curbuf = bufname("%")
4271 if curbuf == '.'
4272 let curbuf = getcwd()
4273 endif
4274" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004275" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004276" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4277" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4278" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4279" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4280 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004281" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4282 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004283 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004284" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004285 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004286 " Aug 14, 2021: was thinking about looking for a [No Name] buffer here and using it, but that might cause problems
Bram Moolenaar446cb832008-06-24 21:56:24 +00004287
4288 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004289 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004290" call Decho("--get enew buffer and name it (bufnum#".bufnum."<0 OR bufexists(".bufnum.")=".bufexists(bufnum)."==0)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004291 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004292" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004293 " name the buffer
4294 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4295 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004296" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004297 let w:netrw_treebufnr = bufnr("%")
4298 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004299 if g:netrw_use_noswf
4300 setl nobl bt=nofile noswf
4301 else
4302 setl nobl bt=nofile
4303 endif
4304 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4305 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4306 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4307 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004308" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004309 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004310 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004311 " enter the new buffer into the s:netrwbuf dictionary
4312 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4313" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4314" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004315 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004316" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004317
4318 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004319" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004320 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004321 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004322 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004323
4324 if &ft == "netrw"
4325" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4326 exe "sil! NetrwKeepj noswapfile b ".bufnum
4327" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004328 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004329" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4330 call s:NetrwEditBuf(bufnum)
4331" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004332 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004333" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004334 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004335 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004336 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004337
4338 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004339 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004340
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004341 if line("$") <= 1 && getline(1) == ""
4342 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004343 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004344" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4345" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004346" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4347 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004348
Bram Moolenaar97d62492012-11-15 21:28:22 +01004349 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004350" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004351 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004352 sil NetrwKeepj %d _
4353" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4354" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004355" call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but refreshing due to g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004356 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004357
Bram Moolenaar446cb832008-06-24 21:56:24 +00004358 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004359" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4360" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004361 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004362 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004363 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004364" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4365" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004366" call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but treelist mode always needs a refresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004367 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004368
Bram Moolenaar446cb832008-06-24 21:56:24 +00004369 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004370" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4371" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4372" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004373 return 1
4374 endif
4375 endif
4376
4377 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4378 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4379 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4380 " med 1 D H
4381 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004382" call Decho("--do netrw settings: make this buffer#".bufnr("%")." not-a-file, modifiable, not line-numbered, etc--",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004383 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004384 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004385 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004386
4387 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004388" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4389" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4390 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004391
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004392" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4393" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4394" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004395 return 0
4396endfun
4397
4398" ---------------------------------------------------------------------
4399" s:NetrwGetcwd: get the current directory. {{{2
4400" Change backslashes to forward slashes, if any.
4401" If doesc is true, escape certain troublesome characters
4402fun! s:NetrwGetcwd(doesc)
4403" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4404 let curdir= substitute(getcwd(),'\\','/','ge')
4405 if curdir !~ '[\/]$'
4406 let curdir= curdir.'/'
4407 endif
4408 if a:doesc
4409 let curdir= fnameescape(curdir)
4410 endif
4411" call Dret("NetrwGetcwd <".curdir.">")
4412 return curdir
4413endfun
4414
4415" ---------------------------------------------------------------------
4416" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4417fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004418" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4419" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4420 let keepsol= &l:sol
4421 setl nosol
4422
Bram Moolenaar446cb832008-06-24 21:56:24 +00004423 call s:UseBufWinVars()
4424
4425 " insure that w:netrw_liststyle is set up
4426 if !exists("w:netrw_liststyle")
4427 if exists("g:netrw_liststyle")
4428 let w:netrw_liststyle= g:netrw_liststyle
4429 else
4430 let w:netrw_liststyle= s:THINLIST
4431 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004432" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004433 endif
4434
4435 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4436 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004437" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004438 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004439 let dirname= "./"
4440 let curline= getline('.')
4441
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004442 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004443 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004444 let s:netrw_skipbrowse= 1
4445 echo 'Pressing "s" also works'
4446
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004447 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004448 let s:netrw_skipbrowse= 1
4449 echo 'Press "S" to edit sorting sequence'
4450
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004451 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004452 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004453 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004454
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004455 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004456 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004457 let s:netrw_skipbrowse= 1
4458 echo 'Pressing "a" also works'
4459
4460 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004461 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004462 endif
4463
4464 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004465" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004466 NetrwKeepj norm! 0
4467 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004468
4469 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004470" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004471 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004472 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4473
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004474 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004475" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004476 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004477 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004478
4479 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004480" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004481 let dirname= getline('.')
4482
4483 if !exists("b:netrw_cpf")
4484 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004485 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004486 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004487" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004488 endif
4489
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004490" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004491 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004492" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4493" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004494 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004495 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004496 else
4497 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004498 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004499 endif
Enno3146d632024-07-04 19:44:42 +02004500
4501 let dict={}
4502 " save the unnamed register and register 0-9 and a
4503 let dict.a=[getreg('a'), getregtype('a')]
4504 for i in range(0, 9)
4505 let dict[i] = [getreg(i), getregtype(i)]
4506 endfor
4507 let dict.unnamed = [getreg(''), getregtype('')]
4508
Bram Moolenaarc236c162008-07-13 17:41:49 +00004509 let eofname= filestart + b:netrw_cpf + 1
4510 if eofname <= col("$")
4511 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004512 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004513 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004514 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004515 endif
Enno3146d632024-07-04 19:44:42 +02004516
Bram Moolenaar446cb832008-06-24 21:56:24 +00004517 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004518 call s:RestoreRegister(dict)
4519
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004520" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004521 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004522" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004523 endif
4524
4525 " symlinks are indicated by a trailing "@". Remove it before further processing.
4526 let dirname= substitute(dirname,"@$","","")
4527
4528 " executables are indicated by a trailing "*". Remove it before further processing.
4529 let dirname= substitute(dirname,"\*$","","")
4530
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004531 let &l:sol= keepsol
4532
Bram Moolenaar446cb832008-06-24 21:56:24 +00004533" call Dret("s:NetrwGetWord <".dirname.">")
4534 return dirname
4535endfun
4536
4537" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004538" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4539" g:netrw_bufsettings will be used after the listing is produced.
4540" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004541fun! s:NetrwListSettings(islocal)
4542" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004543" 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 +00004544 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004545" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4546 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4547 setl bt=nofile nobl ma nonu nowrap noro nornu
4548 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004549 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004550 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004551 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004552" call Dredir("ls!","s:NetrwListSettings")
4553" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004554 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004555 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004556 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004557 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004558 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004559 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004560 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004561" 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 +00004562" call Dret("s:NetrwListSettings")
4563endfun
4564
4565" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004566" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004567" islocal=0: remote browsing
4568" =1: local browsing
4569fun! s:NetrwListStyle(islocal)
4570" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004571
Bram Moolenaar97d62492012-11-15 21:28:22 +01004572 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004573 let fname = s:NetrwGetWord()
4574 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004575 let svpos = winsaveview()
4576" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004577 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004578" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4579" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4580" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004581
Bram Moolenaar85850f32019-07-19 22:05:51 +02004582 " repoint t:netrw_lexbufnr if appropriate
4583 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4584" call Decho("set repointlexbufnr to true!")
4585 let repointlexbufnr= 1
4586 endif
4587
Bram Moolenaar446cb832008-06-24 21:56:24 +00004588 if w:netrw_liststyle == s:THINLIST
4589 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004590" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004591 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4592
4593 elseif w:netrw_liststyle == s:LONGLIST
4594 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004595" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004596 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4597
4598 elseif w:netrw_liststyle == s:WIDELIST
4599 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004600" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004601 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4602
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004603 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004604" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004605 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4606
4607 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004608 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004609 let g:netrw_liststyle = s:THINLIST
4610 let w:netrw_liststyle = g:netrw_liststyle
4611 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4612 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004613 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004614" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004615
4616 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004617" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4618 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004619 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004620" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004621 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004622" 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 +00004623
4624 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004625" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004626 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004627 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004628
Bram Moolenaar85850f32019-07-19 22:05:51 +02004629 " repoint t:netrw_lexbufnr if appropriate
4630 if exists("repointlexbufnr")
4631 let t:netrw_lexbufnr= bufnr("%")
4632" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4633 endif
4634
Bram Moolenaar13600302014-05-22 18:26:40 +02004635 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004636" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4637 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004638 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004639
4640" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4641endfun
4642
4643" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004644" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4645fun! s:NetrwBannerCtrl(islocal)
4646" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4647
Bram Moolenaar97d62492012-11-15 21:28:22 +01004648 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004649 " toggle the banner (enable/suppress)
4650 let g:netrw_banner= !g:netrw_banner
4651
4652 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004653 let svpos= winsaveview()
4654" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004655 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4656
4657 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004658 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4659 let fname= s:NetrwGetWord()
4660 sil NetrwKeepj $
4661 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4662" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4663 if result <= 0 && exists("w:netrw_bannercnt")
4664 exe "NetrwKeepj ".w:netrw_bannercnt
4665 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004666 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004667 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004668" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4669endfun
4670
4671" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004672" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4673"
4674" No bang: enters files/directories into Netrw's bookmark system
4675" No argument and in netrw buffer:
4676" if there are marked files: bookmark marked files
4677" otherwise : bookmark file/directory under cursor
4678" No argument and not in netrw buffer: bookmarks current open file
4679" Has arguments: globs them individually and bookmarks them
4680"
4681" With bang: deletes files/directories from Netrw's bookmark system
4682fun! s:NetrwBookmark(del,...)
4683" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4684 if a:0 == 0
4685 if &ft == "netrw"
4686 let curbufnr = bufnr("%")
4687
4688 if exists("s:netrwmarkfilelist_{curbufnr}")
4689 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004690" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004691 let svpos = winsaveview()
4692" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004693 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004694 for fname in s:netrwmarkfilelist_{curbufnr}
4695 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4696 endfor
4697 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4698 call s:NetrwUnmarkList(curbufnr,curdir)
4699 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004700" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4701 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004702 else
4703 let fname= s:NetrwGetWord()
4704 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4705 endif
4706
4707 else
4708 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004709" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004710 let fname= expand("%")
4711 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4712 endif
4713
4714 else
4715 " bookmark specified files
4716 " attempts to infer if working remote or local
4717 " by deciding if the current file begins with an url
4718 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004719 let islocal= expand("%") !~ '^\a\{3,}://'
4720" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004721 let i = 1
4722 while i <= a:0
4723 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004724 if v:version > 704 || (v:version == 704 && has("patch656"))
4725 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004726 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004727 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004728 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004729 else
4730 let mbfiles= [a:{i}]
4731 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004732" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004733 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004734" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004735 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4736 endfor
4737 let i= i + 1
4738 endwhile
4739 endif
4740
4741 " update the menu
4742 call s:NetrwBookmarkMenu()
4743
4744" call Dret("s:NetrwBookmark")
4745endfun
4746
4747" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004748" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4749" .2.[cnt] for bookmarks, and
4750" .3.[cnt] for history
4751" (see s:NetrwMenu())
4752fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004753 if !exists("s:netrw_menucnt")
4754 return
4755 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004756" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004757
4758 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004759 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004760 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004761" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004762 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4763 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004764 endif
4765 if !exists("s:netrw_initbookhist")
4766 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004767 endif
4768
4769 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004770 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004771 let cnt= 1
4772 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004773" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004774 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004775
4776 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004777 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004778
4779 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004780 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 +01004781 let cnt= cnt + 1
4782 endfor
4783
4784 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004785
4786 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004787 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004788 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004789 let first = 1
4790 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004791 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004792 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004793 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004794 if exists("g:netrw_dirhist_{cnt}")
4795 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004796" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004797 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4798 endif
4799 let first = 0
4800 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4801 if cnt < 0
4802 let cnt= cnt + g:netrw_dirhistmax
4803 endif
4804 endwhile
4805 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004806
Bram Moolenaar9964e462007-05-05 17:54:07 +00004807 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004808" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004809endfun
4810
4811" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004812" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4813" directory and a new directory name. Also, if the
4814" "new directory name" is actually a file,
4815" NetrwBrowseChgDir() edits the file.
4816fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004817" 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 +01004818" 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 +00004819
Bram Moolenaar97d62492012-11-15 21:28:22 +01004820 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004821 if !exists("b:netrw_curdir")
4822 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4823 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004824 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004825" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4826" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004827" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004828" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004829 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004830 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004831" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004832
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004833 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004834" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004835 call s:SavePosn(s:netrw_posn)
4836 NetrwKeepj call s:NetrwOptionsSave("s:")
4837 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004838 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004839 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004840 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004841 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004842 endif
4843 let newdir = a:newdir
4844 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004845 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004846" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004847" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004848" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004849
4850 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004851" 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 +01004852 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004853" 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 +01004854 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004855 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004856" 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 +01004857 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004858" 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 +02004859 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004860 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004861 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004862 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004863" 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 +01004864 endif
4865 endif
4866" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004867" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004868 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004869
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870 " set up o/s-dependent directory recognition pattern
4871 if has("amiga")
4872 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004873 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004874 let dirpat= '[\/]$'
4875 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004876" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004877
4878 if dirname !~ dirpat
4879 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004880 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004881 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004882" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004883 endif
4884
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004885" 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 +01004886 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004887 " ------------------------------
4888 " NetrwBrowseChgDir: edit a file {{{3
4889 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004890" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004891
Bram Moolenaar97d62492012-11-15 21:28:22 +01004892 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004893 let s:rexposn_{bufnr("%")}= winsaveview()
4894" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004895" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4896" 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 +01004897
Bram Moolenaar446cb832008-06-24 21:56:24 +00004898 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004899" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4900" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004901" let newdir = s:NetrwTreePath(s:netrw_treetop)
4902" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004903 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004904 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4905" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4906 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004907 if dirname =~ '/$'
4908 let dirname= dirname.newdir
4909 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004910 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004911 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004912" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4913" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004914 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004915" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004916 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004917 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004918 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004919 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004920" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004921 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004922 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004923" 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 +02004924 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004925 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004926 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004927" " 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 +01004928 if type(g:netrw_browse_split) == 3
4929 " open file in server
4930 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004931" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004932 call s:NetrwServerEdit(a:islocal,dirname)
4933" call Dret("s:NetrwBrowseChgDir")
4934 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004935
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004936 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004937 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004938" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004939 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4940 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004941 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004942 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004943 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004944 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004945
Bram Moolenaar446cb832008-06-24 21:56:24 +00004946 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004947 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004948" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004949 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4950 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004951 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004952 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004953 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004954 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004955
Bram Moolenaar446cb832008-06-24 21:56:24 +00004956 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004957 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004958" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004959 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004960 if !exists("b:netrw_curdir")
4961 let b:netrw_curdir= getcwd()
4962 endif
4963 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004964
Bram Moolenaar446cb832008-06-24 21:56:24 +00004965 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004966 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004967" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004968 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004969 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004970" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004971 return
4972 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004973 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004974
Bram Moolenaar9964e462007-05-05 17:54:07 +00004975 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004976 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004977" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004978 call s:NetrwMenu(0)
4979 " optional change to window
4980 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004981" 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 +02004982 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004983 " if g:netrw_chgwin is set to one more than the last window, then
4984 " vertically split the last window to make that window available.
4985 let curwin= winnr()
4986 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4987 vs
4988 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004989 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004990 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004991 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004992 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004993 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004994
Bram Moolenaar9964e462007-05-05 17:54:07 +00004995 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004996
Bram Moolenaar446cb832008-06-24 21:56:24 +00004997 " the point where netrw actually edits the (local) file
4998 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004999 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005000 if !&mod
5001 " if e the new file would fail due to &mod, then don't change any of the flags
5002 let dolockout= 1
5003 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005004 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005005" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005006 " some like c-^ to return to the last edited file
5007 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005008 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5009 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005010 call s:NetrwEditFile("e","",dirname)
5011" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005012 " COMBAK -- cuc cul related
5013 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005014 if &hidden || &bufhidden == "hide"
5015 " file came from vim's hidden storage. Don't "restore" options with it.
5016 let dorestore= 0
5017 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005018 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005019" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005020 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005021
5022 " handle g:Netrw_funcref -- call external-to-netrw functions
5023 " This code will handle g:Netrw_funcref as an individual function reference
5024 " or as a list of function references. It will ignore anything that's not
5025 " a function reference. See :help Funcref for information about function references.
5026 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005027" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005028 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005029" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005030 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005031 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005032" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005033 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005034 if type(Fncref) == 2
5035 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005036 endif
5037 endfor
5038 endif
5039 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005040 endif
5041
5042 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005043 " ----------------------------------------------------
5044 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5045 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005046" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005047 let dirname = newdir
5048 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005049 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005050 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005051
5052 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005053 " ---------------------------------------------
5054 " NetrwBrowseChgDir: refresh the directory list {{{3
5055 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005056" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005057 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005058 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005059
5060 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005061 " --------------------------------------
5062 " NetrwBrowseChgDir: go up one directory {{{3
5063 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005064" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005065
5066 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5067 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005068" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5069" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005070 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005071 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005072 endif
5073
5074 if has("amiga")
5075 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005076" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005077 if a:islocal
5078 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5079 let dirname= substitute(dirname,'/$','','')
5080 else
5081 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5082 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005083" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005084
Nir Lichtman1e34b952024-05-08 19:19:34 +02005085 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005086 " windows
5087 if a:islocal
5088 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5089 if dirname == ""
5090 let dirname= '/'
5091 endif
5092 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005093 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005094 endif
5095 if dirname =~ '^\a:$'
5096 let dirname= dirname.'/'
5097 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005098" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005099
Bram Moolenaar446cb832008-06-24 21:56:24 +00005100 else
5101 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005102" 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 +00005103 if a:islocal
5104 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5105 if dirname == ""
5106 let dirname= '/'
5107 endif
5108 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005109 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005110 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005111" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005112 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005113 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005114 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005115
5116 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005117 " --------------------------------------
5118 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5119 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005120" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005121 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5122" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005123 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005124 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005125" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5126 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005127 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005128 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005129" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005130 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005131 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005132" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005133
5134 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005135" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005136 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005137" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005138 let haskey= 1
5139 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005140" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005141 endif
5142
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005143 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005144" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005145 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005146 if has_key(w:netrw_treedict,treedir."/")
5147 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005148" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005149 let haskey = 1
5150 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005151" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005152 endif
5153 endif
5154
5155 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005156" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005157 if !haskey && treedir =~ '/$'
5158 let treedir= substitute(treedir,'/$','','')
5159 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005160" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005161 let haskey = 1
5162 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005163" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 endif
5165 endif
5166
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005167" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005168 if haskey
5169 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005170" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005172" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5173" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005174 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005175 else
5176 " go down one directory
5177 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005178" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5179" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005180 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005181 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005182" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005183 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005184
5185 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005186 " ----------------------------------------
5187 " NetrwBrowseChgDir: Go down one directory {{{3
5188 " ----------------------------------------
5189 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005190" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005191 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005192 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005193 endif
5194
Bram Moolenaar97d62492012-11-15 21:28:22 +01005195 " --------------------------------------
5196 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5197 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005198 if dorestore
5199 " dorestore is zero'd when a local file was hidden or bufhidden;
5200 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005201" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005202 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005203" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005204" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005205 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005206 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005207" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005208 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005209" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5210" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005211 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005212" 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 +02005213 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005214" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5215" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005216 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005217" 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 +02005218 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005219 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005220 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005221 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005222
Bram Moolenaar446cb832008-06-24 21:56:24 +00005223" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5224 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005225endfun
5226
5227" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005228" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5229" for thin, long, and wide: cursor placed just after banner
5230" for tree, keeps cursor on current filename
5231fun! s:NetrwBrowseUpDir(islocal)
5232" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005233 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5234 " this test needed because occasionally this function seems to be incorrectly called
5235 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005236 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005237 " directories.
5238" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5239 return
5240 endif
5241
Bram Moolenaara6878372014-03-22 21:02:50 +01005242 norm! 0
5243 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005244" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005245 let curline= getline(".")
5246 let swwline= winline() - 1
5247 if exists("w:netrw_treetop")
5248 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005249 elseif exists("b:netrw_curdir")
5250 let w:netrw_treetop= b:netrw_curdir
5251 else
5252 let w:netrw_treetop= getcwd()
5253 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005254 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005255 let curfile = getline(".")
5256 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005257 if a:islocal
5258 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5259 else
5260 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5261 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005262" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5263" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5264 if w:netrw_treetop == '/'
5265 keepj call search('^\M'.curfile,"w")
5266 elseif curfile == '../'
5267 keepj call search('^\M'.curfile,"wb")
5268 else
5269" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5270 while 1
5271 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5272 let treepath= s:NetrwTreePath(w:netrw_treetop)
5273" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5274 if treepath == curpath
5275 break
5276 endif
5277 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005278 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005279
Bram Moolenaara6878372014-03-22 21:02:50 +01005280 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005281" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005282 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005283 if exists("b:netrw_curdir")
5284 let curdir= b:netrw_curdir
5285 else
5286 let curdir= expand(getcwd())
5287 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005288 if a:islocal
5289 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5290 else
5291 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5292 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005293 call s:RestorePosn(s:netrw_posn)
5294 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005295 let curdir= '\<'. escape(curdir, '~'). '/'
5296 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005297 endif
5298" call Dret("s:NetrwBrowseUpDir")
5299endfun
5300
5301" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005302" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005303" given filename; typically this means given their extension.
5304" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005305fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005306 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005307" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005308
Bram Moolenaar91359012019-11-30 17:57:03 +01005309 if a:remote == 0 && isdirectory(a:fname)
5310 " if its really just a local directory, then do a "gf" instead
5311" 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 +01005312" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5313 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005314" call Dret("netrw#BrowseX")
5315 return
5316 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5317 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5318" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5319" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5320" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5321" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5322 norm! gf
5323" call Dret("netrw#BrowseX")
5324 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005325 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005326" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005327
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005328 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5329 let remote = a:remote
5330 else
5331 let remote = 0
5332 endif
5333
Bram Moolenaar97d62492012-11-15 21:28:22 +01005334 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005335 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005336" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005337
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005338 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5339 let awkeep = &aw
5340 set noaw
5341
Bram Moolenaar5c736222010-01-06 20:54:52 +01005342 " special core dump handler
5343 if a:fname =~ '/core\(\.\d\+\)\=$'
5344 if exists("g:Netrw_corehandler")
5345 if type(g:Netrw_corehandler) == 2
5346 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005347" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005348 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005349 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005350 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005351" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005352 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005353 if type(Fncref) == 2
5354 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005355 endif
5356 endfor
5357 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005358" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005359 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005360 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005361 let &aw= awkeep
5362" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005363 return
5364 endif
5365 endif
5366
Bram Moolenaar446cb832008-06-24 21:56:24 +00005367 " set up the filename
5368 " (lower case the extension, make a local copy of a remote file)
5369 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005370 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005371 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005372 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005373 if exten =~ "[\\/]"
5374 let exten= ""
5375 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005376" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005377
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005378 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005379 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005380" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005381 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005382 call netrw#NetRead(3,a:fname)
5383 " attempt to rename tempfile
5384 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005385 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005386" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5387" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005388 if s:netrw_tmpfile != newname && newname != ""
5389 if rename(s:netrw_tmpfile,newname) == 0
5390 " renaming succeeded
5391" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5392 let fname= newname
5393 else
5394 " renaming failed
5395" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5396 let fname= s:netrw_tmpfile
5397 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005398 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005399 let fname= s:netrw_tmpfile
5400 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005401 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005402" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005403 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005404 " special ~ handler for local
5405 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005406" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5407 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005408 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005409 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005410" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5411" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005412
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005413 " set up redirection (avoids browser messages)
5414 " by default, g:netrw_suppress_gx_mesg is true
5415 if g:netrw_suppress_gx_mesg
5416 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005417 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005418 let redir= substitute(&srr,"%s","nul","")
5419 else
5420 let redir= substitute(&srr,"%s","/dev/null","")
5421 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005422 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005423 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005424 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005425 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005426 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005427 else
5428 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005429 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005430" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005431
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005432 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005433 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005434" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005435 if g:netrw_browsex_viewer =~ '\s'
5436 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5437 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5438 let oviewer = ''
5439 let cnt = 1
5440 while !executable(viewer) && viewer != oviewer
5441 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5442 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5443 let cnt = cnt + 1
5444 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005445" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005446 endwhile
5447 else
5448 let viewer = g:netrw_browsex_viewer
5449 let viewopt = ""
5450 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005451" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005452 endif
5453
5454 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005455" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005456 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005457" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005458 let ret= netrwFileHandlers#Invoke(exten,fname)
5459
5460 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005461" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005462 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005463 let ret= v:shell_error
5464
Nir Lichtman1e34b952024-05-08 19:19:34 +02005465 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005466" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005467 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005468 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005469 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005470 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005471 else
5472 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5473 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005474 let ret= v:shell_error
5475
Bram Moolenaar97d62492012-11-15 21:28:22 +01005476 elseif has("win32unix")
5477 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005478" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005479 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005480" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005481 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005482 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005483" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005484 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005485 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005486" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005487 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005488 else
5489 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5490 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005491 let ret= v:shell_error
5492
Bram Moolenaar85850f32019-07-19 22:05:51 +02005493 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005494" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5495 if a:fname =~ '^https\=://'
5496 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5497 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005498" call Decho("fname<".fname.">")
5499" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005500 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5501
5502 else
5503 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5504 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005505 let ret= v:shell_error
5506
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005507 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5508" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5509 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5510 let ret= v:shell_error
5511
5512 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5513" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5514 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5515 let ret= v:shell_error
5516
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005517 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005518" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005519 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005520 let ret= v:shell_error
5521
5522 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005523" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005524 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005525 let ret= v:shell_error
5526
5527 else
5528 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005529" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005530 let ret= netrwFileHandlers#Invoke(exten,fname)
5531 endif
5532
5533 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5534 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005535" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005536 let ret= netrwFileHandlers#Invoke(exten,fname)
5537 endif
5538
Bram Moolenaarc236c162008-07-13 17:41:49 +00005539 " restoring redraw! after external file handlers
5540 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005541
5542 " cleanup: remove temporary file,
5543 " delete current buffer if success with handler,
5544 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005545 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005546 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005547" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005548"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005549" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005550" endif
5551
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005552 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005553 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005554 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005555 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005556 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005557 if use_ctrlo
5558 exe "sil! NetrwKeepj norm! \<c-o>"
5559 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005560 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005561" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005562 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005563 let @@ = ykeep
5564 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005565
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005566" call Dret("netrw#BrowseX")
5567endfun
5568
5569" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005570" netrw#GX: gets word under cursor for gx support {{{2
5571" See also: netrw#BrowseXVis
5572" netrw#BrowseX
5573fun! netrw#GX()
5574" call Dfunc("netrw#GX()")
5575 if &ft == "netrw"
5576 let fname= s:NetrwGetWord()
5577 else
5578 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5579 endif
5580" call Dret("netrw#GX <".fname.">")
5581 return fname
5582endfun
5583
5584" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005585" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5586fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005587 let dict={}
5588 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005589 norm! gv"ay
5590 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005591 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005592 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005593endfun
5594
5595" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005596" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5597" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5598" to become an unlisted buffer, so in that case don't bwipe it.
5599fun! s:NetrwBufRename(newname)
5600" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5601" call Dredir("ls!","s:NetrwBufRename (before rename)")
5602 let oldbufname= bufname(bufnr("%"))
5603" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5604
5605 if oldbufname != a:newname
5606" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5607 let b:junk= 1
5608" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5609 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005610" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005611 let oldbufnr= bufnr(oldbufname)
5612" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5613" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5614 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5615" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5616 exe "bwipe! ".oldbufnr
5617" else " Decho
5618" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005619" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5620" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5621" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005622 endif
5623" call Dredir("ls!","s:NetrwBufRename (after rename)")
5624" else " Decho
5625" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5626 endif
5627
5628" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5629endfun
5630
5631" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005632" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005633fun! netrw#CheckIfRemote(...)
5634" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5635 if a:0 > 0
5636 let curfile= a:1
5637 else
5638 let curfile= expand("%")
5639 endif
5640" call Decho("curfile<".curfile.">")
5641 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005642" call Dret("netrw#CheckIfRemote 1")
5643 return 1
5644 else
5645" call Dret("netrw#CheckIfRemote 0")
5646 return 0
5647 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005648endfun
5649
5650" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005651" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5652fun! s:NetrwChgPerm(islocal,curdir)
5653" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005654 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005655 call inputsave()
5656 let newperm= input("Enter new permission: ")
5657 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005658 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5659 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5660" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005661 call system(chgperm)
5662 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005663 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005664 endif
5665 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005666 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005667 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005668 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005669" call Dret("s:NetrwChgPerm")
5670endfun
5671
5672" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005673" s:CheckIfKde: checks if kdeinit is running {{{2
5674" Returns 0: kdeinit not running
5675" 1: kdeinit is running
5676fun! s:CheckIfKde()
5677" call Dfunc("s:CheckIfKde()")
5678 " seems kde systems often have gnome-open due to dependencies, even though
5679 " gnome-open's subsidiary display tools are largely absent. Kde systems
5680 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5681 if !exists("s:haskdeinit")
5682 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005683 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005684 if v:shell_error
5685 let s:haskdeinit = 0
5686 endif
5687 else
5688 let s:haskdeinit= 0
5689 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005690" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005691 endif
5692
5693" call Dret("s:CheckIfKde ".s:haskdeinit)
5694 return s:haskdeinit
5695endfun
5696
5697" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005698" s:NetrwClearExplore: clear explore variables (if any) {{{2
5699fun! s:NetrwClearExplore()
5700" call Dfunc("s:NetrwClearExplore()")
5701 2match none
5702 if exists("s:explore_match") |unlet s:explore_match |endif
5703 if exists("s:explore_indx") |unlet s:explore_indx |endif
5704 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5705 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5706 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5707 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5708 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5709 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5710 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5711" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005712" call Dret("s:NetrwClearExplore")
5713endfun
5714
5715" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005716" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5717fun! s:NetrwEditBuf(bufnum)
5718" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5719 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5720" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5721 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5722 else
5723" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005724 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005725 endif
5726" call Dret("s:NetrwEditBuf")
5727endfun
5728
5729" ---------------------------------------------------------------------
5730" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5731" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5732fun! s:NetrwEditFile(cmd,opt,fname)
5733" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5734 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5735" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5736 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5737 else
5738" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005739 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5740 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5741 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005742 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5743 endif
5744" call Dret("s:NetrwEditFile")
5745endfun
5746
5747" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005748" s:NetrwExploreListUniq: {{{2
5749fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005750" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005751
5752 " this assumes that the list is already sorted
5753 let newexplist= []
5754 for member in a:explist
5755 if !exists("uniqmember") || member != uniqmember
5756 let uniqmember = member
5757 let newexplist = newexplist + [ member ]
5758 endif
5759 endfor
5760
Bram Moolenaar15146672011-10-20 22:22:38 +02005761" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005762 return newexplist
5763endfun
5764
5765" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005766" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5767fun! s:NetrwForceChgDir(islocal,newdir)
5768" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005769 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005770 if a:newdir !~ '/$'
5771 " ok, looks like force is needed to get directory-style treatment
5772 if a:newdir =~ '@$'
5773 let newdir= substitute(a:newdir,'@$','/','')
5774 elseif a:newdir =~ '[*=|\\]$'
5775 let newdir= substitute(a:newdir,'.$','/','')
5776 else
5777 let newdir= a:newdir.'/'
5778 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005779" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005780 else
5781 " should already be getting treatment as a directory
5782 let newdir= a:newdir
5783 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005784 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005785 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005786 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005787" call Dret("s:NetrwForceChgDir")
5788endfun
5789
5790" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005791" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005792" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5793" expr : this is the expression to follow the directory. Will use s:ComposePath()
5794" pare =1: remove the current directory from the resulting glob() filelist
5795" =0: leave the current directory in the resulting glob() filelist
5796fun! s:NetrwGlob(direntry,expr,pare)
5797" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005798 if netrw#CheckIfRemote()
5799 keepalt 1sp
5800 keepalt enew
5801 let keep_liststyle = w:netrw_liststyle
5802 let w:netrw_liststyle = s:THINLIST
5803 if s:NetrwRemoteListing() == 0
5804 keepj keepalt %s@/@@
5805 let filelist= getline(1,$)
5806 q!
5807 else
5808 " remote listing error -- leave treedict unchanged
5809 let filelist= w:netrw_treedict[a:direntry]
5810 endif
5811 let w:netrw_liststyle= keep_liststyle
5812 else
Christian Brabandt14879472024-06-13 21:25:35 +02005813 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005814 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005815 " escape [ so it is not detected as wildcard character, see :h wildcard
5816 let path= substitute(path, '[', '[[]', 'g')
5817 endif
5818 if v:version > 704 || (v:version == 704 && has("patch656"))
5819 let filelist= glob(path,0,1,1)
5820 else
5821 let filelist= glob(path,0,1)
5822 endif
5823 if a:pare
5824 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5825 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005826 endif
5827" call Dret("s:NetrwGlob ".string(filelist))
5828 return filelist
5829endfun
5830
5831" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005832" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5833fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005834" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005835 if a:newfile =~ '[/@*=|\\]$'
5836 let newfile= substitute(a:newfile,'.$','','')
5837 else
5838 let newfile= a:newfile
5839 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005840 if a:islocal
5841 call s:NetrwBrowseChgDir(a:islocal,newfile)
5842 else
5843 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5844 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005845" call Dret("s:NetrwForceFile")
5846endfun
5847
5848" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005849" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5850" and switches the hiding mode. The actual hiding is done by
5851" s:NetrwListHide().
5852" g:netrw_hide= 0: show all
5853" 1: show not-hidden files
5854" 2: show hidden files only
5855fun! s:NetrwHide(islocal)
5856" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005857 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005858 let svpos= winsaveview()
5859" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005860
5861 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005862" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5863" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005864
5865 " hide the files in the markfile list
5866 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005867" 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 +00005868 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5869 " remove fname from hiding list
5870 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5871 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5872 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005873" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005874 else
5875 " append fname to hiding list
5876 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5877 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5878 else
5879 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5880 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005881" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005882 endif
5883 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005884 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005885 let g:netrw_hide= 1
5886
5887 else
5888
5889 " switch between show-all/show-not-hidden/show-hidden
5890 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005891 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005892 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005893 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005894 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005895" call Dret("NetrwHide")
5896 return
5897 endif
5898 endif
5899
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005900 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005901" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5902 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005903 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005904" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005905endfun
5906
5907" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005908" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5909fun! s:NetrwHideEdit(islocal)
5910" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5911
5912 let ykeep= @@
5913 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005914 let svpos= winsaveview()
5915" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005916
5917 " get new hiding list from user
5918 call inputsave()
5919 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5920 call inputrestore()
5921 let g:netrw_list_hide= newhide
5922" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5923
5924 " refresh the listing
5925 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5926
5927 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005928" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5929 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005930 let @@= ykeep
5931
5932" call Dret("NetrwHideEdit")
5933endfun
5934
5935" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005936" s:NetrwHidden: invoked by "gh" {{{2
5937fun! s:NetrwHidden(islocal)
5938" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005939 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005940 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005941 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005942" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005943
5944 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005945 " remove .file pattern from hiding list
5946" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005947 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005948 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005949" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005950 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5951 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005952" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005953 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5954 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005955 if g:netrw_list_hide =~ '^,'
5956 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5957 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005958
5959 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005960 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005961" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5962 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005963 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005964" call Dret("s:NetrwHidden")
5965endfun
5966
5967" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005968" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5969fun! s:NetrwHome()
5970 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005971 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005972 else
5973 " go to vim plugin home
5974 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005975 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005976 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005977 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005978 let home= basehome."/.vim"
5979 break
5980 endif
5981 endfor
5982 if home == ""
5983 " just pick the first directory
5984 let home= substitute(&rtp,',.*$','','')
5985 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005986 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005987 let home= substitute(home,'/','\\','g')
5988 endif
5989 endif
5990 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005991 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005992" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005993 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005994" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005995 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005996 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005997" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005998 call mkdir(home)
5999 endif
6000 endif
6001 let g:netrw_home= home
6002 return home
6003endfun
6004
6005" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006006" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
6007fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006008 if exists("s:netrwdrag")
6009 return
6010 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006011 if &ft != "netrw"
6012 return
6013 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006014" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006015
Bram Moolenaar97d62492012-11-15 21:28:22 +01006016 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006017 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006018 while getchar(0) != 0
6019 "clear the input stream
6020 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006021 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006022 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006023 let mouse_lnum = v:mouse_lnum
6024 let wlastline = line('w$')
6025 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006026" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6027" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006028 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6029 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006030 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006031" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6032 return
6033 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006034 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006035 " 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 +01006036 " without this test when its disabled.
6037 " 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 +01006038" 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 +01006039 if v:mouse_col > virtcol('.')
6040 let @@= ykeep
6041" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6042 return
6043 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006044
Bram Moolenaar446cb832008-06-24 21:56:24 +00006045 if a:islocal
6046 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006047 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006048 endif
6049 else
6050 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006051 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006052 endif
6053 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006054 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006055" call Dret("s:NetrwLeftmouse")
6056endfun
6057
6058" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006059" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6060fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006061 if &ft != "netrw"
6062 return
6063 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006064" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6065 call s:NetrwMarkFileTgt(a:islocal)
6066" call Dret("s:NetrwCLeftmouse")
6067endfun
6068
6069" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006070" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6071" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006072" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006073" a:islocal=2 : <c-r> used, remote
6074" a:islocal=3 : <c-r> used, local
6075fun! s:NetrwServerEdit(islocal,fname)
6076" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6077 let islocal = a:islocal%2 " =0: remote =1: local
6078 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006079" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006080
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006081 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006082 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006083 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006084" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006085 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006086 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006087 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6088 unlet s:netrw_browse_split_{winnr()}
6089 endif
6090 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6091" call Dret("s:NetrwServerEdit")
6092 return
6093 endif
6094
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006095" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006096 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006097" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006098
6099 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006100" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006101 let srvrname = g:netrw_browse_split[0]
6102 let tabnum = g:netrw_browse_split[1]
6103 let winnum = g:netrw_browse_split[2]
6104
6105 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006106" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006107
6108 if !ctrlr
6109 " user must have closed the server window and the user did not use <c-r>, but
6110 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006111" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006112 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006113 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006114 endif
6115 let g:netrw_browse_split= 0
6116 if exists("s:netrw_browse_split_".winnr())
6117 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6118 endif
6119 call s:NetrwBrowseChgDir(islocal,a:fname)
6120" call Dret("s:NetrwServerEdit")
6121 return
6122
6123 elseif has("win32") && executable("start")
6124 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006125" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006126 call system("start gvim --servername ".srvrname)
6127
6128 else
6129 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006130" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006131 call system("gvim --servername ".srvrname)
6132 endif
6133 endif
6134
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006135" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006136 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6137 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006138 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006139
6140 else
6141
6142 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6143
6144 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006145" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006146 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006147 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006148 endif
6149 let g:netrw_browse_split= 0
6150 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6151" call Dret("s:NetrwServerEdit")
6152 return
6153
6154 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006155" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006156 if has("win32") && executable("start")
6157 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006158" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006159 call system("start gvim --servername ".g:netrw_servername)
6160 else
6161 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006162" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006163 call system("gvim --servername ".g:netrw_servername)
6164 endif
6165 endif
6166 endif
6167
6168 while 1
6169 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006170" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6171 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006172 break
6173 catch /^Vim\%((\a\+)\)\=:E241/
6174 sleep 200m
6175 endtry
6176 endwhile
6177
6178 if exists("g:netrw_browse_split")
6179 if type(g:netrw_browse_split) != 3
6180 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6181 endif
6182 unlet g:netrw_browse_split
6183 endif
6184 let g:netrw_browse_split= [g:netrw_servername,1,1]
6185 endif
6186
6187 else
6188 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6189 endif
6190
6191" call Dret("s:NetrwServerEdit")
6192endfun
6193
6194" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006195" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6196fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006197 if &ft != "netrw"
6198 return
6199 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006200" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006201
Bram Moolenaar8d043172014-01-23 14:24:41 +01006202 let s:ngw= s:NetrwGetWord()
6203 call s:NetrwMarkFile(a:islocal,s:ngw)
6204
6205" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006206endfun
6207
6208" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006209" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6210" Used to mark multiple files.
6211fun! s:NetrwSLeftdrag(islocal)
6212" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6213 if !exists("s:netrwdrag")
6214 let s:netrwdrag = winnr()
6215 if a:islocal
6216 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006217 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006218 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006219 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006220 endif
6221 let ngw = s:NetrwGetWord()
6222 if !exists("s:ngw") || s:ngw != ngw
6223 call s:NetrwMarkFile(a:islocal,ngw)
6224 endif
6225 let s:ngw= ngw
6226" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6227endfun
6228
6229" ---------------------------------------------------------------------
6230" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6231fun! s:NetrwSLeftrelease(islocal)
6232" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6233 if exists("s:netrwdrag")
6234 nunmap <s-leftrelease>
6235 let ngw = s:NetrwGetWord()
6236 if !exists("s:ngw") || s:ngw != ngw
6237 call s:NetrwMarkFile(a:islocal,ngw)
6238 endif
6239 if exists("s:ngw")
6240 unlet s:ngw
6241 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006242 unlet s:netrwdrag
6243 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006244" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006245endfun
6246
6247" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006248" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6249" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006250fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006251" 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 +02006252" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006253 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006254
6255 " 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 +02006256 " How-it-works: take the hiding command, convert it into a range.
6257 " Duplicate characters don't matter.
6258 " Remove all such characters from the '/~@#...890' string.
6259 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006260" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006261 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006262 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006263" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006264
6265 while listhide != ""
6266 if listhide =~ ','
6267 let hide = substitute(listhide,',.*$','','e')
6268 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6269 else
6270 let hide = listhide
6271 let listhide = ""
6272 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006273" 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 +01006274 if g:netrw_sort_by =~ '^[ts]'
6275 if hide =~ '^\^'
6276" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6277 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6278 elseif hide =~ '^\\(\^'
6279 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6280 endif
6281" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6282 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006283
6284 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006285" 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 +00006286 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006287" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006288 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006289 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006290" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006291 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006292 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006293" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006294 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006295
Bram Moolenaar446cb832008-06-24 21:56:24 +00006296 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006297 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006298" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006299 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006300" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006301 endif
6302
Bram Moolenaaradc21822011-04-01 18:03:16 +02006303 " remove any blank lines that have somehow remained.
6304 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006305 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006306
Bram Moolenaar97d62492012-11-15 21:28:22 +01006307 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006308" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006309endfun
6310
6311" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006312" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006313" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006314fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006315" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006316
Bram Moolenaar97d62492012-11-15 21:28:22 +01006317 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006318 " get name of new directory from user. A bare <CR> will skip.
6319 " if its currently a directory, also request will be skipped, but with
6320 " a message.
6321 call inputsave()
6322 let newdirname= input("Please give directory name: ")
6323 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006324" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006325
6326 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006327 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006328" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006329 return
6330 endif
6331
6332 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006333" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006334
6335 " Local mkdir:
6336 " sanity checks
6337 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006338" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6339 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006340 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006341 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006342 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006343 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006344" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006345 return
6346 endif
6347 if s:FileReadable(fullnewdir)
6348 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006349 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006350 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006351 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006352" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006353 return
6354 endif
6355
6356 " requested new local directory is neither a pre-existing file or
6357 " directory, so make it!
6358 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006359 if has("unix")
6360 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6361 else
6362 call mkdir(fullnewdir,"p")
6363 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006364 else
6365 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006366 if s:NetrwLcd(b:netrw_curdir)
6367" call Dret("s:NetrwMakeDir : lcd failure")
6368 return
6369 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006370" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006371 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006372 if v:shell_error != 0
6373 let @@= ykeep
6374 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 +01006375" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006376 return
6377 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006378 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006379" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006380 if s:NetrwLcd(netrw_origdir)
6381" call Dret("s:NetrwBrowse : lcd failure")
6382 return
6383 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006384 endif
6385 endif
6386
6387 if v:shell_error == 0
6388 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006389" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006390 let svpos= winsaveview()
6391" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006392 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006393" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6394 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006395 elseif !exists("g:netrw_quiet")
6396 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6397 endif
6398" redraw!
6399
6400 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006401 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006402" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006403 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6404 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006405 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006406 if v:shell_error == 0
6407 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006408 let svpos= winsaveview()
6409" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006410 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006411" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6412 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006413 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006414 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006415 endif
6416" redraw!
6417
6418 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006419 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006420 let svpos= winsaveview()
6421" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006422" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006423 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006424" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006425 let remotepath= b:netrw_fname
6426 else
6427 let remotepath= ""
6428 endif
6429 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006430 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006431" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6432 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006433
Bram Moolenaar446cb832008-06-24 21:56:24 +00006434 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006435 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006436 let svpos= winsaveview()
6437" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006438" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006439 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006440" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006441 let remotepath= b:netrw_fname
6442 else
6443 let remotepath= ""
6444 endif
6445 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006446 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006447" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6448 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006449 endif
6450
Bram Moolenaar97d62492012-11-15 21:28:22 +01006451 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006452" call Dret("s:NetrwMakeDir")
6453endfun
6454
6455" ---------------------------------------------------------------------
6456" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6457fun! s:TreeSqueezeDir(islocal)
6458" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6459 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6460 " its a tree-listing style
6461 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006462 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006463 let depth = strchars(substitute(curdepth,' ','','g'))
6464 let srch = -1
6465" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6466" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006467" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006468" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6469 if depth >= 2
6470 NetrwKeepj norm! 0
6471 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6472 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6473" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6474" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6475 elseif depth == 1
6476 NetrwKeepj norm! 0
6477 let treedepthchr= substitute(s:treedepthstring,' ','','')
6478 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6479" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6480 endif
6481 if srch > 0
6482" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6483 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6484 exe srch
6485 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006486 endif
6487" call Dret("s:TreeSqueezeDir")
6488endfun
6489
6490" ---------------------------------------------------------------------
6491" s:NetrwMaps: {{{2
6492fun! s:NetrwMaps(islocal)
6493" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6494
Bram Moolenaar85850f32019-07-19 22:05:51 +02006495 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006496 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006497" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006498 if !hasmapto("<Plug>NetrwReturn")
6499 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006500" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006501 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6502 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006503" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006504 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6505 endif
6506 endif
6507 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006508" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006509 endif
6510
Bram Moolenaar85850f32019-07-19 22:05:51 +02006511 " generate default <Plug> maps {{{3
6512 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006513 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006514 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6515 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6516 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6517 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6518 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6519 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6520 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6521 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6522 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6523 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6524" ---------------------------------------------------------------------
6525" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6526" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6527" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6528" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6529" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6530" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6531" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6532" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6533" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6534" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6535" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6536" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6537" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6538" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6539" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6540" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6541" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6542" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6543" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6544" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6545" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6546" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6547" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6548" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6549" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6550" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6551" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6552" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6553" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6554" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6555" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6556" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6557" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6558" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6559" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6560" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6561" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6562" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6563" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6564" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6565" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6566" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6567" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6568" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6569" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6570" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6571" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6572
Bram Moolenaara6878372014-03-22 21:02:50 +01006573 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006574" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006575 " local normal-mode maps {{{3
6576 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6577 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6578 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6579 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6580 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6581 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6582 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6583 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6584 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6585 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6586 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6587" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006588 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6589 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6590 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006591 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006592 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006593 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6594 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6595 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6596 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006597 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6598 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6599 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6600 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6601 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6602 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6603 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6604 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6605 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6606 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6607 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6608 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6609 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006610 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006611 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006612 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6613 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6614 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6615 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6616 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006617 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006618 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006619 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6620 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006621 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6622 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6623 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006624 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006625 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006626 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6627 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006628 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006629 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006630 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6631 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6632 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006633 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6634 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006635
6636 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 +01006637 if !hasmapto('<Plug>NetrwHideEdit')
6638 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006639 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006640 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006641 if !hasmapto('<Plug>NetrwRefresh')
6642 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006643 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006644 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 +01006645 if s:didstarstar || !mapcheck("<s-down>","n")
6646 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006647 endif
6648 if s:didstarstar || !mapcheck("<s-up>","n")
6649 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006650 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006651 if !hasmapto('<Plug>NetrwTreeSqueeze')
6652 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006653 endif
6654 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006655 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6656 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006657 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6658 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6659 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6660 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6661 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6662 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6663 imap <buffer> <leftmouse> <Plug>ILeftmouse
6664 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006665 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6666 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6667 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6668 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6669 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006670 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006671 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6672 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006673 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006674 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6675 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6676 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6677 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6678 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6679 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6680 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006681 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6682
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006683 " support user-specified maps
6684 call netrw#UserMaps(1)
6685
Bram Moolenaar85850f32019-07-19 22:05:51 +02006686 else
6687 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006688" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006689 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006690 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6691 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6692 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6693 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6694 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6695 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6696 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6697 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6698 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6699 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6700 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6701" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006702 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6703 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6704 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6705 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6706 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6707 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6708 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6709 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006710 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006711 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006712 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6713 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6714 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6715 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6716 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6717 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6718 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6719 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6720 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6721 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6722 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006723 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006724 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006725 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6726 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6727 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6728 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6729 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006730 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6731 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6732 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6733 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006734 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006735 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6736 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006737 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006738 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 +01006739 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6740 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6741 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6742 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6743 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6744 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6745 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6746 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6747 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006748 if !hasmapto('<Plug>NetrwHideEdit')
6749 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006750 endif
6751 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6752 if !hasmapto('<Plug>NetrwRefresh')
6753 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006754 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006755 if !hasmapto('<Plug>NetrwTreeSqueeze')
6756 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006757 endif
6758 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006759
6760 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006761 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006762
6763 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6764 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006765 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006766 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006767 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006768 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006769 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006770 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006771 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006772 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006773 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006774 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006775 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6776 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6777 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006778 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006779 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006780 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6781 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006782 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006783 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6784 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6785 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6786 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6787 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6788 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6789 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006790 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006791
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006792 " support user-specified maps
6793 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006794 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006795
6796" call Dret("s:NetrwMaps")
6797endfun
6798
6799" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006800" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006801" If -buffer, the command is only available from within netrw buffers
6802" Otherwise, the command is available from any window, so long as netrw
6803" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006804fun! s:NetrwCommands(islocal)
6805" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6806
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006807 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6808 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006809 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 +01006810 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006811 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006812 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006813 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006814 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006815 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006816
6817" call Dret("s:NetrwCommands")
6818endfun
6819
6820" ---------------------------------------------------------------------
6821" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6822" glob()ing only works with local files
6823fun! s:NetrwMarkFiles(islocal,...)
6824" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006825 let curdir = s:NetrwGetCurdir(a:islocal)
6826 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006827 while i <= a:0
6828 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006829 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006830 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006831 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006832 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006833 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006834 else
6835 let mffiles= [a:{i}]
6836 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006837" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006838 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006839" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006840 call s:NetrwMarkFile(a:islocal,mffile)
6841 endfor
6842 let i= i + 1
6843 endwhile
6844" call Dret("s:NetrwMarkFiles")
6845endfun
6846
6847" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006848" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006849fun! s:NetrwMarkTarget(...)
6850" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6851 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006852 let curdir = s:NetrwGetCurdir(1)
6853 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006854 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006855 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6856 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006857 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006858" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006859 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006860 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6861 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006862 let svpos = winsaveview()
6863" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006864 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006865" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6866 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006867" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006868endfun
6869
6870" ---------------------------------------------------------------------
6871" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6872" mark and unmark files. If a markfile list exists,
6873" then the rename and delete functions will use it instead
6874" of whatever may happen to be under the cursor at that
6875" moment. When the mouse and gui are available,
6876" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006877"
6878" Creates two lists
6879" s:netrwmarkfilelist -- holds complete paths to all marked files
6880" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6881"
6882" Creates a marked file match string
6883" s:netrwmarfilemtch_# -- used with 2match to display marked files
6884"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006885" Creates a buffer version of islocal
6886" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006887fun! s:NetrwMarkFile(islocal,fname)
6888" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006889" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006890
6891 " sanity check
6892 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006893" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006894 return
6895 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006896 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006897
Bram Moolenaar97d62492012-11-15 21:28:22 +01006898 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006899 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006900 if a:fname =~ '^\a'
6901 let leader= '\<'
6902 else
6903 let leader= ''
6904 endif
6905 if a:fname =~ '\a$'
6906 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6907 else
6908 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6909 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006910
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006911 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006912 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006913" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6914" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6915" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006916 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006917
6918 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006919 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006920" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006921 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006922 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006923
6924 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006925 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006926" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006927 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6928 if s:netrwmarkfilelist_{curbufnr} == []
6929 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006930" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006931 call s:NetrwUnmarkList(curbufnr,curdir)
6932 else
6933 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006934" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006935 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006936 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006937 for fname in s:netrwmarkfilelist_{curbufnr}
6938 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006939 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006940 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006941 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942 endif
6943 let first= 0
6944 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006945" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006946 endif
6947 endif
6948
6949 else
6950 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006951" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006952
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006953" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006954 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006955 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6956" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006957
6958 " build initial markfile matching pattern
6959 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006960 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006961 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006962 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006963 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006964" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006965 endif
6966
6967 " handle global markfilelist
6968 if exists("s:netrwmarkfilelist")
6969 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6970 if index(s:netrwmarkfilelist,dname) == -1
6971 " append new filename to global markfilelist
6972 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006973" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006974 else
6975 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006976" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6977" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006978 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006979" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006980 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006981" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006982 unlet s:netrwmarkfilelist
6983 endif
6984 endif
6985 else
6986 " initialize new global-directory markfilelist
6987 let s:netrwmarkfilelist= []
6988 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006989" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006990 endif
6991
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006992 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006993 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6994 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6995" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6996 if exists("g:did_drchip_netrwlist_syntax")
6997 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6998 endif
6999 else
7000" " call Decho("2match none",'~'.expand("<slnum>"))
7001 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01007002 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007003 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007004 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007005" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
7006" 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 +00007007endfun
7008
7009" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007010" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7011" mA: move the argument list to marked file list (tomflist=1)
7012" Uses the global marked file list
7013fun! s:NetrwMarkFileArgList(islocal,tomflist)
7014" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7015
7016 let svpos = winsaveview()
7017" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7018 let curdir = s:NetrwGetCurdir(a:islocal)
7019 let curbufnr = bufnr("%")
7020
7021 if a:tomflist
7022 " mA: move argument list to marked file list
7023 while argc()
7024 let fname= argv(0)
7025" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7026 exe "argdel ".fnameescape(fname)
7027 call s:NetrwMarkFile(a:islocal,fname)
7028 endwhile
7029
7030 else
7031 " ma: move marked file list to argument list
7032 if exists("s:netrwmarkfilelist")
7033
7034 " for every filename in the marked list
7035 for fname in s:netrwmarkfilelist
7036" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7037 exe "argadd ".fnameescape(fname)
7038 endfor " for every file in the marked list
7039
7040 " unmark list and refresh
7041 call s:NetrwUnmarkList(curbufnr,curdir)
7042 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7043" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7044 NetrwKeepj call winrestview(svpos)
7045 endif
7046 endif
7047
7048" call Dret("s:NetrwMarkFileArgList")
7049endfun
7050
7051" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007052" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7053" compress/decompress files using the programs
7054" in g:netrw_compress and g:netrw_uncompress,
7055" using g:netrw_compress_suffix to know which to
7056" do. By default:
7057" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007058" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007059fun! s:NetrwMarkFileCompress(islocal)
7060" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007061 let svpos = winsaveview()
7062" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007063 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007064 let curbufnr = bufnr("%")
7065
Bram Moolenaarff034192013-04-24 18:51:19 +02007066 " sanity check
7067 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007068 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007069" call Dret("s:NetrwMarkFileCompress")
7070 return
7071 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007072" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007073
Bram Moolenaar446cb832008-06-24 21:56:24 +00007074 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007075
7076 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007077 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007078 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007079" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007080 if exists("g:netrw_decompress['".sfx."']")
7081 " fname has a suffix indicating that its compressed; apply associated decompression routine
7082 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007083" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007084 let exe= netrw#WinPath(exe)
7085 if a:islocal
7086 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007087 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007088 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007089 call system(exe." ".fname)
7090 if v:shell_error
7091 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007092 endif
7093 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007094 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7095 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007096 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007097
Bram Moolenaarff034192013-04-24 18:51:19 +02007098 endif
7099 unlet sfx
7100
Bram Moolenaar446cb832008-06-24 21:56:24 +00007101 if exists("exe")
7102 unlet exe
7103 elseif a:islocal
7104 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007105 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007106 if v:shell_error
7107 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7108 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007109 else
7110 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007111 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007112 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007113 endfor " for every file in the marked list
7114
Bram Moolenaar446cb832008-06-24 21:56:24 +00007115 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007116 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007117" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7118 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007119 endif
7120" call Dret("s:NetrwMarkFileCompress")
7121endfun
7122
7123" ---------------------------------------------------------------------
7124" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7125" If no marked files, then set up directory as the
7126" target. Currently does not support copying entire
7127" directories. Uses the local-buffer marked file list.
7128" Returns 1=success (used by NetrwMarkFileMove())
7129" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007130fun! s:NetrwMarkFileCopy(islocal,...)
7131" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7132
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007133 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007134 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007135 if b:netrw_curdir !~ '/$'
7136 if !exists("b:netrw_curdir")
7137 let b:netrw_curdir= curdir
7138 endif
7139 let b:netrw_curdir= b:netrw_curdir."/"
7140 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007141
Bram Moolenaarff034192013-04-24 18:51:19 +02007142 " sanity check
7143 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007144 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007145" call Dret("s:NetrwMarkFileCopy")
7146 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007147 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007148" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007149
Bram Moolenaar446cb832008-06-24 21:56:24 +00007150 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007151 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007152" call Dret("s:NetrwMarkFileCopy 0")
7153 return 0
7154 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007155" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007156
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007157 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007158 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007159" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007160 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007161 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7162" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7163 return
7164 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007165
7166 " copy marked files while within the same directory (ie. allow renaming)
7167 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7168 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7169 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007170" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007171 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007172 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7173 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007174" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007175 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007176 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007177 let oldname = a:1
7178 else
7179 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007180" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007181 let s:recursive= 1
7182 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7183 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7184 if ret == 0
7185 break
7186 endif
7187 endfor
7188 unlet s:recursive
7189 call s:NetrwUnmarkList(curbufnr,curdir)
7190" call Dret("s:NetrwMarkFileCopy ".ret)
7191 return ret
7192 endif
7193
7194 call inputsave()
7195 let newname= input("Copy ".oldname." to : ",oldname,"file")
7196 call inputrestore()
7197 if newname == ""
7198" call Dret("s:NetrwMarkFileCopy 0")
7199 return 0
7200 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007201 let args= s:ShellEscape(oldname)
7202 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007203 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007204 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7205 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007206 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007207 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007208 let args= substitute(args,'/','\\','g')
7209 let tgt = substitute(tgt, '/','\\','g')
7210 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007211 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7212 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7213 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7214 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7215" call Decho("args <".args.">",'~'.expand("<slnum>"))
7216" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007217 if isdirectory(s:NetrwFile(args))
7218" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007219 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007220" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007221 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007222 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7223 " contents to a target. One must append the source directory name to the target to get xcopy to
7224 " do the right thing.
7225 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007226" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007227 endif
7228 else
7229 let copycmd= g:netrw_localcopycmd
7230 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007231 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007232 let copycmd = substitute(copycmd,'\s.*$','','')
7233 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007234 let copycmd = netrw#WinPath(copycmd).copycmdargs
7235 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007236 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007237 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007238" call Decho("args <".args.">",'~'.expand("<slnum>"))
7239" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7240" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7241" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007242 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007243 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007244 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007245 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 +01007246 else
7247 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7248 endif
7249" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007250 return 0
7251 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007252
7253 elseif a:islocal && !s:netrwmftgt_islocal
7254 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007255" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007256 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007257
7258 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007259 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007260" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007261 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007262
7263 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007264 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007265" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007266 let curdir = getcwd()
7267 let tmpdir = s:GetTempfile("")
7268 if tmpdir !~ '/'
7269 let tmpdir= curdir."/".tmpdir
7270 endif
7271 if exists("*mkdir")
7272 call mkdir(tmpdir)
7273 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007274 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007275 if v:shell_error != 0
7276 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 +01007277" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007278 return
7279 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007280 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007281 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007282 if s:NetrwLcd(tmpdir)
7283" call Dret("s:NetrwMarkFileCopy : lcd failure")
7284 return
7285 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007286 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007287 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007288 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007289 if getcwd() == tmpdir
7290 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007291 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007292 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007293 if s:NetrwLcd(curdir)
7294" call Dret("s:NetrwMarkFileCopy : lcd failure")
7295 return
7296 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007297 if delete(tmpdir,"d")
7298 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007299 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007300 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007301 if s:NetrwLcd(curdir)
7302" call Dret("s:NetrwMarkFileCopy : lcd failure")
7303 return
7304 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007305 endif
7306 endif
7307 endif
7308
7309 " -------
7310 " cleanup
7311 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007312" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007313 " remove markings from local buffer
7314 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007315" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7316" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7317" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7318" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7319" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7320" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7321 if exists("s:recursive")
7322" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7323 else
7324" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007325 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007326 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007327 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007328 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007329 else
7330 " refresh local and targets for fast browsing
7331 if !exists("s:recursive")
7332 " remove markings from local buffer
7333" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7334 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7335 endif
7336
7337 " refresh buffers
7338 if s:netrwmftgt_islocal
7339" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7340 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7341 endif
7342 if a:islocal && s:netrwmftgt != curdir
7343" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7344 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7345 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007346 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007347
Bram Moolenaar446cb832008-06-24 21:56:24 +00007348" call Dret("s:NetrwMarkFileCopy 1")
7349 return 1
7350endfun
7351
7352" ---------------------------------------------------------------------
7353" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7354" invoke vim's diff mode on the marked files.
7355" Either two or three files can be so handled.
7356" Uses the global marked file list.
7357fun! s:NetrwMarkFileDiff(islocal)
7358" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7359 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007360
Bram Moolenaarff034192013-04-24 18:51:19 +02007361 " sanity check
7362 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007363 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007364" call Dret("s:NetrwMarkFileDiff")
7365 return
7366 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007367 let curdir= s:NetrwGetCurdir(a:islocal)
7368" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007369
Bram Moolenaara6878372014-03-22 21:02:50 +01007370 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007371 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007372 for fname in s:netrwmarkfilelist
7373 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007374 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007375" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007376 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007377 diffthis
7378 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007379 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007380" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007381 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007382 diffthis
7383 else
7384 break
7385 endif
7386 endfor
7387 call s:NetrwUnmarkList(curbufnr,curdir)
7388 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007389
Bram Moolenaar446cb832008-06-24 21:56:24 +00007390" call Dret("s:NetrwMarkFileDiff")
7391endfun
7392
7393" ---------------------------------------------------------------------
7394" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7395" Uses global markfilelist
7396fun! s:NetrwMarkFileEdit(islocal)
7397" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7398
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007399 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007400 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007401
7402 " sanity check
7403 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007404 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007405" call Dret("s:NetrwMarkFileEdit")
7406 return
7407 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007408" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007409
Bram Moolenaar446cb832008-06-24 21:56:24 +00007410 if exists("s:netrwmarkfilelist_{curbufnr}")
7411 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007412 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007413 " unmark markedfile list
7414" call s:NetrwUnmarkList(curbufnr,curdir)
7415 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007416" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007417 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007418 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007419 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007420
Bram Moolenaar446cb832008-06-24 21:56:24 +00007421" call Dret("s:NetrwMarkFileEdit")
7422endfun
7423
7424" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007425" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007426fun! s:NetrwMarkFileQFEL(islocal,qfel)
7427" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7428 call s:NetrwUnmarkAll()
7429 let curbufnr= bufnr("%")
7430
7431 if !empty(a:qfel)
7432 for entry in a:qfel
7433 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007434" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007435 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007436" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007437 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7438 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7439 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7440 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007441" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007442 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7443 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007444" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007445 endif
7446 endfor
7447 echo "(use me to edit marked files)"
7448 else
7449 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7450 endif
7451
7452" call Dret("s:NetrwMarkFileQFEL")
7453endfun
7454
7455" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007456" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7457" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7458" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7459fun! s:NetrwMarkFileExe(islocal,enbloc)
7460" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007461 let svpos = winsaveview()
7462" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007463 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007464 let curbufnr = bufnr("%")
7465
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007466 if a:enbloc == 0
7467 " individually apply command to files, one at a time
7468 " sanity check
7469 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7470 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7471" call Dret("s:NetrwMarkFileExe")
7472 return
7473 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007474" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007475
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007476 if exists("s:netrwmarkfilelist_{curbufnr}")
7477 " get the command
7478 call inputsave()
7479 let cmd= input("Enter command: ","","file")
7480 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007481" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007482 if cmd == ""
7483" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7484 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007485 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007486
7487 " apply command to marked files, individually. Substitute: filename -> %
7488 " If no %, then append a space and the filename to the command
7489 for fname in s:netrwmarkfilelist_{curbufnr}
7490 if a:islocal
7491 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007492 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007493 endif
7494 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007495 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007496 endif
7497 if cmd =~ '%'
7498 let xcmd= substitute(cmd,'%',fname,'g')
7499 else
7500 let xcmd= cmd.' '.fname
7501 endif
7502 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007503" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007504 let ret= system(xcmd)
7505 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007506" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007507 let ret= s:RemoteSystem(xcmd)
7508 endif
7509 if v:shell_error < 0
7510 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7511 break
7512 else
7513 echo ret
7514 endif
7515 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007516
7517 " unmark marked file list
7518 call s:NetrwUnmarkList(curbufnr,curdir)
7519
7520 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007521 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007522" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7523 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007524 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007525 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007526 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007527
7528 else " apply command to global list of files, en bloc
7529
7530 call inputsave()
7531 let cmd= input("Enter command: ","","file")
7532 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007533" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007534 if cmd == ""
7535" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7536 return
7537 endif
7538 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007539 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007540 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007541 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007542 endif
7543 if a:islocal
7544 call system(cmd)
7545 if v:shell_error < 0
7546 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7547 endif
7548 else
7549 let ret= s:RemoteSystem(cmd)
7550 endif
7551 call s:NetrwUnmarkAll()
7552
7553 " refresh the listing
7554 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007555" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7556 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007557
7558 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007559
Bram Moolenaar446cb832008-06-24 21:56:24 +00007560" call Dret("s:NetrwMarkFileExe")
7561endfun
7562
7563" ---------------------------------------------------------------------
7564" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7565" as the marked file(s) (toggles suffix presence)
7566" Uses the local marked file list.
7567fun! s:NetrwMarkHideSfx(islocal)
7568" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007569 let svpos = winsaveview()
7570" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007571 let curbufnr = bufnr("%")
7572
7573 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7574 if exists("s:netrwmarkfilelist_{curbufnr}")
7575
7576 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007577" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007578 " construct suffix pattern
7579 if fname =~ '\.'
7580 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7581 else
7582 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7583 endif
7584 " determine if its in the hiding list or not
7585 let inhidelist= 0
7586 if g:netrw_list_hide != ""
7587 let itemnum = 0
7588 let hidelist= split(g:netrw_list_hide,',')
7589 for hidepat in hidelist
7590 if sfxpat == hidepat
7591 let inhidelist= 1
7592 break
7593 endif
7594 let itemnum= itemnum + 1
7595 endfor
7596 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007597" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007598 if inhidelist
7599 " remove sfxpat from list
7600 call remove(hidelist,itemnum)
7601 let g:netrw_list_hide= join(hidelist,",")
7602 elseif g:netrw_list_hide != ""
7603 " append sfxpat to non-empty list
7604 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7605 else
7606 " set hiding list to sfxpat
7607 let g:netrw_list_hide= sfxpat
7608 endif
7609 endfor
7610
7611 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007612 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007613" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7614 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007615 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007616 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007617 endif
7618
7619" call Dret("s:NetrwMarkHideSfx")
7620endfun
7621
7622" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007623" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007624" Uses the local marked-file list.
7625fun! s:NetrwMarkFileVimCmd(islocal)
7626" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007627 let svpos = winsaveview()
7628" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007629 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007630 let curbufnr = bufnr("%")
7631
Bram Moolenaarff034192013-04-24 18:51:19 +02007632 " sanity check
7633 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007634 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007635" call Dret("s:NetrwMarkFileVimCmd")
7636 return
7637 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007638" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007639
Bram Moolenaar15146672011-10-20 22:22:38 +02007640 if exists("s:netrwmarkfilelist_{curbufnr}")
7641 " get the command
7642 call inputsave()
7643 let cmd= input("Enter vim command: ","","file")
7644 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007645" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007646 if cmd == ""
7647" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7648 return
7649 endif
7650
7651 " apply command to marked files. Substitute: filename -> %
7652 " If no %, then append a space and the filename to the command
7653 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007654" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007655 if a:islocal
7656 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007657 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007658" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007659 exe cmd
7660 exe "sil! keepalt wq!"
7661 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007662" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007663 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007664 endif
7665 endfor
7666
7667 " unmark marked file list
7668 call s:NetrwUnmarkList(curbufnr,curdir)
7669
7670 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007671 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007672" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7673 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007674 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007675 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007676 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007677
Bram Moolenaar15146672011-10-20 22:22:38 +02007678" call Dret("s:NetrwMarkFileVimCmd")
7679endfun
7680
7681" ---------------------------------------------------------------------
7682" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7683" as the marked file(s) (toggles suffix presence)
7684" Uses the local marked file list.
7685fun! s:NetrwMarkHideSfx(islocal)
7686" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007687 let svpos = winsaveview()
7688" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007689 let curbufnr = bufnr("%")
7690
7691 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7692 if exists("s:netrwmarkfilelist_{curbufnr}")
7693
7694 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007695" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007696 " construct suffix pattern
7697 if fname =~ '\.'
7698 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7699 else
7700 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7701 endif
7702 " determine if its in the hiding list or not
7703 let inhidelist= 0
7704 if g:netrw_list_hide != ""
7705 let itemnum = 0
7706 let hidelist= split(g:netrw_list_hide,',')
7707 for hidepat in hidelist
7708 if sfxpat == hidepat
7709 let inhidelist= 1
7710 break
7711 endif
7712 let itemnum= itemnum + 1
7713 endfor
7714 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007715" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007716 if inhidelist
7717 " remove sfxpat from list
7718 call remove(hidelist,itemnum)
7719 let g:netrw_list_hide= join(hidelist,",")
7720 elseif g:netrw_list_hide != ""
7721 " append sfxpat to non-empty list
7722 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7723 else
7724 " set hiding list to sfxpat
7725 let g:netrw_list_hide= sfxpat
7726 endif
7727 endfor
7728
7729 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007730 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007731" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7732 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007733 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007734 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007735 endif
7736
7737" call Dret("s:NetrwMarkHideSfx")
7738endfun
7739
7740" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007741" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7742" Uses the global markfilelist
7743fun! s:NetrwMarkFileGrep(islocal)
7744" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007745 let svpos = winsaveview()
7746" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007747 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007748 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007749
7750 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007751" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007752 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007753" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007754 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007755 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007756" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007757 let netrwmarkfilelist= "*"
7758 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007759
Bram Moolenaarff034192013-04-24 18:51:19 +02007760 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007761" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007762 call inputsave()
7763 let pat= input("Enter pattern: ","")
7764 call inputrestore()
7765 let patbang = ""
7766 if pat =~ '^!'
7767 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007768 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007769 endif
7770 if pat =~ '^\i'
7771 let pat = escape(pat,'/')
7772 let pat = '/'.pat.'/'
7773 else
7774 let nonisi = pat[0]
7775 endif
7776
7777 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007778" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007779 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007780 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007781 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007782 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007783" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7784 return
7785 endtry
7786 echo "(use :cn, :cp to navigate, :Rex to return)"
7787
7788 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007789" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7790 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007791
7792 if exists("nonisi")
7793 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007794" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007795 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007796 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007797 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007798 endif
7799
7800" call Dret("s:NetrwMarkFileGrep")
7801endfun
7802
7803" ---------------------------------------------------------------------
7804" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7805" uses the global marked file list
7806" s:netrwmfloc= 0: target directory is remote
7807" = 1: target directory is local
7808fun! s:NetrwMarkFileMove(islocal)
7809" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007810 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007811 let curbufnr = bufnr("%")
7812
7813 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007814 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007815 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007816" call Dret("s:NetrwMarkFileMove")
7817 return
7818 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007819" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007820
Bram Moolenaar446cb832008-06-24 21:56:24 +00007821 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007822 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007823" call Dret("s:NetrwMarkFileCopy 0")
7824 return 0
7825 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007826" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007827
7828 if a:islocal && s:netrwmftgt_islocal
7829 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007830" call Decho("move from local to local",'~'.expand("<slnum>"))
7831" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007832 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007833 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7834" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7835 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007836 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007837 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007838" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007839 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007840 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007841" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007842 if g:netrw_localmovecmd =~ '\s'
7843 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7844 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7845 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007846" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007847 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007848 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007849" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007850 endif
7851 else
7852 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007854 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007855 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007856 if g:netrw_keepdir
7857 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7858 let fname= b:netrw_curdir."/".fname
7859 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007860 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007861 let fname= substitute(fname,'/','\\','g')
7862 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007863" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007864 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007865 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007866 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007867 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 +01007868 else
7869 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7870 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007871 break
7872 endif
7873 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007874
7875 elseif a:islocal && !s:netrwmftgt_islocal
7876 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007877" call Decho("move from local to remote",'~'.expand("<slnum>"))
7878" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007879 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007880 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007881" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007882 for fname in mflist
7883 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7884 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7885 endfor
7886 unlet mflist
7887
7888 elseif !a:islocal && s:netrwmftgt_islocal
7889 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007890" call Decho("move from remote to local",'~'.expand("<slnum>"))
7891" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007892 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007893 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007894" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007895 for fname in mflist
7896 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7897 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7898 endfor
7899 unlet mflist
7900
7901 elseif !a:islocal && !s:netrwmftgt_islocal
7902 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007903" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7904" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007905 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007906 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007907" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007908 for fname in mflist
7909 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7910 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7911 endfor
7912 unlet mflist
7913 endif
7914
7915 " -------
7916 " cleanup
7917 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007918" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007919
7920 " remove markings from local buffer
7921 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7922
7923 " refresh buffers
7924 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007925" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007926 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007927 endif
7928 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007929" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007930 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007931 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007932 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007933" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007934 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007935 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007936
Bram Moolenaar446cb832008-06-24 21:56:24 +00007937" call Dret("s:NetrwMarkFileMove")
7938endfun
7939
7940" ---------------------------------------------------------------------
7941" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7942" using the hardcopy command. Local marked-file list only.
7943fun! s:NetrwMarkFilePrint(islocal)
7944" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7945 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007946
7947 " sanity check
7948 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007949 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007950" call Dret("s:NetrwMarkFilePrint")
7951 return
7952 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007953" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7954 let curdir= s:NetrwGetCurdir(a:islocal)
7955
Bram Moolenaar446cb832008-06-24 21:56:24 +00007956 if exists("s:netrwmarkfilelist_{curbufnr}")
7957 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007958 call s:NetrwUnmarkList(curbufnr,curdir)
7959 for fname in netrwmarkfilelist
7960 if a:islocal
7961 if g:netrw_keepdir
7962 let fname= s:ComposePath(curdir,fname)
7963 endif
7964 else
7965 let fname= curdir.fname
7966 endif
7967 1split
7968 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007969" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007970 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007971" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007972 hardcopy
7973 q
7974 endfor
7975 2match none
7976 endif
7977" call Dret("s:NetrwMarkFilePrint")
7978endfun
7979
7980" ---------------------------------------------------------------------
7981" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7982" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007983" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007984fun! s:NetrwMarkFileRegexp(islocal)
7985" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7986
7987 " get the regular expression
7988 call inputsave()
7989 let regexp= input("Enter regexp: ","","file")
7990 call inputrestore()
7991
7992 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007993 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007994" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007995 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007996" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007997 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007998 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007999 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008000 else
8001 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008002 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008003 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008004" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008005
8006 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008007 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02008008 if fname =~ '^'.fnameescape(curdir)
8009" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8010 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8011 else
8012" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8013 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8014 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008015 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008016
8017 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008018" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008019
8020 " convert displayed listing into a filelist
8021 let eikeep = &ei
8022 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008023 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008024 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008025" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008026 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008027 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008028 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008029 sil NetrwKeepj norm! "ap
8030 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008031 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008032 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008033 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008034 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008035 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008036 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008037 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008038 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008039 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008040 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008041 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8042 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008043 call histdel("/",-1)
8044 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008045 endif
8046 " convert regexp into the more usual glob-style format
8047 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008048" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008049 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008050 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008051 let filelist= getline(1,line("$"))
8052 q!
8053 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008054 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008055 endfor
8056 unlet filelist
8057 let @a = areg
8058 let &ei = eikeep
8059 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008060 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008061
8062" call Dret("s:NetrwMarkFileRegexp")
8063endfun
8064
8065" ---------------------------------------------------------------------
8066" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8067" Uses the local marked file list.
8068fun! s:NetrwMarkFileSource(islocal)
8069" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8070 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008071
8072 " sanity check
8073 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008074 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008075" call Dret("s:NetrwMarkFileSource")
8076 return
8077 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008078" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8079 let curdir= s:NetrwGetCurdir(a:islocal)
8080
Bram Moolenaar446cb832008-06-24 21:56:24 +00008081 if exists("s:netrwmarkfilelist_{curbufnr}")
8082 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008083 call s:NetrwUnmarkList(curbufnr,curdir)
8084 for fname in netrwmarkfilelist
8085 if a:islocal
8086 if g:netrw_keepdir
8087 let fname= s:ComposePath(curdir,fname)
8088 endif
8089 else
8090 let fname= curdir.fname
8091 endif
8092 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008093" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008094 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008095 endfor
8096 2match none
8097 endif
8098" call Dret("s:NetrwMarkFileSource")
8099endfun
8100
8101" ---------------------------------------------------------------------
8102" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8103" Uses the global markfilelist
8104fun! s:NetrwMarkFileTag(islocal)
8105" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008106 let svpos = winsaveview()
8107" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008108 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008109 let curbufnr = bufnr("%")
8110
Bram Moolenaarff034192013-04-24 18:51:19 +02008111 " sanity check
8112 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008113 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008114" call Dret("s:NetrwMarkFileTag")
8115 return
8116 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008117" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008118
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008120" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8121 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008122 call s:NetrwUnmarkAll()
8123
8124 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008125
8126" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8127 call system(g:netrw_ctags." ".netrwmarkfilelist)
8128 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008129 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8130 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008131
Bram Moolenaar446cb832008-06-24 21:56:24 +00008132 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008133 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008134 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008135 let curdir= b:netrw_curdir
8136 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008137 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008138 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008139" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008140 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008141 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008142 wq!
8143 endif
8144 2match none
8145 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008146" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8147 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008148 endif
8149
8150" call Dret("s:NetrwMarkFileTag")
8151endfun
8152
8153" ---------------------------------------------------------------------
8154" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008155" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008156" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008157" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008158" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008159fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008160" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8161 let svpos = winsaveview()
8162" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008163 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008164 let hadtgt = exists("s:netrwmftgt")
8165 if !exists("w:netrw_bannercnt")
8166 let w:netrw_bannercnt= b:netrw_bannercnt
8167 endif
8168
8169 " set up target
8170 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008171" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008172 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8173 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008174" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008175 unlet s:netrwmftgt s:netrwmftgt_islocal
8176 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008177 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008178 endif
8179 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008180" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8181 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008182" call Dret("s:NetrwMarkFileTgt : removed target")
8183 return
8184 else
8185 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008186" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008187 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008188
8189 else
8190 " get word under cursor.
8191 " * If directory, use it for the target.
8192 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008193" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008194 let curword= s:NetrwGetWord()
8195 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008196 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008197 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008198" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008199 elseif !a:islocal && tgtdir =~ '/$'
8200 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008201" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008202 else
8203 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008204" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008205 endif
8206 endif
8207 if a:islocal
8208 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8209 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008210" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008211 endif
8212 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008213 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008214 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8215 endif
8216 let s:netrwmftgt_islocal= a:islocal
8217
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008218 " need to do refresh so that the banner will be updated
8219 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008220 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008221" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008222 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008223 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008224" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
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 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8227 else
8228 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8229 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008230" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8231 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008232 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008233 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008234 endif
8235
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008236" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8237" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008238" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8239endfun
8240
8241" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008242" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8243fun! s:NetrwGetCurdir(islocal)
8244" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8245
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008246 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008247 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8248" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8249 elseif !exists("b:netrw_curdir")
8250 let b:netrw_curdir= getcwd()
8251" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8252 endif
8253
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008254" 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 +01008255 if b:netrw_curdir !~ '\<\a\{3,}://'
8256 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008257" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008258 if g:netrw_keepdir == 0
8259 call s:NetrwLcd(curdir)
8260 endif
8261 endif
8262
8263" call Dret("s:NetrwGetCurdir <".curdir.">")
8264 return b:netrw_curdir
8265endfun
8266
8267" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008268" s:NetrwOpenFile: query user for a filename and open it {{{2
8269fun! s:NetrwOpenFile(islocal)
8270" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008271 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008272 call inputsave()
8273 let fname= input("Enter filename: ")
8274 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008275" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8276
8277 " determine if Lexplore is in use
8278 if exists("t:netrw_lexbufnr")
8279 " check if t:netrw_lexbufnr refers to a netrw window
8280" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8281 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8282 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8283" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8284 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8285 exe "NetrwKeepj e ".fnameescape(fname)
8286 let @@= ykeep
8287" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8288 endif
8289 endif
8290
8291 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008292 if fname !~ '[/\\]'
8293 if exists("b:netrw_curdir")
8294 if exists("g:netrw_quiet")
8295 let netrw_quiet_keep = g:netrw_quiet
8296 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008297 let g:netrw_quiet = 1
8298 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008299 let s:rexposn_{bufnr("%")}= winsaveview()
8300" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008301 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008302 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008303 else
8304 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8305 endif
8306 if exists("netrw_quiet_keep")
8307 let g:netrw_quiet= netrw_quiet_keep
8308 else
8309 unlet g:netrw_quiet
8310 endif
8311 endif
8312 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008313 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008314 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008315 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008316" call Dret("s:NetrwOpenFile")
8317endfun
8318
8319" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008320" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8321" For the mapping to this function be made via
8322" netrwPlugin, you'll need to have had
8323" g:netrw_usetab set to non-zero.
8324fun! netrw#Shrink()
8325" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8326 let curwin = winnr()
8327 let wiwkeep = &wiw
8328 set wiw=1
8329
8330 if &ft == "netrw"
8331 if winwidth(0) > g:netrw_wiw
8332 let t:netrw_winwidth= winwidth(0)
8333 exe "vert resize ".g:netrw_wiw
8334 wincmd l
8335 if winnr() == curwin
8336 wincmd h
8337 endif
8338" call Decho("vert resize 0",'~'.expand("<slnum>"))
8339 else
8340 exe "vert resize ".t:netrw_winwidth
8341" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8342 endif
8343
8344 elseif exists("t:netrw_lexbufnr")
8345 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8346 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8347 let t:netrw_winwidth= winwidth(0)
8348 exe "vert resize ".g:netrw_wiw
8349 wincmd l
8350 if winnr() == curwin
8351 wincmd h
8352 endif
8353" call Decho("vert resize 0",'~'.expand("<slnum>"))
8354 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8355 exe "vert resize ".t:netrw_winwidth
8356" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8357 else
8358 call netrw#Lexplore(0,0)
8359 endif
8360
8361 else
8362 call netrw#Lexplore(0,0)
8363 endif
8364 let wiw= wiwkeep
8365
8366" call Dret("netrw#Shrink")
8367endfun
8368
8369" ---------------------------------------------------------------------
8370" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8371fun! s:NetSortSequence(islocal)
8372" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8373
8374 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008375 let svpos= winsaveview()
8376" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008377 call inputsave()
8378 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8379 call inputrestore()
8380
8381 " refresh the listing
8382 let g:netrw_sort_sequence= newsortseq
8383 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008384" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8385 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008386 let @@= ykeep
8387
8388" call Dret("NetSortSequence")
8389endfun
8390
8391" ---------------------------------------------------------------------
8392" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8393" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008394" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008395fun! s:NetrwUnmarkList(curbufnr,curdir)
8396" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8397
8398 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008399 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008400 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8401 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8402 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8403 call remove(s:netrwmarkfilelist,idx) " remove from global list
8404 endfor
8405 if s:netrwmarkfilelist == []
8406 unlet s:netrwmarkfilelist
8407 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008408
Bram Moolenaar446cb832008-06-24 21:56:24 +00008409 " getting rid of the local marked-file lists is easy
8410 unlet s:netrwmarkfilelist_{a:curbufnr}
8411 endif
8412 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8413 unlet s:netrwmarkfilemtch_{a:curbufnr}
8414 endif
8415 2match none
8416" call Dret("s:NetrwUnmarkList")
8417endfun
8418
8419" ---------------------------------------------------------------------
8420" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8421fun! s:NetrwUnmarkAll()
8422" call Dfunc("s:NetrwUnmarkAll()")
8423 if exists("s:netrwmarkfilelist")
8424 unlet s:netrwmarkfilelist
8425 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008426 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008427 2match none
8428" call Dret("s:NetrwUnmarkAll")
8429endfun
8430
8431" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008432" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008433fun! s:NetrwUnmarkAll2()
8434" call Dfunc("s:NetrwUnmarkAll2()")
8435 redir => netrwmarkfilelist_let
8436 let
8437 redir END
8438 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008439 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008440 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8441 for flist in netrwmarkfilelist_list
8442 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8443 unlet s:netrwmarkfilelist_{curbufnr}
8444 unlet s:netrwmarkfilemtch_{curbufnr}
8445 endfor
8446" call Dret("s:NetrwUnmarkAll2")
8447endfun
8448
8449" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008450" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8451"
8452" Marked files are in two types of lists:
8453" s:netrwmarkfilelist -- holds complete paths to all marked files
8454" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8455"
8456" Marked files suitable for use with 2match are in:
8457" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008458fun! s:NetrwUnMarkFile(islocal)
8459" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008460 let svpos = winsaveview()
8461" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008462 let curbufnr = bufnr("%")
8463
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008464 " unmark marked file list
8465 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8466 if exists("s:netrwmarkfilelist")
8467" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008468 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008469 endif
8470
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008471 let ibuf= 1
8472 while ibuf < bufnr("$")
8473 if exists("s:netrwmarkfilelist_".ibuf)
8474 unlet s:netrwmarkfilelist_{ibuf}
8475 unlet s:netrwmarkfilemtch_{ibuf}
8476 endif
8477 let ibuf = ibuf + 1
8478 endwhile
8479 2match none
8480
Bram Moolenaar446cb832008-06-24 21:56:24 +00008481" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008482"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8483call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008484" call Dret("s:NetrwUnMarkFile")
8485endfun
8486
8487" ---------------------------------------------------------------------
8488" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8489fun! s:NetrwMenu(domenu)
8490
8491 if !exists("g:NetrwMenuPriority")
8492 let g:NetrwMenuPriority= 80
8493 endif
8494
Bram Moolenaaradc21822011-04-01 18:03:16 +02008495 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008496" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8497
8498 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008499" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008500 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008501 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8505 if g:netrw_dirhistmax > 0
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8510 else
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8512 endif
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8527 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 +01008528 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 +02008529 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8552 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8553 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8555 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8556 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8558 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>'
8559 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>'
8560 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>'
8561 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8562 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>'
8563 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>'
8564 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 +01008565 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 +02008566 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8567 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008568 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008569 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8570 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008571
8572 elseif !a:domenu
8573 let s:netrwcnt = 0
8574 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008575 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008576 exe curwin."wincmd w"
8577
8578 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008579" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008580 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008581" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008582 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008583 endif
8584 endif
8585" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008586 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008587 endif
8588
8589endfun
8590
8591" ---------------------------------------------------------------------
8592" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8593" Used by the O maps (as <SID>NetrwObtain())
8594fun! s:NetrwObtain(islocal)
8595" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8596
Bram Moolenaar97d62492012-11-15 21:28:22 +01008597 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008598 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008599 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008600 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8602 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008603 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008604 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008605 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008606
8607" call Dret("NetrwObtain")
8608endfun
8609
8610" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008611" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8612" If there's only one window, then the window will first be split.
8613" Returns:
8614" choice = 0 : didn't have to choose
8615" choice = 1 : saved modified file in window first
8616" choice = 2 : didn't save modified file, opened window
8617" choice = 3 : cancel open
8618fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008619" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008620
Bram Moolenaar97d62492012-11-15 21:28:22 +01008621 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008622 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008623 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008624" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008625
8626 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008627 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008628 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008629" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8630" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8631 let curword = s:NetrwGetWord()
8632 let choice = 0
8633 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8634" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008635 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008636" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008637 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008638" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008639" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008640" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008641
Bram Moolenaar8d043172014-01-23 14:24:41 +01008642 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643 if lastwinnr == 1
8644 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008645" 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 +02008646 " g:netrw_preview=0: preview window shown in a horizontally split window
8647 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008648 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008649 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008650 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008651" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008652 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008653 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008654 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008655 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008656" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008657 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008658 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008659 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008660" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008661
8662 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008663" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008664 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008665" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008666 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008667" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008668 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008669" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008670 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008671" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008672" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008673" call Decho("COMBAK#12: mod=".&mod)
8674
8675 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8676 " whoops -- user trying to open file in the Lexplore window.
8677 " Use Lexplore's opening-file window instead.
8678" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8679" exe g:netrw_chgwin."wincmd w"
8680 wincmd p
8681 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8682 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008683
8684 " prevwinnr: the window number of the "prev" window
8685 " prevbufnr: the buffer number of the buffer in the "prev" window
8686 " bnrcnt : the qty of windows open on the "prev" buffer
8687 let prevwinnr = winnr()
8688 let prevbufnr = bufnr("%")
8689 let prevbufname = bufname("%")
8690 let prevmod = &mod
8691 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008692" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008693 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008694" 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 +01008695" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008696
8697 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008698 " and it doesn't appear in any other extant window, then ask the
8699 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008700 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008701" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008702 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008703" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008704 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008705" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008706
8707 if bnrcnt == 1 && &hidden == 0
8708 " only one copy of the modified buffer in a window, and
8709 " hidden not set, so overwriting will lose the modified file. Ask first...
8710 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008711" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008712 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008713" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008714
8715 if choice == 1
8716 " Yes -- write file & then browse
8717 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008718 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008719 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008720 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008721 exe origwin."wincmd w"
8722 let &ei = eikeep
8723 let @@ = ykeep
8724" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008725 return choice
8726 endif
8727
8728 elseif choice == 2
8729 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008730" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008731 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008732
8733 else
8734 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008735" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008736 exe origwin."wincmd w"
8737 let &ei= eikeep
8738 let @@ = ykeep
8739" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008740 return choice
8741 endif
8742 endif
8743 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008744 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008745 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008746" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008747
8748 " restore b:netrw_curdir (window split/enew may have lost it)
8749 let b:netrw_curdir= curdir
8750 if a:islocal < 2
8751 if a:islocal
8752 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8753 else
8754 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8755 endif
8756 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008757 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008758" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008759 return choice
8760endfun
8761
8762" ---------------------------------------------------------------------
8763" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8764" Always assumed to be local -> remote
8765" call s:NetrwUpload(filename, target)
8766" call s:NetrwUpload(filename, target, fromdirectory)
8767fun! s:NetrwUpload(fname,tgt,...)
8768" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8769
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008770 if a:tgt =~ '^\a\{3,}://'
8771 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008772 else
8773 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8774 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008775" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008776
8777 if a:0 > 0
8778 let fromdir= a:1
8779 else
8780 let fromdir= getcwd()
8781 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008782" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008783
8784 if type(a:fname) == 1
8785 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008786" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008787 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008788" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8789 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8790" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008791 if a:tgt =~ '/$'
8792 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008793" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008794 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008795 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008796" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008797 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008798" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008799 endif
8800 q!
8801
8802 elseif type(a:fname) == 3
8803 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008804" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008805 let curdir= getcwd()
8806 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008807 if s:NetrwLcd(fromdir)
8808" call Dret("s:NetrwUpload : lcd failure")
8809 return
8810 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008811 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008812 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008813 if exists("g:netrw_port") && g:netrw_port != ""
8814 let useport= " ".g:netrw_scpport." ".g:netrw_port
8815 else
8816 let useport= ""
8817 endif
8818 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8819 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008820 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 +02008821 if s:NetrwLcd(curdir)
8822" call Dret("s:NetrwUpload : lcd failure")
8823 return
8824 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008825
8826 elseif a:tgt =~ '^ftp:'
8827 call s:NetrwMethod(a:tgt)
8828
8829 if b:netrw_method == 2
8830 " handle uploading a list of files via ftp+.netrc
8831 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008832 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008833" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008834
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008835 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008836" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008837
8838 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008839 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008840" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008841 endif
8842
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008843 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008844" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008845
Bram Moolenaaradc21822011-04-01 18:03:16 +02008846 if tgtdir == ""
8847 let tgtdir= '/'
8848 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008849 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008850" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008851
8852 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008853 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8854" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008855 endfor
8856
8857 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008858 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 +00008859 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008860" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8861 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008862 endif
8863 " 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 +01008864 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008865 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008866 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8867 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8868 else
8869 bw!|q
8870 endif
8871
8872 elseif b:netrw_method == 3
8873 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8874 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008875 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008876 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008877 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008878
8879 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008880 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008881" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008882 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008883 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008884" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008885 endif
8886
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008887 if exists("g:netrw_uid") && g:netrw_uid != ""
8888 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008889 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008890" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008891 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008892 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008893 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008894" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008895 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008896 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008897" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008898 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008899 endif
8900
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008901 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008902" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008903
8904 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008905 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008906" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008907 endif
8908
8909 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008910 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008911" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008912 endif
8913
8914 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008915 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008916" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008917 endfor
8918
8919 " perform ftp:
8920 " -i : turns off interactive prompting from ftp
8921 " -n unix : DON'T use <.netrc>, even though it exists
8922 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008923 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008924 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008925 " 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 +01008926 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008927 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008928 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8929 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008930 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008931 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8932 let &debug = debugkeep
8933 let mod = 1
8934 else
8935 bw!|q
8936 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008937 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008938" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008939 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008940 endif
8941 else
8942 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8943 endif
8944 endif
8945
8946" call Dret("s:NetrwUpload")
8947endfun
8948
8949" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008950" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008951fun! s:NetrwPreview(path) range
8952" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008953" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8954" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008955 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008956 NetrwKeepj call s:NetrwOptionsSave("s:")
8957 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8958 NetrwKeepj call s:NetrwOptionsSafe(1)
8959 else
8960 NetrwKeepj call s:NetrwOptionsSafe(0)
8961 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008962 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008963" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008964 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008965" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8966 if g:netrw_preview
8967 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008968 let pvhkeep = &pvh
8969 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8970 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008971" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8972 else
8973 " horizontal split
8974 let pvhkeep = &pvh
8975 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8976 let &pvh = winheight(0) - winsz
8977" 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 +02008978 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008979 " g:netrw_preview g:netrw_alto
8980 " 1 : vert 1: top -- preview window is vertically split off and on the left
8981 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8982 " 0 : 1: top -- preview window is horizontally split off and on the top
8983 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8984 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008985 " 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 +02008986 " the BufEnter event set up in netrwPlugin.vim
8987" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8988 let eikeep = &ei
8989 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008990 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008991 let &ei= eikeep
8992" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008993 if exists("pvhkeep")
8994 let &pvh= pvhkeep
8995 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008996 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008997 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008998 endif
8999 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009000 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 +00009001 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009002 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009003 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009004" call Dret("NetrwPreview")
9005endfun
9006
9007" ---------------------------------------------------------------------
9008" s:NetrwRefresh: {{{2
9009fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009010" 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 +00009011 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009012 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009013" call Decho("setl ma noro",'~'.expand("<slnum>"))
9014" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009015 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009016 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9017 if !exists("w:netrw_treetop")
9018 if exists("b:netrw_curdir")
9019 let w:netrw_treetop= b:netrw_curdir
9020 else
9021 let w:netrw_treetop= getcwd()
9022 endif
9023 endif
9024 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9025 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009026
9027 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009028 let screenposn = winsaveview()
9029" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009030
9031" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9032" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9033 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009034 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009035 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009036 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009037 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009038 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009039
9040 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009041" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9042 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009043
9044 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009045 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9046 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9047" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9048 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9049 else
9050" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9051 2match none
9052 endif
9053 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054
Bram Moolenaar97d62492012-11-15 21:28:22 +01009055" restore
9056 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009057" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009058endfun
9059
9060" ---------------------------------------------------------------------
9061" s:NetrwRefreshDir: refreshes a directory by name {{{2
9062" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009063" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009064fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009065" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009066 if g:netrw_fastbrowse == 0
9067 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009068" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009069 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009070" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009071
9072 if tgtwin > 0
9073 " tgtwin is being displayed, so refresh it
9074 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009075" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009076 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009077 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009078 exe curwin."wincmd w"
9079
9080 elseif bufnr(a:dirname) > 0
9081 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009082" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9083 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009084 endif
9085
9086 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009087" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009088 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009089 endif
9090" call Dret("s:NetrwRefreshDir")
9091endfun
9092
9093" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009094" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9095" window number to do its editing in.
9096" Supports [count]C where the count, if present, is used to specify
9097" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009098fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009099" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009100 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009101" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009102 if a:1 == "" " :NetrwC win#
9103 let g:netrw_chgwin= winnr()
9104 else " :NetrwC
9105 let g:netrw_chgwin= a:1
9106 endif
9107 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009108 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009109 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009110 let g:netrw_chgwin= winnr()
9111 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009112 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009113" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009114endfun
9115
9116" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009117" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9118" What this function does is to compute a priority for the patterns
9119" in the g:netrw_sort_sequence. It applies a substitute to any
9120" "files" that satisfy each pattern, putting the priority / in
9121" front. An "*" pattern handles the default priority.
9122fun! s:NetrwSetSort()
9123" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009124 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009125 if w:netrw_liststyle == s:LONGLIST
9126 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9127 else
9128 let seqlist = g:netrw_sort_sequence
9129 endif
9130 " sanity check -- insure that * appears somewhere
9131 if seqlist == ""
9132 let seqlist= '*'
9133 elseif seqlist !~ '\*'
9134 let seqlist= seqlist.',*'
9135 endif
9136 let priority = 1
9137 while seqlist != ""
9138 if seqlist =~ ','
9139 let seq = substitute(seqlist,',.*$','','e')
9140 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9141 else
9142 let seq = seqlist
9143 let seqlist = ""
9144 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009145 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009146 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009147 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009148 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009149 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009150 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009151 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009152" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009153
9154 " sanity check
9155 if w:netrw_bannercnt > line("$")
9156 " apparently no files were left after a Hiding pattern was used
9157" call Dret("SetSort : no files left after hiding")
9158 return
9159 endif
9160 if seq == '*'
9161 let starpriority= spriority
9162 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009163 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009164 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165 " sometimes multiple sorting patterns will match the same file or directory.
9166 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009167 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9168 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009169 endif
9170 let priority = priority + 1
9171 endwhile
9172 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009173 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9174 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009175 endif
9176
9177 " Following line associated with priority -- items that satisfy a priority
9178 " pattern get prefixed by ###/ which permits easy sorting by priority.
9179 " Sometimes files can satisfy multiple priority patterns -- only the latest
9180 " priority pattern needs to be retained. So, at this point, these excess
9181 " priority prefixes need to be removed, but not directories that happen to
9182 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009183 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9184 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009185 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009186
9187" call Dret("SetSort")
9188endfun
9189
Bram Moolenaarff034192013-04-24 18:51:19 +02009190" ---------------------------------------------------------------------
9191" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9192" Implements [count]Tb (bookhist<b>)
9193" [count]Th (bookhist<h>)
9194" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009195fun! s:NetrwSetTgt(islocal,bookhist,choice)
9196" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009197
9198 if a:bookhist == 'b'
9199 " supports choosing a bookmark as a target using a qb-generated list
9200 let choice= a:choice - 1
9201 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009202 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009203 else
9204 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9205 endif
9206
9207 elseif a:bookhist == 'h'
9208 " supports choosing a history stack entry as a target using a qb-generated list
9209 let choice= (a:choice % g:netrw_dirhistmax) + 1
9210 if exists("g:netrw_dirhist_".choice)
9211 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009212 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009213 else
9214 echomsg "Sorry, history#".a:choice." not available!"
9215 endif
9216 endif
9217
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009218 " refresh the display
9219 if !exists("b:netrw_curdir")
9220 let b:netrw_curdir= getcwd()
9221 endif
9222 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9223
Bram Moolenaarff034192013-04-24 18:51:19 +02009224" call Dret("s:NetrwSetTgt")
9225endfun
9226
Bram Moolenaar446cb832008-06-24 21:56:24 +00009227" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009228" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009229fun! s:NetrwSortStyle(islocal)
9230" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009231 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009232 let svpos= winsaveview()
9233" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009234
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009235 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 +01009236 NetrwKeepj norm! 0
9237 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009238" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9239 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009240
9241" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9242endfun
9243
9244" ---------------------------------------------------------------------
9245" s:NetrwSplit: mode {{{2
9246" =0 : net and o
9247" =1 : net and t
9248" =2 : net and v
9249" =3 : local and o
9250" =4 : local and t
9251" =5 : local and v
9252fun! s:NetrwSplit(mode)
9253" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9254
Bram Moolenaar97d62492012-11-15 21:28:22 +01009255 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009256 call s:SaveWinVars()
9257
9258 if a:mode == 0
9259 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009260 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(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_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009263 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
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 == 1
9270 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009271 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009272" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009273 tabnew
9274 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009275 NetrwKeepj call s:RestoreWinVars()
9276 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009277 unlet s:didsplit
9278
9279 elseif a:mode == 2
9280 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009281 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009282 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009283" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009284 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009285 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009286 NetrwKeepj call s:RestoreWinVars()
9287 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009288 unlet s:didsplit
9289
9290 elseif a:mode == 3
9291 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009292 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009293 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009294" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009295 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009296 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009297 NetrwKeepj call s:RestoreWinVars()
9298 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009299 unlet s:didsplit
9300
9301 elseif a:mode == 4
9302 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009303 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009304 let eikeep = &ei
9305 let netrw_winnr = winnr()
9306 let netrw_line = line(".")
9307 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009308 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009309 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009310 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009311 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9312 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009313 let &ei = eikeep
9314 let netrw_curdir = s:NetrwTreeDir(0)
9315" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009316 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009317 let b:netrw_curdir = netrw_curdir
9318 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009319 NetrwKeepj call s:RestoreWinVars()
9320 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009321 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009322 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009323 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9324 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009325 let &ei= eikeep
9326 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009327 unlet s:didsplit
9328
9329 elseif a:mode == 5
9330 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009331 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009332 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009333" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009334 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009335 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009336 NetrwKeepj call s:RestoreWinVars()
9337 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009338 unlet s:didsplit
9339
9340 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009341 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009342 endif
9343
Bram Moolenaar97d62492012-11-15 21:28:22 +01009344 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009345" call Dret("s:NetrwSplit")
9346endfun
9347
9348" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009349" s:NetrwTgtMenu: {{{2
9350fun! s:NetrwTgtMenu()
9351 if !exists("s:netrw_menucnt")
9352 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009353 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009354" call Dfunc("s:NetrwTgtMenu()")
9355
9356 " the following test assures that gvim is running, has menus available, and has menus enabled.
9357 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9358 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009359" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009360 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9361 endif
9362 if !exists("s:netrw_initbookhist")
9363 call s:NetrwBookHistRead()
9364 endif
9365
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009366 " try to cull duplicate entries
9367 let tgtdict={}
9368
Bram Moolenaarff034192013-04-24 18:51:19 +02009369 " target bookmarked places
9370 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009371" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009372 let cnt= 1
9373 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009374 if has_key(tgtdict,bmd)
9375 let cnt= cnt + 1
9376 continue
9377 endif
9378 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009379 let ebmd= escape(bmd,g:netrw_menu_escape)
9380 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009381" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009382 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 +02009383 let cnt= cnt + 1
9384 endfor
9385 endif
9386
9387 " target directory browsing history
9388 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009389" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009390 let histcnt = 1
9391 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009392 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009393 if exists("g:netrw_dirhist_{histcnt}")
9394 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009395 if has_key(tgtdict,histentry)
9396 let histcnt = histcnt + 1
9397 continue
9398 endif
9399 let tgtdict[histentry] = histcnt
9400 let ehistentry = escape(histentry,g:netrw_menu_escape)
9401" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009402 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 +02009403 endif
9404 let histcnt = histcnt + 1
9405 endwhile
9406 endif
9407 endif
9408" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009409endfun
9410
9411" ---------------------------------------------------------------------
9412" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9413" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009414fun! s:NetrwTreeDir(islocal)
9415" 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 +02009416" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009417" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9418" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9419" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009420" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009421
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009422 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009423 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009424" 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 +01009425 let treedir= s:treedir
9426 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009427 unlet s:prevwinopen
9428" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009429 return treedir
9430 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009431 if exists("s:prevwinopen")
9432 unlet s:prevwinopen
9433 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009434" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009435
Bram Moolenaar8d043172014-01-23 14:24:41 +01009436 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9437 let b:netrw_curdir= getcwd()
9438 endif
9439 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009440" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009441" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009442
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009443 let s:treecurpos= winsaveview()
9444" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009445" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009446
9447 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009448" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9449" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009450" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009451
9452 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009453 let curline= substitute(getline('.'),"\t -->.*$",'','')
9454 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009455" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009456 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009457" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9458 elseif curline =~ '@$'
9459" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009460 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009461" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009462 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009463" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009464 let treedir= ""
9465 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009466" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009467
9468 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009469" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9470" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009471" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009472 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009473" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009474 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009475" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9476 sil! NetrwKeepj %d _
9477" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009478 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009479" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009480" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009481 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009482" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009483
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009484" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009485" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009486" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009487
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009488 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9489" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9490" let newdir = w:netrw_treetop.'/'.potentialdir
9491" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9492" let treedir = s:NetrwTreePath(newdir)
9493" let w:netrw_treetop = newdir
9494" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9495" else
9496" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009497 if a:islocal && curline =~ '@$'
9498 if isdirectory(s:NetrwFile(potentialdir))
9499 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9500 let w:netrw_treetop = treedir
9501 endif
9502 else
9503 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9504 let treedir = s:NetrwTreePath(w:netrw_treetop)
9505 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009506 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009507" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009508
9509 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009510 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009511" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009512" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009513
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009514" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009515 return treedir
9516endfun
9517
9518" ---------------------------------------------------------------------
9519" s:NetrwTreeDisplay: recursive tree display {{{2
9520fun! s:NetrwTreeDisplay(dir,depth)
9521" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9522
9523 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009524 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009525
9526 " install ../ and shortdir
9527 if a:depth == ""
9528 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009529" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009530 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009531 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009532 if a:dir == w:netrw_treetop
9533 let shortdir= a:dir
9534 else
9535 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9536 endif
9537 call setline(line("$")+1,a:depth.shortdir)
9538 else
9539 let shortdir= substitute(a:dir,'^.*/','','e')
9540 call setline(line("$")+1,a:depth.shortdir.'/')
9541 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009542" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009543 " append a / to dir if its missing one
9544 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009545
9546 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009547 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009548" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009549
Bram Moolenaar85850f32019-07-19 22:05:51 +02009550 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9551 if g:netrw_hide == 1
9552 " hide given patterns
9553 let listhide= split(g:netrw_list_hide,',')
9554" call Decho("listhide=".string(listhide))
9555 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009556 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009557 endfor
9558
9559 elseif g:netrw_hide == 2
9560 " show given patterns (only)
9561 let listhide= split(g:netrw_list_hide,',')
9562" call Decho("listhide=".string(listhide))
9563 let entries=[]
9564 for entry in w:netrw_treedict[dir]
9565 for pat in listhide
9566 if entry =~ pat
9567 call add(entries,entry)
9568 break
9569 endif
9570 endfor
9571 endfor
9572 let w:netrw_treedict[dir]= entries
9573 endif
9574 if depth != ""
9575 " always remove "." and ".." entries when there's depth
9576 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9577 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9578 endif
9579
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009580" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009581 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009582 if dir =~ '/$'
9583 let direntry= substitute(dir.entry,'[@/]$','','e')
9584 else
9585 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9586 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009587" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009588 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009589" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009590 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009591 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009592" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9593 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9594 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9595" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009596 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009597 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009598" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009599 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009600 endif
9601 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009602" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009603
Bram Moolenaar446cb832008-06-24 21:56:24 +00009604" call Dret("NetrwTreeDisplay")
9605endfun
9606
9607" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009608" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9609fun! s:NetrwRefreshTreeDict(dir)
9610" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009611 if !exists("w:netrw_treedict")
9612" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9613 return
9614 endif
9615
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009616 for entry in w:netrw_treedict[a:dir]
9617 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9618" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9619
9620 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9621" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9622 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009623 let liststar = s:NetrwGlob(direntry,'*',1)
9624 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009625 let w:netrw_treedict[direntry] = liststar + listdotstar
9626" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9627
9628 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9629" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9630 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009631 let liststar = s:NetrwGlob(direntry.'/','*',1)
9632 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009633 let w:netrw_treedict[direntry]= liststar + listdotstar
9634" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9635
9636 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9637" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9638 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009639 let liststar = s:NetrwGlob(direntry.'/','*',1)
9640 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009641" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9642
9643 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009644" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009645 endif
9646 endfor
9647" call Dret("s:NetrwRefreshTreeDict")
9648endfun
9649
9650" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009651" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009652" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009653fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009654 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009655" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009656" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9657" 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>"))
9658" 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 +00009659
9660 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009661 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009662" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009663 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009664 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009665" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009666 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 +02009667" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009668 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009669 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009670" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009671 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009672 if exists("w:netrw_treetop")
9673 let s:netrw_treetop= w:netrw_treetop
9674 else
9675 let w:netrw_treetop= getcwd()
9676 let s:netrw_treetop= w:netrw_treetop
9677 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009678
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009680 " insure that we have a treedict, albeit empty
9681" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009682 let w:netrw_treedict= {}
9683 endif
9684
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009685 " update the dictionary for the current directory
9686" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009687" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009688 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009689 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009690" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009691 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009692
9693 " if past banner, record word
9694 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9695 let fname= expand("<cword>")
9696 else
9697 let fname= ""
9698 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009699" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9700" 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 +00009701
9702 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009703" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009704 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009705" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009706
9707 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9708 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009709" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009710 1d
9711 endwhile
9712
Bram Moolenaar13600302014-05-22 18:26:40 +02009713 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009714
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009715" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009716 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009717 endif
9718endfun
9719
9720" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009721" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009722" Normally, treetop is w:netrw_treetop, but a
9723" user of the function ( netrw#SetTreetop() )
9724" wipes that out prior to calling this function
9725fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009726" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9727 if line(".") < w:netrw_bannercnt + 2
9728 let treedir= a:treetop
9729 if treedir !~ '/$'
9730 let treedir= treedir.'/'
9731 endif
9732" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9733 return treedir
9734 endif
9735
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009736 let svpos = winsaveview()
9737" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009738 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009739" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009740 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009741" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9742 let curline= getline('.')
9743" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9744 if curline =~ '/$'
9745" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9746 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9747" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9748 elseif curline =~ '@\s\+-->'
9749" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9750 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9751 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9752" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009753 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009754" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009755 let treedir= ""
9756 endif
9757 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009758" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9759" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009760 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9761 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9762 let treedir= dirname.treedir
9763 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009764" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009765 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009766" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009767 if a:treetop =~ '/$'
9768 let treedir= a:treetop.treedir
9769 else
9770 let treedir= a:treetop.'/'.treedir
9771 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009772" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009773 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009774" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009775" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9776 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009777" call Dret("s:NetrwTreePath <".treedir.">")
9778 return treedir
9779endfun
9780
9781" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009782" s:NetrwWideListing: {{{2
9783fun! s:NetrwWideListing()
9784
9785 if w:netrw_liststyle == s:WIDELIST
9786" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9787 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009788 " cpf: characters per filename
9789 " fpl: filenames per line
9790 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009791 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009792 let dict={}
9793 " save the unnamed register and register 0-9 and a
9794 let dict.a=[getreg('a'), getregtype('a')]
9795 for i in range(0, 9)
9796 let dict[i] = [getreg(i), getregtype(i)]
9797 endfor
9798 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009799" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009800 let b:netrw_cpf= 0
9801 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009802 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009803 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9804 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009805 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009806 " restore stored registers
9807 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009808" call Dret("NetrwWideListing")
9809 return
9810 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009811 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009812 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009813" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009814
9815 " determine qty files per line (fpl)
9816 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9817 if w:netrw_fpl <= 0
9818 let w:netrw_fpl= 1
9819 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009820" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009821
9822 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009823 " fpc: files per column of wide listing
9824 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009825 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009826 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9827 let newcolstart = w:netrw_bannercnt + fpc
9828 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009829" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009830 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009831" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009832 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009833 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009834 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009835 while line("$") >= newcolstart
9836 if newcolend > line("$") | let newcolend= line("$") | endif
9837 let newcolqty= newcolend - newcolstart
9838 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009839 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009840 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009841 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009842 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009843 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009844 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009845 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009846 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009847 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009848 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009849" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009850 if @* != keepregstar | sil! let @* = keepregstar | endif
9851 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009852 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009853 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9854 NetrwKeepj call histdel("/",-1)
9855 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9856 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009857" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009858 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009859 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009860" 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 +00009861" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009862 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009863 else
9864 if hasmapto("w","n")
9865 sil! nunmap <buffer> w
9866 endif
9867 if hasmapto("b","n")
9868 sil! nunmap <buffer> b
9869 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009870 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009871endfun
9872
9873" ---------------------------------------------------------------------
9874" s:PerformListing: {{{2
9875fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009876" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9877" 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 +02009878" 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>"))
9879 sil! NetrwKeepj %d _
9880" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009881
Bram Moolenaar15146672011-10-20 22:22:38 +02009882 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009883" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009884 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009885
Bram Moolenaar85850f32019-07-19 22:05:51 +02009886 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009887 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009888" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009889
9890" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009891" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009892" endif " Decho
9893
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009894" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009895 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9896 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009897" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9898 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009899 endif
9900
9901 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009902 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009903
9904 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009905 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009906" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009907 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009908 if exists("g:netrw_pchk")
9909 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9910 " failure detections.
9911 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009912 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009913 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9914 endif
9915 if exists("g:netrw_pchk")
9916 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9917 else
9918 let curdir= b:netrw_curdir
9919 endif
9920 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9921 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9922 else
9923 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009924 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009925 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009926 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009927 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009928" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009929 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009930 let w:netrw_bannercnt= 1
9931 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009932" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9933" 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 +00009934
Bram Moolenaar85850f32019-07-19 22:05:51 +02009935 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009936 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009937 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009938 let sortby= sortby." reversed"
9939 endif
9940
9941 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009942 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009943" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009944 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009945" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009946 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009947 NetrwKeepj put ='\" Sorted by '.sortby
9948 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009949 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9950 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009951" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009952 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009953 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009954 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9955 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009956 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009957" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009958" 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 +00009959 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009960
Bram Moolenaar85850f32019-07-19 22:05:51 +02009961 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009962 if g:netrw_banner
9963 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009964" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009965 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009966 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009967 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009968 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009969 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009970 endif
9971 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009972 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009973" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009974 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009975 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009976 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009977
9978 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009979 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009980" 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 +01009981 if g:netrw_list_hide != "" && g:netrw_hide
9982 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009983 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009984 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009985 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009986 endif
9987 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009988 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009989 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009990
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009991" 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 +01009992 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009993" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009994 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009995" 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 +01009996 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009997 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009998" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009999" 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 +000010000 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010001
10002 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +010010003 if g:netrw_banner
10004 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010005 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010006" 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 +010010007" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010008" 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 +010010009 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010010
Bram Moolenaar446cb832008-06-24 21:56:24 +000010011 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010012" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010013 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010014 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010015 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010016 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010017 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010018" 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 +010010019" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10020 return
10021 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010022 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010023
10024 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010025 if !exists("w:netrw_bannercnt")
10026 let w:netrw_bannercnt= 0
10027 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010028" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10029" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10030" 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 +010010031
Bram Moolenaar5c736222010-01-06 20:54:52 +010010032 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010033" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010034" 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 +000010035 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010036 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010037 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010038 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010039" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010040
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010041 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010042 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010043" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010044 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010045
Bram Moolenaar5c736222010-01-06 20:54:52 +010010046 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010047" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010048 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010049 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010050 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010051 else
10052 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010053 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010054 endif
10055 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010056
Bram Moolenaar446cb832008-06-24 21:56:24 +000010057 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010058" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010059 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10060 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010061
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010062 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010063 " exten: sort by extension
10064 " The histdel(...,-1) calls remove the last search from the search history
10065" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010066 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10067 NetrwKeepj call histdel("/",-1)
10068 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10069 NetrwKeepj call histdel("/",-1)
10070 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10071 NetrwKeepj call histdel("/",-1)
10072 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10073" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010074 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010075 " normal direction sorting
10076 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10077 else
10078 " reverse direction sorting
10079 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10080 endif
10081 endif
10082 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10083 NetrwKeepj call histdel("/",-1)
10084
Bram Moolenaar446cb832008-06-24 21:56:24 +000010085 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010086 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010087" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010088 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010089" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010090 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010091 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010092" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010093 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010094 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010095" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010096 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10097 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010098 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010099 endif
10100
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010101 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010102" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010103 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010104 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010105 call histdel("/",-1)
10106 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010107 endif
10108 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010109" 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 +000010110
10111 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010112" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10113" 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 +010010114 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010115" 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 +010010116 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010117" 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 +000010118
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010119 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010120 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010121" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010122 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010123 endif
10124
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010125 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010126 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010127" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10128 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010129 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010130" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10131 else
10132" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10133" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10134" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10135" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010136 endif
10137
10138 " record previous current directory
10139 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010140" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010141
10142 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010143" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10144" 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 +010010145 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010146" 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 +020010147 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010148" 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 +000010149
10150 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010151" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010152 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010153" 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 +010010154 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010155" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010156 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10157 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010158" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010159" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010160
Bram Moolenaar8d043172014-01-23 14:24:41 +010010161 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010162" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10163" 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 +010010164" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10165 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010166 unlet s:treecurpos
10167 endif
10168
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010169" 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>"))
10170" 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 +000010171" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10172endfun
10173
10174" ---------------------------------------------------------------------
10175" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010176fun! s:SetupNetrwStatusLine(statline)
10177" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10178
10179 if !exists("s:netrw_setup_statline")
10180 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010181" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010182
10183 if !exists("s:netrw_users_stl")
10184 let s:netrw_users_stl= &stl
10185 endif
10186 if !exists("s:netrw_users_ls")
10187 let s:netrw_users_ls= &laststatus
10188 endif
10189
10190 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010191 let dict={}
10192 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010193 redir @a
10194 try
10195 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010196 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010197 if &bg == "dark"
10198 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10199 else
10200 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10201 endif
10202 endtry
10203 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010204 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010205 endif
10206
10207 " set up status line (may use User9 highlighting)
10208 " insure that windows have a statusline
10209 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010210 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010211 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010212" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010213 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010214
10215" call Dret("SetupNetrwStatusLine : stl=".&stl)
10216endfun
10217
Bram Moolenaar85850f32019-07-19 22:05:51 +020010218" =========================================
10219" Remote Directory Browsing Support: {{{1
10220" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010221
10222" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010223" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10224" This function assumes that a long listing will be received. Size, time,
10225" and reverse sorts will be requested of the server but not otherwise
10226" enforced here.
10227fun! s:NetrwRemoteFtpCmd(path,listcmd)
10228" 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 +010010229" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010230 " sanity check: {{{3
10231 if !exists("w:netrw_method")
10232 if exists("b:netrw_method")
10233 let w:netrw_method= b:netrw_method
10234 else
10235 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10236" call Dret("NetrwRemoteFtpCmd")
10237 return
10238 endif
10239 endif
10240
10241 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10242 let ffkeep= &ff
10243 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010244" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010245
10246 " clear off any older non-banner lines " {{{3
10247 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010248" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10249 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010250
10251 ".........................................
10252 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10253 " ftp + <.netrc>: Method #2
10254 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010255 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010256 endif
10257 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010258 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010259" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010260 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010261 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010262" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010263 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010264" 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>"))
10265 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 +010010266 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010267" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10268 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 +010010269 endif
10270
10271 ".........................................
10272 elseif w:netrw_method == 3 " {{{3
10273 " ftp + machine,id,passwd,filename: Method #3
10274 setl ff=unix
10275 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010276 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010277 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010278 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010279 endif
10280
10281 " handle userid and password
10282 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010283" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010284 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10285 call NetUserPass("ftp:".host)
10286 endif
10287 if exists("g:netrw_uid") && g:netrw_uid != ""
10288 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010289 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010290 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010291 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010292 endif
10293 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010294 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010295 endif
10296 endif
10297
10298 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010299 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010300 endif
10301 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010302 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010303" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010304 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010305 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010306
10307 " perform ftp:
10308 " -i : turns off interactive prompting from ftp
10309 " -n unix : DON'T use <.netrc>, even though it exists
10310 " -n win32: quit being obnoxious about password
10311 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010312" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010313 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010314" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010315" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10316" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010317 endif
10318
10319 ".........................................
10320 elseif w:netrw_method == 9 " {{{3
10321 " sftp username@machine: Method #9
10322 " s:netrw_sftp_cmd
10323 setl ff=unix
10324
10325 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010326 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010327" call Dret("NetrwRemoteFtpCmd")
10328 return
10329
10330 ".........................................
10331 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010332 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010333 endif
10334
10335 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010336 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010337 sil! NetrwKeepj %s/\r$//e
10338 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010339 endif
10340 if a:listcmd == "dir"
10341 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010342 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10343 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10344 NetrwKeepj call histdel("/",-1)
10345 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010346 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 +010010347 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10348 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010349 endif
10350 endif
10351
10352 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10353 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010354 exe 'NetrwKeepj '.w:netrw_bannercnt
10355 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010356 endif
10357 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010358 exe 'NetrwKeepj '.w:netrw_bannercnt
10359 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010360 endif
10361
10362 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010363 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010364" call Dret("NetrwRemoteFtpCmd")
10365endfun
10366
10367" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010368" s:NetrwRemoteListing: {{{2
10369fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010370" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010371
Bram Moolenaara6878372014-03-22 21:02:50 +010010372 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10373 let w:netrw_bannercnt= s:bannercnt
10374 endif
10375 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010376 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010377 endif
10378
Bram Moolenaar446cb832008-06-24 21:56:24 +000010379 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010380
Bram Moolenaar446cb832008-06-24 21:56:24 +000010381 " sanity check:
10382 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010383" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010384 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010385" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010386 if !exists("g:netrw_quiet")
10387 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10388 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010389 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010390" call Dret("s:NetrwRemoteListing -1")
10391 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010392 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010393
Bram Moolenaar8d043172014-01-23 14:24:41 +010010394 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010395" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010396 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010397 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010398 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 +000010399 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010400 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 +000010401 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010402 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010403
Bram Moolenaar85850f32019-07-19 22:05:51 +020010404 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010405" call Dret("s:NetrwRemoteListing -1")
10406 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010407 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010408" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010409
Bram Moolenaar446cb832008-06-24 21:56:24 +000010410 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010411" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010412 let w:netrw_method= b:netrw_method
10413 endif
10414
Bram Moolenaar13600302014-05-22 18:26:40 +020010415 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010416 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010417" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010418 let s:method = "ftp"
10419 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010420 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010421 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010422 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010423 let listcmd= g:netrw_ftp_sizelist_cmd
10424 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010425" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010426 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010427" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010428
Bram Moolenaara6878372014-03-22 21:02:50 +010010429 " report on missing file or directory messages
10430 if search('[Nn]o such file or directory\|Failed to change directory')
10431 let mesg= getline(".")
10432 if exists("w:netrw_bannercnt")
10433 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010434 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010435 setl noma
10436 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010437 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010438 call netrw#ErrorMsg(s:WARNING,mesg,96)
10439" call Dret("s:NetrwRemoteListing : -1")
10440 return -1
10441 endif
10442
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010443 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 +000010444 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010445" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010446 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447
10448 " cleanup
10449 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010450 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10451 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010452 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010453 sil! NetrwKeepj %s/\r$//e
10454 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010455
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010456 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010457 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010458 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010459 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010460" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010461 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010462" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010463 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010464 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010465 exe "sil! NetrwKeepj ".line1
10466 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010467
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010468" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010469 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010470" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010471 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10472 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010473 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010474" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010475 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10476 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10477 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10478 NetrwKeepj call histdel("/",-1)
10479 NetrwKeepj call histdel("/",-1)
10480 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010481 endif
10482 endif
10483
Bram Moolenaar13600302014-05-22 18:26:40 +020010484 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010485 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010486" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010487 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010488" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010490" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10491 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010492 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010493 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10494 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10495 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10496 NetrwKeepj call histdel("/",-1)
10497 NetrwKeepj call histdel("/",-1)
10498 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010499 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010500 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10501 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010502 endif
10503 else
10504 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010505" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010506 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010507 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010508" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10509 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10510" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010511 endif
10512 endif
10513
10514 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010515 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010516" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010517 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10518 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010519 endif
10520 endif
10521
10522 if w:netrw_liststyle == s:LONGLIST
10523 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010524" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010525
10526 if s:method == "ftp"
10527 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010528 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010529 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010530 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010532 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010533 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010534 sil! NetrwKeepj 1
10535 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010536 let line2= line(".")
10537 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010538 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010539 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010540 endif
10541 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010542 exe "sil! NetrwKeepj ".line1
10543 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010544 endif
10545
10546 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010547" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010548 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 +000010549 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010550" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010551 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010552 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010553 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10554 NetrwKeepj call histdel("/",-1)
10555 NetrwKeepj call histdel("/",-1)
10556 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010557 endif
10558 endif
10559
10560" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010561" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010562" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010563
10564" call Dret("s:NetrwRemoteListing 0")
10565 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010566endfun
10567
Bram Moolenaar446cb832008-06-24 21:56:24 +000010568" ---------------------------------------------------------------------
10569" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10570fun! s:NetrwRemoteRm(usrhost,path) range
10571" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010572" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010573 let svpos= winsaveview()
10574" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575
10576 let all= 0
10577 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10578 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010579" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010580 for fname in s:netrwmarkfilelist_{bufnr("%")}
10581 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010582 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010583 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010584 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010585 let all= 1
10586 endif
10587 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010588 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010589
10590 else
10591 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010592" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010593
10594 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010595 let keepsol = &l:sol
10596 setl nosol
10597 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010598
10599 " remove multiple files and directories
10600 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010601 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010602 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010603 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010604 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010605 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010606 let all= 1
10607 endif
10608 let ctr= ctr + 1
10609 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010610 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010611 endif
10612
10613 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010614" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010615 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010616" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10617 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010618
10619" call Dret("s:NetrwRemoteRm")
10620endfun
10621
10622" ---------------------------------------------------------------------
10623" s:NetrwRemoteRmFile: {{{2
10624fun! s:NetrwRemoteRmFile(path,rmfile,all)
10625" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10626
10627 let all= a:all
10628 let ok = ""
10629
10630 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10631 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010632" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010633 if !all
10634 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010635" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010636 call inputsave()
10637 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10638 call inputrestore()
10639 echohl NONE
10640 if ok == ""
10641 let ok="no"
10642 endif
10643 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010644 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010645 let all= 1
10646 endif
10647 endif
10648
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010649 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010650" 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 +000010651 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010652" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010653 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010654 if path =~ '^\a\{3,}://'
10655 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010656 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010657 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010658 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10659 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010660" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010661 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010662" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010663 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010664 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010665 let ok="q"
10666 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010667 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10669" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10670" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010671 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010672 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010673 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010674 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010676" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010677 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010678 if v:shell_error != 0
10679 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010680 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 +010010681 else
10682 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10683 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010684 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010685 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010686 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010687" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010688 endif
10689 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010690 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010691" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010692 endif
10693
10694 else
10695 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010696" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010697 if !all
10698 call inputsave()
10699 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10700 call inputrestore()
10701 if ok == ""
10702 let ok="no"
10703 endif
10704 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010705 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010706 let all= 1
10707 endif
10708 endif
10709
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010710 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010711 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010712 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010713 else
10714 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010715 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10716" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010717 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010718" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010719
10720 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010721" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10722 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10723" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010724 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010725" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010726
10727 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010728 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010729 endif
10730 endif
10731 endif
10732
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010733 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010734" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010735 endif
10736 endif
10737
10738" call Dret("s:NetrwRemoteRmFile ".ok)
10739 return ok
10740endfun
10741
10742" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010743" s:NetrwRemoteRename: rename a remote file or directory {{{2
10744fun! s:NetrwRemoteRename(usrhost,path) range
10745" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10746
10747 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010748 let svpos = winsaveview()
10749" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010750 let ctr = a:firstline
10751 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10752
10753 " rename files given by the markfilelist
10754 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10755 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010756" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010757 if exists("subfrom")
10758 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010759" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010760 else
10761 call inputsave()
10762 let newname= input("Moving ".oldname." to : ",oldname)
10763 call inputrestore()
10764 if newname =~ '^s/'
10765 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10766 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10767 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010768" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010769 endif
10770 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010771
Bram Moolenaar446cb832008-06-24 21:56:24 +000010772 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010773 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010774 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010775 let oldname= s:ShellEscape(a:path.oldname)
10776 let newname= s:ShellEscape(a:path.newname)
10777" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010778 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010779 endif
10780
10781 endfor
10782 call s:NetrwUnMarkFile(1)
10783
10784 else
10785
10786 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010787 let keepsol= &l:sol
10788 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010789 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010790 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010791
10792 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010793" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010794
10795 call inputsave()
10796 let newname= input("Moving ".oldname." to : ",oldname)
10797 call inputrestore()
10798
10799 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10800 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10801 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010802 let oldname= s:ShellEscape(a:path.oldname)
10803 let newname= s:ShellEscape(a:path.newname)
10804" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010805 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010806 endif
10807
10808 let ctr= ctr + 1
10809 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010810 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010811 endif
10812
10813 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010814 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010815" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10816 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010817
10818" call Dret("NetrwRemoteRename")
10819endfun
10820
Bram Moolenaar85850f32019-07-19 22:05:51 +020010821" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010822" Local Directory Browsing Support: {{{1
10823" ==========================================
10824
10825" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010826" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010827" Should accept: file://localhost/etc/fstab
10828" file:///etc/fstab
10829" file:///c:/WINDOWS/clock.avi
10830" file:///c|/WINDOWS/clock.avi
10831" file://localhost/c:/WINDOWS/clock.avi
10832" file://localhost/c|/WINDOWS/clock.avi
10833" file://c:/foo.txt
10834" file:///c:/foo.txt
10835" 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 +020010836fun! netrw#FileUrlEdit(fname)
10837" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010838 let fname = a:fname
10839 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010840" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010841 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010842" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010843 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010844 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010845 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010846" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010847 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010848" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010849 endif
10850 endif
10851 let fname2396 = netrw#RFC2396(fname)
10852 let fname2396e= fnameescape(fname2396)
10853 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010854 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010855" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010856 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010857" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010858 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10859 endif
10860 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010861
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010862" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10863" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010864 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010865 exe 'NetrwKeepj keepalt edit '.plainfname
10866 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10867
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010868" 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 +020010869" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010870 exe "sil doau BufReadPost ".fname2396e
10871endfun
10872
10873" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010874" netrw#LocalBrowseCheck: {{{2
10875fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010876 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010877 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10878 "
10879 " unfortunate interaction -- split window debugging can't be used here, must use
10880 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10881 " another call to LocalBrowseCheck() when attempts to write
10882 " to the DBG buffer are made.
10883 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010884 " The &ft == "netrw" test was installed because the BufEnter event
10885 " would hit when re-entering netrw windows, creating unexpected
10886 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010887" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010888" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010889" 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 +010010890 " getting E930: Cannot use :redir inside execute
10891"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010892" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10893" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010894
Bram Moolenaar97d62492012-11-15 21:28:22 +010010895 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010896 if isdirectory(s:NetrwFile(a:dirname))
10897" 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 +010010898
Bram Moolenaar97d62492012-11-15 21:28:22 +010010899 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010900" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10901" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010902 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010903
Bram Moolenaar446cb832008-06-24 21:56:24 +000010904 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010905" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010906 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010907
Bram Moolenaar5c736222010-01-06 20:54:52 +010010908 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010909" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010910 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010911 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010912 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010913" 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 +010010914" call Dret("netrw#LocalBrowseCheck")
10915 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010916 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010917
Bram Moolenaar85850f32019-07-19 22:05:51 +020010918 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010919 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10920 " AND IF the listing style is not a tree listing
10921 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010922" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010923 let ibuf = 1
10924 let buflast = bufnr("$")
10925 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010926 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10927 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010928 endif
10929 let ibuf= ibuf + 1
10930 endwhile
10931 endif
10932 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010933" 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>"))
10934" 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 +000010935 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010936" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010937endfun
10938
10939" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010940" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010941" performed any shell command. The idea is to cause all local-browsing
10942" buffers to be refreshed after a user has executed some shell command,
10943" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010944fun! s:LocalBrowseRefresh()
10945" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010946" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10947" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010948
Bram Moolenaar446cb832008-06-24 21:56:24 +000010949 " determine which buffers currently reside in a tab
10950 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010951" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010952 return
10953 endif
10954 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010955" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010956 return
10957 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010958 if !empty(getcmdwintype())
10959 " cannot move away from cmdline window, see :h E11
10960 return
10961 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010962 if exists("s:netrw_events") && s:netrw_events == 1
10963 " s:LocalFastBrowser gets called (indirectly) from a
10964 let s:netrw_events= 2
10965" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10966 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010967 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010968 let itab = 1
10969 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010970 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010971 while itab <= tabpagenr("$")
10972 let buftablist = buftablist + tabpagebuflist()
10973 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010974 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010975 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010976" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10977" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010978 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10979 " | refresh any netrw window
10980 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010981 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010982 let ibl = 0
10983 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010984" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010985 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10986 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010987 " (ibuf not shown in a current window AND
10988 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010989" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10990 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010991 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010992" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010993 continue
10994 elseif index(tabpagebuflist(),ibuf) != -1
10995 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010996" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010997 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010998 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010999 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
11000 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
11001 let g:netrw_quickhelp= g:netrw_quickhelp - 1
11002 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011003" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011004 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
11005 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11006 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011007 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011008 endif
11009 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011010" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011011 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011012" call Decho("restore window: win_gotoid(".curwinid.")")
11013 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011014 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011015
Bram Moolenaara6878372014-03-22 21:02:50 +010011016" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011017endfun
11018
11019" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011020" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11021"
11022" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011023" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011024" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11025" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011026" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011027"
11028" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11029" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011030" (re-using a buffer may not be as accurate)
11031"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011032" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011033" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11034" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11035" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11036" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011037fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011038" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11039" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11040" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11041" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011042
11043 " initialize browselist, a list of buffer numbers that the local browser has used
11044 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011045" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011046 let s:netrw_browselist= []
11047 endif
11048
11049 " append current buffer to fastbrowse list
11050 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011051" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011052 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011053" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011054 endif
11055
11056 " enable autocmd events to handle refreshing/removing local browser buffers
11057 " If local browse buffer is currently showing: refresh it
11058 " If local browse buffer is currently hidden : wipe it
11059 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11060 " =1 : medium speed, re-use directory listing for remote only
11061 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011062 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11063 let s:netrw_events= 1
11064 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011065 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011066 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011067" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011068 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011069 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011070" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011071 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011072 endif
11073 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011074
11075 " user must have changed fastbrowse to its fast setting, so remove
11076 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011077 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011078" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011079 unlet s:netrw_events
11080 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011081 au!
11082 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011083 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011084 endif
11085
Bram Moolenaar85850f32019-07-19 22:05:51 +020011086" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011087endfun
11088
11089" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011090" s:LocalListing: does the job of "ls" for local directories {{{2
11091fun! s:LocalListing()
11092" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011093" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11094" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11095" 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 +010011096
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011097" 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
11098" 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
11099" 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 " get the list of files contained in the current directory
11102 let dirname = b:netrw_curdir
11103 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011104 let filelist = s:NetrwGlob(dirname,"*",0)
11105 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011106" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011107
Nir Lichtman1e34b952024-05-08 19:19:34 +020011108 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011109" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011110 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11111 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011112" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011113 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011114" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011115 endif
11116
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011117" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011118" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011119" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011120
11121 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11122 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11123 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011124" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11125" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011126 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011127" 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 +010011128
11129 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011130" call Decho(" ",'~'.expand("<slnum>"))
11131" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011132
11133 if getftype(filename) == "link"
11134 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011135" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011136 let pfile= filename."@"
11137
11138 elseif getftype(filename) == "socket"
11139 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011141 let pfile= filename."="
11142
11143 elseif getftype(filename) == "fifo"
11144 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011145" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011146 let pfile= filename."|"
11147
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011148 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011149 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011150" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011151 let pfile= filename."/"
11152
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011153 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011154 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011155 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11156 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011157" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011158 let pfile= filename."*"
11159 else
11160 " normal file
11161 let pfile= filename
11162 endif
11163 elseif executable(filename)
11164 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011165" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011166 let pfile= filename."*"
11167 else
11168 " normal file
11169 let pfile= filename
11170 endif
11171
11172 else
11173 " normal file
11174 let pfile= filename
11175 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011176" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011177
11178 if pfile =~ '//$'
11179 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011180" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011181 endif
11182 let pfile= strpart(pfile,dirnamelen)
11183 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011184" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11185" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011186
11187 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011188 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11189 let sz = getfsize(filename)
11190 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11191 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011192
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011193 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011194 let sz= s:NetrwHumanReadable(sz)
11195 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011196 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011197 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011198" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011199 endif
11200
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011201 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011202 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011203 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011204" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011205" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011206 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011207 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011208" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011209 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011210 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011211
11212 elseif g:netrw_sort_by =~ "^s"
11213 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011214" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011215" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011216 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011217 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011218" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011219 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011220 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011221
11222 else
11223 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011224" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011225" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011226 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011227 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011228" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011229 endfor
11230
11231 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011232 sil! NetrwKeepj g/^$/d
11233 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011234 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011235" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011236 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11237
11238" call Dret("s:LocalListing")
11239endfun
11240
11241" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011242" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11243fun! s:NetrwLocalExecute(cmd)
11244" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11245 let ykeep= @@
11246 " sanity check
11247 if !executable(a:cmd)
11248 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11249 let @@= ykeep
11250" call Dret("s:NetrwLocalExecute")
11251 return
11252 endif
11253
11254 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011255" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011256 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011257" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011258
11259 " strip any ansi escape sequences off
11260 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11261
11262 " show user the result(s)
11263 echomsg result
11264 let @@= ykeep
11265
11266" call Dret("s:NetrwLocalExecute")
11267endfun
11268
11269" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011270" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011271fun! s:NetrwLocalRename(path) range
11272" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11273
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011274 if !exists("w:netrw_bannercnt")
11275 let w:netrw_bannercnt= b:netrw_bannercnt
11276 endif
11277
Bram Moolenaar97d62492012-11-15 21:28:22 +010011278 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011279 let ykeep = @@
11280 let ctr = a:firstline
11281 let svpos = winsaveview()
11282 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011283" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011284
11285 " rename files given by the markfilelist
11286 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11287 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011288" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011289 if exists("subfrom")
11290 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011291" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011292 else
11293 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011294 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011295 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011296 if newname =~ ''
11297 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11298 let newname = substitute(newname,'^.*','','')
11299 elseif newname =~ ''
11300 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11301 let newname = substitute(newname,'[^/]*','','')
11302 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011303 if newname =~ '^s/'
11304 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11305 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011306" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011307 let newname = substitute(oldname,subfrom,subto,'')
11308 endif
11309 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011310 if !all && filereadable(newname)
11311 call inputsave()
11312 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11313 call inputrestore()
11314 if response == "all"
11315 let all= 1
11316 elseif response != "y" && response != "yes"
11317 " refresh the directory
11318" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11319 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11320" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11321 NetrwKeepj call winrestview(svpos)
11322 let @@= ykeep
11323" call Dret("NetrwLocalRename")
11324 return
11325 endif
11326 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011327 call rename(oldname,newname)
11328 endfor
11329 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011330
Bram Moolenaar97d62492012-11-15 21:28:22 +010011331 else
11332
11333 " attempt to rename files/directories
11334 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011335 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011336
11337 " sanity checks
11338 if line(".") < w:netrw_bannercnt
11339 let ctr= ctr + 1
11340 continue
11341 endif
11342 let curword= s:NetrwGetWord()
11343 if curword == "./" || curword == "../"
11344 let ctr= ctr + 1
11345 continue
11346 endif
11347
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011348 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011349 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011350" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011351
11352 call inputsave()
11353 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11354 call inputrestore()
11355
11356 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011357" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011358
11359 let ctr= ctr + 1
11360 endwhile
11361 endif
11362
11363 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011364" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011365 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011366" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11367 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011368 let @@= ykeep
11369
11370" call Dret("NetrwLocalRename")
11371endfun
11372
11373" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011374" s:NetrwLocalRm: {{{2
11375fun! s:NetrwLocalRm(path) range
11376" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011377" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011378
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011379 if !exists("w:netrw_bannercnt")
11380 let w:netrw_bannercnt= b:netrw_bannercnt
11381 endif
11382
Bram Moolenaar446cb832008-06-24 21:56:24 +000011383 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011384 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011385 let ret = 0
11386 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011387 let svpos = winsaveview()
11388" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011389
11390 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11391 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011392" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011393 for fname in s:netrwmarkfilelist_{bufnr("%")}
11394 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011395 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011396 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011397 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011398 let all= 1
11399 endif
11400 endfor
11401 call s:NetrwUnMarkFile(1)
11402
11403 else
11404 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011405" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011406
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011407 let keepsol= &l:sol
11408 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011409 let ctr = a:firstline
11410 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011411 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011412
11413 " sanity checks
11414 if line(".") < w:netrw_bannercnt
11415 let ctr= ctr + 1
11416 continue
11417 endif
11418 let curword= s:NetrwGetWord()
11419 if curword == "./" || curword == "../"
11420 let ctr= ctr + 1
11421 continue
11422 endif
11423 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011424 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011425 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011426 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011427 let all= 1
11428 endif
11429 let ctr= ctr + 1
11430 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011431 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011432 endif
11433
11434 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011435" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011436 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011437 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011438" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11439 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011440 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011441 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011442
11443" call Dret("s:NetrwLocalRm")
11444endfun
11445
11446" ---------------------------------------------------------------------
11447" s:NetrwLocalRmFile: remove file fname given the path {{{2
11448" Give confirmation prompt unless all==1
11449fun! s:NetrwLocalRmFile(path,fname,all)
11450" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011451
Bram Moolenaar446cb832008-06-24 21:56:24 +000011452 let all= a:all
11453 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011454 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011455 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11456" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011457
11458 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11459 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011460" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011461 if !all
11462 echohl Statement
11463 call inputsave()
11464 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11465 call inputrestore()
11466 echohl NONE
11467 if ok == ""
11468 let ok="no"
11469 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011470" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011471 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011472" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011473 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011474 let all= 1
11475 endif
11476 endif
11477
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011478 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011479 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011480" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011481 endif
11482
11483 else
11484 " attempt to remove directory
11485 if !all
11486 echohl Statement
11487 call inputsave()
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011488 let ok= input("Confirm *recursive* deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011489 call inputrestore()
11490 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11491 if ok == ""
11492 let ok="no"
11493 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011494 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011495 let all= 1
11496 endif
11497 endif
11498 let rmfile= substitute(rmfile,'[\/]$','','e')
11499
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011500 if all || ok =~# 'y\%[es]' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011501 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011502 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011503 endif
11504 endif
11505 endif
11506
11507" call Dret("s:NetrwLocalRmFile ".ok)
11508 return ok
11509endfun
11510
Bram Moolenaar85850f32019-07-19 22:05:51 +020011511" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011512" Support Functions: {{{1
11513
Bram Moolenaar488c6512005-08-11 20:09:58 +000011514" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011515" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11516" 0: marked file list of current buffer
11517" 1: marked file target
11518fun! netrw#Access(ilist)
11519 if a:ilist == 0
11520 if exists("s:netrwmarkfilelist_".bufnr('%'))
11521 return s:netrwmarkfilelist_{bufnr('%')}
11522 else
11523 return "no-list-buf#".bufnr('%')
11524 endif
11525 elseif a:ilist == 1
11526 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011527 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011528endfun
11529
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011530" ---------------------------------------------------------------------
11531" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11532fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011533 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011534endfun
11535
Bram Moolenaara6878372014-03-22 21:02:50 +010011536" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011537" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11538" I expect this function to be used in
11539" :PChkAssert netrw#Expose("netrwmarkfilelist")
11540" for example.
11541fun! netrw#Expose(varname)
11542" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011543 if exists("s:".a:varname)
11544 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011545" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011546 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011547" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011548 if type(retval) == 3
11549 let retval = copy(retval)
11550 let i = 0
11551 while i < len(retval)
11552 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11553 let i = i + 1
11554 endwhile
11555 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011556" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011557 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011558 else
11559" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011560 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011561 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011562" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011563 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011564 endif
11565
11566" call Dret("netrw#Expose ".string(retval))
11567 return retval
11568endfun
11569
11570" ---------------------------------------------------------------------
11571" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11572fun! netrw#Modify(varname,newvalue)
11573" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11574 exe "let s:".a:varname."= ".string(a:newvalue)
11575" call Dret("netrw#Modify")
11576endfun
11577
11578" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011579" netrw#RFC2396: converts %xx into characters {{{2
11580fun! netrw#RFC2396(fname)
11581" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011582 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011583" call Dret("netrw#RFC2396 ".fname)
11584 return fname
11585endfun
11586
11587" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011588" netrw#UserMaps: supports user-specified maps {{{2
11589" see :help function()
11590"
11591" g:Netrw_UserMaps is a List with members such as:
11592" [[keymap sequence, function reference],...]
11593"
11594" The referenced function may return a string,
11595" refresh : refresh the display
11596" -other- : this string will be executed
11597" or it may return a List of strings.
11598"
11599" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011600" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011601" Related functions:
11602" netrw#Expose(varname) -- see s:varname variables
11603" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11604" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11605fun! netrw#UserMaps(islocal)
11606" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11607" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11608
11609 " set up usermaplist
11610 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11611" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11612 for umap in g:Netrw_UserMaps
11613" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11614" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11615 " if umap[0] is a string and umap[1] is a string holding a function name
11616 if type(umap[0]) == 1 && type(umap[1]) == 1
11617" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11618 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11619 else
11620 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11621 endif
11622 endfor
11623 endif
11624" call Dret("netrw#UserMaps")
11625endfun
11626
11627" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011628" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11629fun! netrw#WinPath(path)
11630" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011631 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011632 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011633 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011634 " remove trailing slash (Win95)
11635 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11636 " remove escaped spaces
11637 let path = substitute(path, '\ ', ' ', 'g')
11638 " convert slashes to backslashes
11639 let path = substitute(path, '/', '\', 'g')
11640 else
11641 let path= a:path
11642 endif
11643" call Dret("netrw#WinPath <".path.">")
11644 return path
11645endfun
11646
11647" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011648" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11649" cb : bl2mf=0 add marked files to buffer list
11650" cB : bl2mf=1 use bufferlist to mark files
11651" (mnemonic: cb = copy (marked files) to buffer list)
11652fun! s:NetrwBadd(islocal,bl2mf)
11653" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11654 if a:bl2mf
11655 " cB: add buffer list to marked files
11656 redir => bufl
11657 ls
11658 redir END
11659 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11660 for fname in bufl
11661 call s:NetrwMarkFile(a:islocal,fname)
11662 endfor
11663 else
11664 " cb: add marked files to buffer list
11665 for fname in s:netrwmarkfilelist_{bufnr("%")}
11666" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11667 exe "badd ".fnameescape(fname)
11668 endfor
11669 let curbufnr = bufnr("%")
11670 let curdir = s:NetrwGetCurdir(a:islocal)
11671 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11672 endif
11673" call Dret("s:NetrwBadd")
11674endfun
11675
11676" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011677" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11678fun! s:ComposePath(base,subdir)
11679" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11680
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011681 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011682" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011683 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011684 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011685 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011686 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011687 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011688 endif
11689
Bram Moolenaar85850f32019-07-19 22:05:51 +020011690 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011691 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011692" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011693 let ret= a:subdir
11694
Nir Lichtman1e34b952024-05-08 19:19:34 +020011695 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011696" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011697 if a:base =~ '[/\\]$'
11698 let ret= a:base.a:subdir
11699 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011700 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011701 endif
11702
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011703 elseif a:base =~ '^\a\{3,}://'
11704" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011705 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11706 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11707 if a:subdir == '../'
11708 if curpath =~ '[^/]/[^/]\+/$'
11709 let curpath= substitute(curpath,'[^/]\+/$','','')
11710 else
11711 let curpath=""
11712 endif
11713 let ret= urlbase.curpath
11714 else
11715 let ret= urlbase.curpath.a:subdir
11716 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011717" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11718" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11719" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011720
11721 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011722" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011723 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11724 if a:base =~ '^//'
11725 " keeping initial '//' for the benefit of network share listing support
11726 let ret= '/'.ret
11727 endif
11728 let ret= simplify(ret)
11729 endif
11730
11731" call Dret("s:ComposePath ".ret)
11732 return ret
11733endfun
11734
11735" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011736" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11737" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11738fun! s:DeleteBookmark(fname)
11739" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11740 call s:MergeBookmarks()
11741
11742 if exists("g:netrw_bookmarklist")
11743 let indx= index(g:netrw_bookmarklist,a:fname)
11744 if indx == -1
11745 let indx= 0
11746 while indx < len(g:netrw_bookmarklist)
11747 if g:netrw_bookmarklist[indx] =~ a:fname
11748 call remove(g:netrw_bookmarklist,indx)
11749 let indx= indx - 1
11750 endif
11751 let indx= indx + 1
11752 endwhile
11753 else
11754 " remove exact match
11755 call remove(g:netrw_bookmarklist,indx)
11756 endif
11757 endif
11758
11759" call Dret("s:DeleteBookmark")
11760endfun
11761
11762" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011763" s:FileReadable: o/s independent filereadable {{{2
11764fun! s:FileReadable(fname)
11765" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11766
11767 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011768 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011769 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011770 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011771 endif
11772
11773" call Dret("s:FileReadable ".ret)
11774 return ret
11775endfun
11776
11777" ---------------------------------------------------------------------
11778" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11779" Places correct suffix on end of temporary filename,
11780" using the suffix provided with fname
11781fun! s:GetTempfile(fname)
11782" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11783
11784 if !exists("b:netrw_tmpfile")
11785 " get a brand new temporary filename
11786 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011787" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011788
Bram Moolenaarc236c162008-07-13 17:41:49 +000011789 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011790" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011791
Bram Moolenaar9964e462007-05-05 17:54:07 +000011792 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011793 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11794" 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 +010011795 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011796" call Dret("s:GetTempfile getcwd<".getcwd().">")
11797 return ""
11798 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011799
Bram Moolenaar9964e462007-05-05 17:54:07 +000011800 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011801 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011802" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011803
Bram Moolenaar9964e462007-05-05 17:54:07 +000011804 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011805 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011806 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011807 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011808 if !exists("+shellslash") || !&ssl
11809 let tmpfile = substitute(tmpfile,'/','\','g')
11810 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011811 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011812 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011813 endif
11814 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011815" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011816 else
11817 " re-use temporary filename
11818 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011819" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011820 endif
11821
11822 " use fname's suffix for the temporary file
11823 if a:fname != ""
11824 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011825" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011826 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011827 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011828 elseif a:fname =~ '.txz$'
11829 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011830 else
11831 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11832 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011833" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011834 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011835" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011836 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011837" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011838 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11839 endif
11840 endif
11841
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011842" 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 +000011843" call Dret("s:GetTempfile <".tmpfile.">")
11844 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011845endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011846
11847" ---------------------------------------------------------------------
11848" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011849" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011850fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011851" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011852 if s:user == ""
11853 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11854 else
11855 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11856 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011857 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011858 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011859 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011860 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011861 else
11862 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11863 endif
11864" call Dret("s:MakeSshCmd <".sshcmd.">")
11865 return sshcmd
11866endfun
11867
11868" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011869" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11870fun! s:MakeBookmark(fname)
11871" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11872
11873 if !exists("g:netrw_bookmarklist")
11874 let g:netrw_bookmarklist= []
11875 endif
11876
11877 if index(g:netrw_bookmarklist,a:fname) == -1
11878 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011879 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011880 call add(g:netrw_bookmarklist,a:fname.'/')
11881 elseif a:fname !~ '/'
11882 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11883 else
11884 call add(g:netrw_bookmarklist,a:fname)
11885 endif
11886 call sort(g:netrw_bookmarklist)
11887 endif
11888
11889" call Dret("s:MakeBookmark")
11890endfun
11891
11892" ---------------------------------------------------------------------
11893" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11894fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011895" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011896 " get bookmarks from .netrwbook file
11897 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011898 if filereadable(s:NetrwFile(savefile))
11899" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011900 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011901" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011902 NetrwKeepj call delete(savefile)
11903 endif
11904" call Dret("s:MergeBookmarks")
11905endfun
11906
11907" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011908" s:NetrwBMShow: {{{2
11909fun! s:NetrwBMShow()
11910" call Dfunc("s:NetrwBMShow()")
11911 redir => bmshowraw
11912 menu
11913 redir END
11914 let bmshowlist = split(bmshowraw,'\n')
11915 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011916 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011917 if bmshowfuncs != []
11918 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011919 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011920 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011921 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011922 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011923 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011924" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11925endfun
11926
11927" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011928" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011929fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011930 if !exists("w:netrw_liststyle")
11931 let w:netrw_liststyle= g:netrw_liststyle
11932 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011933" 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 +020011934
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011935" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11936
Bram Moolenaaradc21822011-04-01 18:03:16 +020011937 if &ft != "netrw"
11938 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11939 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011940" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011941
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011942 elseif g:netrw_cursor == 8
11943 if w:netrw_liststyle == s:WIDELIST
11944 setl cursorline
11945 setl cursorcolumn
11946 else
11947 setl cursorline
11948 endif
11949 elseif g:netrw_cursor == 7
11950 setl cursorline
11951 elseif g:netrw_cursor == 6
11952 if w:netrw_liststyle == s:WIDELIST
11953 setl cursorline
11954 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011955 elseif g:netrw_cursor == 4
11956 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011957" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011958 setl cursorline
11959 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011960
11961 elseif g:netrw_cursor == 3
11962 " thin-long-tree: cursorline, user's cursorcolumn
11963 " wide : cursorline, cursorcolumn
11964 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011965" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011966 setl cursorline
11967 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011968 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011969" 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 +020011970 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011971 endif
11972
11973 elseif g:netrw_cursor == 2
11974 " thin-long-tree: cursorline, user's cursorcolumn
11975 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011976" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011977 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011978
11979 elseif g:netrw_cursor == 1
11980 " thin-long-tree: user's cursorline, user's cursorcolumn
11981 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011982 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011983" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011984 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011985 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011986" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011987 endif
11988
11989 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011990 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011991" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011992 let &l:cursorline = s:netrw_usercul
11993 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011994 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011995
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011996" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011997" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011998endfun
11999
12000" ---------------------------------------------------------------------
12001" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
12002fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012003" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012004 if exists("s:netrw_usercul")
12005 let &l:cursorline = s:netrw_usercul
12006 endif
12007 if exists("s:netrw_usercuc")
12008 let &l:cursorcolumn = s:netrw_usercuc
12009 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012010" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012011" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12012endfun
12013
Christian Brabandt62f7b552024-06-23 20:23:40 +020012014" s:RestoreRegister: restores all registers given in the dict {{{2
12015fun! s:RestoreRegister(dict)
12016 for [key, val] in items(a:dict)
12017 if key == 'unnamed'
12018 let key = ''
12019 endif
12020 call setreg(key, val[0], val[1])
12021 endfor
12022endfun
12023
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012024" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012025" s:NetrwDelete: Deletes a file. {{{2
12026" Uses Steve Hall's idea to insure that Windows paths stay
12027" acceptable. No effect on Unix paths.
12028" Examples of use: let result= s:NetrwDelete(path)
12029fun! s:NetrwDelete(path)
12030" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12031
Bram Moolenaar5c736222010-01-06 20:54:52 +010012032 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012033 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012034 if exists("+shellslash")
12035 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012036 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012037 let result = delete(path)
12038 let &shellslash = sskeep
12039 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012040" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012041 let result= delete(path)
12042 endif
12043 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012044" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012045 let result= delete(path)
12046 endif
12047 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012048 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012049 endif
12050
12051" call Dret("s:NetrwDelete ".result)
12052 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012053endfun
12054
12055" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012056" s:NetrwBufRemover: removes a buffer that: {{{2s
12057" has buffer-id > 1
12058" is unlisted
12059" is unnamed
12060" does not appear in any window
12061fun! s:NetrwBufRemover(bufid)
12062" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12063" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12064" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12065" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12066" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12067
yasuda4dbb2662023-10-04 20:50:35 +020012068 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012069" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012070 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012071 endif
12072
12073" call Dret("s:NetrwBufRemover")
12074endfun
12075
12076" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012077" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012078fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012079" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012080" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012081
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012082 " Clean out the last buffer:
12083 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12084 " If so, delete it.
12085 call s:NetrwBufRemover(bufnr("$"))
12086
Bram Moolenaar446cb832008-06-24 21:56:24 +000012087 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012088" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012089 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12090 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12091 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12092 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12093 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12094 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12095 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12096 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12097 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12098 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12099 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12100 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12101 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12102 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12103 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12104 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12105
Bram Moolenaar85850f32019-07-19 22:05:51 +020012106 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012107" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012108 " when tree listing uses file TreeListing... a new buffer is made.
12109 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012110 " COMBAK: this causes a problem, see P43
12111" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012112 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012113 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012114 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012115" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012116 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012117
Bram Moolenaar446cb832008-06-24 21:56:24 +000012118 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012119" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012120 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12121 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12122 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12123 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12124 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12125 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12126 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12127 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12128 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12129 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12130 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12131 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12132 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12133 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12134 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12135 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12136
Bram Moolenaar5c736222010-01-06 20:54:52 +010012137 if a:0 > 0
12138 let b:netrw_curdir= a:1
12139 if b:netrw_curdir =~ '/$'
12140 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012141 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012142 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012143 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012144 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12145 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012146 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012147 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012148 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012149 endif
12150 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012151 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12152 let &l:bexpr = "netrw#BalloonHelp()"
12153 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012154
Bram Moolenaar8d043172014-01-23 14:24:41 +010012155" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012156endfun
12157
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012158" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012159" s:NetrwExe: executes a string using "!" {{{2
12160fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012161" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012162 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012163" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012164 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12165 set shell& shellcmdflag& shellxquote& shellxescape&
12166 set shellquote& shellpipe& shellredir& shellslash&
12167 exe a:cmd
12168 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12169 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012170" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012171 exe a:cmd
12172 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012173 if v:shell_error
12174 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12175 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012176" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012177endfun
12178
12179" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012180" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12181fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012182 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012183" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012184 let curbuf = bufnr("%")
12185 let curwin = winnr()
12186 let iwin = 1
12187 while iwin <= winnr("$")
12188 exe iwin."wincmd w"
12189 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12190 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12191 let winvars= w:
12192 break
12193 endif
12194 let iwin= iwin + 1
12195 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012196 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012197 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012198" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012199 for k in keys(winvars)
12200 let w:{k}= winvars[k]
12201 endfor
12202 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012203" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012204 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012205endfun
12206
Bram Moolenaara6878372014-03-22 21:02:50 +010012207" ---------------------------------------------------------------------
12208" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012209" Returns: 0=success
12210" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012211fun! s:NetrwLcd(newdir)
12212" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012213" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012214
Bram Moolenaar85850f32019-07-19 22:05:51 +020012215 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012216 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012217 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012218 catch /^Vim\%((\a\+)\)\=:E344/
12219 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12220 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012221 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012222 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12223 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012224 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012225 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12226 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012227 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012228 endif
12229 endif
12230 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012231 let err472= 1
12232 endtry
12233
12234 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012235 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12236 if exists("w:netrw_prvdir")
12237 let a:newdir= w:netrw_prvdir
12238 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012239 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012240" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012241 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012242" 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 +010012243 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012244 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012245" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12246 return -1
12247 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012248
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012249" call Decho("getcwd <".getcwd().">")
12250" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012251" call Dret("s:NetrwLcd 0")
12252 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012253endfun
12254
Bram Moolenaar9964e462007-05-05 17:54:07 +000012255" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012256" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12257" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12258fun! s:NetrwSaveWordPosn()
12259" call Dfunc("NetrwSaveWordPosn()")
12260 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12261" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12262endfun
12263
12264" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012265" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12266" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12267fun! s:NetrwHumanReadable(sz)
12268" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12269
12270 if g:netrw_sizestyle == 'h'
12271 if a:sz >= 1000000000
12272 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12273 elseif a:sz >= 10000000
12274 let sz = printf("%d",a:sz/1000000)."m"
12275 elseif a:sz >= 1000000
12276 let sz = printf("%.1f",a:sz/1000000.0)."m"
12277 elseif a:sz >= 10000
12278 let sz = printf("%d",a:sz/1000)."k"
12279 elseif a:sz >= 1000
12280 let sz = printf("%.1f",a:sz/1000.0)."k"
12281 else
12282 let sz= a:sz
12283 endif
12284
12285 elseif g:netrw_sizestyle == 'H'
12286 if a:sz >= 1073741824
12287 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12288 elseif a:sz >= 10485760
12289 let sz = printf("%d",a:sz/1048576)."M"
12290 elseif a:sz >= 1048576
12291 let sz = printf("%.1f",a:sz/1048576.0)."M"
12292 elseif a:sz >= 10240
12293 let sz = printf("%d",a:sz/1024)."K"
12294 elseif a:sz >= 1024
12295 let sz = printf("%.1f",a:sz/1024.0)."K"
12296 else
12297 let sz= a:sz
12298 endif
12299
12300 else
12301 let sz= a:sz
12302 endif
12303
12304" call Dret("s:NetrwHumanReadable ".sz)
12305 return sz
12306endfun
12307
12308" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012309" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12310" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12311fun! s:NetrwRestoreWordPosn()
12312" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012313 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012314" call Dret("NetrwRestoreWordPosn")
12315endfun
12316
12317" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012318" s:RestoreBufVars: {{{2
12319fun! s:RestoreBufVars()
12320" call Dfunc("s:RestoreBufVars()")
12321
12322 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12323 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12324 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12325 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12326 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12327 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12328
12329" call Dret("s:RestoreBufVars")
12330endfun
12331
12332" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012333" s:RemotePathAnalysis: {{{2
12334fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012335" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012336
Bram Moolenaara6878372014-03-22 21:02:50 +010012337 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012338 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012339 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012340 let s:user = substitute(a:dirname,dirpat,'\3','')
12341 let s:machine = substitute(a:dirname,dirpat,'\4','')
12342 let s:port = substitute(a:dirname,dirpat,'\5','')
12343 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012344 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012345 if s:machine =~ '@'
12346 let dirpat = '^\(.*\)@\(.\{-}\)$'
12347 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12348 let s:machine = substitute(s:machine,dirpat,'\2','')
12349 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012350
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012351" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12352" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12353" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12354" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12355" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12356" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012357
12358" call Dret("s:RemotePathAnalysis")
12359endfun
12360
12361" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012362" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12363" Returns status
12364" Runs system() on
12365" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012366" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012367fun! s:RemoteSystem(cmd)
12368" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12369 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012370 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 +000012371 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012372 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012373 else
12374 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12375 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12376 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012377 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012378 else
12379 let cmd= cmd.' '
12380 endif
12381 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012382" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012383 let ret= system(cmd)
12384 endif
12385" call Dret("s:RemoteSystem ".ret)
12386 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012387endfun
12388
12389" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012390" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012391fun! s:RestoreWinVars()
12392" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012393 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012394 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12395 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12396 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12397 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12398 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12399 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12400 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12401 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12402 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12403 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12404 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12405 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012406 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12407 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012408 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12409 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12410 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12411" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012412endfun
12413
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012414" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012415" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12416"
12417" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12418" is true) and a command, :Rexplore, which call this function.
12419"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012420" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012421"
12422" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012423fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012424 if exists("s:netrwdrag")
12425 return
12426 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012427" 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 +010012428" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12429" 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 +010012430
12431 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012432 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012433" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012434 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012435 unlet w:netrw_rexfile
12436" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012437 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012438" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012439" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12440" 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 +020012441 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012442
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012443 " ---------------------------
12444 " :Rex issued while in a file
12445 " ---------------------------
12446
Bram Moolenaara6878372014-03-22 21:02:50 +010012447 " record current file so :Rex can return to it from netrw
12448 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012449" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012450
12451 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012452" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012453 return
12454 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012455" 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 +020012456 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012457 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012458 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012459 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012460 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012461 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012462 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012463 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012464 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012465" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12466 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012467" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12468 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012469 if exists("s:rexposn_".bufnr('%'))
12470 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012471 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012472 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012473" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012474 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012475
Bram Moolenaar85850f32019-07-19 22:05:51 +020012476 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12477 if exists("s:explore_match")
12478 exe "2match netrwMarkFile /".s:explore_match."/"
12479 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012480 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012481
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012482" 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 +010012483" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012484endfun
12485
12486" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012487" s:SaveBufVars: save selected b: variables to s: variables {{{2
12488" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012489fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012490" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012491
12492 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12493 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12494 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12495 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12496 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12497 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12498
12499" call Dret("s:SaveBufVars")
12500endfun
12501
12502" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012503" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12504fun! s:SavePosn(posndict)
12505" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12506
Bram Moolenaar85850f32019-07-19 22:05:51 +020012507 if !exists("a:posndict[bufnr('%')]")
12508 let a:posndict[bufnr("%")]= []
12509 endif
12510" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12511 call add(a:posndict[bufnr("%")],winsaveview())
12512" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012513
12514" call Dret("s:SavePosn posndict")
12515 return a:posndict
12516endfun
12517
12518" ---------------------------------------------------------------------
12519" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12520fun! s:RestorePosn(posndict)
12521" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012522 if exists("a:posndict")
12523 if has_key(a:posndict,bufnr("%"))
12524" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12525 let posnlen= len(a:posndict[bufnr("%")])
12526 if posnlen > 0
12527 let posnlen= posnlen - 1
12528" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12529 call winrestview(a:posndict[bufnr("%")][posnlen])
12530 call remove(a:posndict[bufnr("%")],posnlen)
12531" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12532 endif
12533 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012534 endif
12535" call Dret("s:RestorePosn")
12536endfun
12537
12538" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012539" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012540fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012541" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012542 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12543 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12544 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12545 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12546 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12547 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12548 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12549 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12550 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12551 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12552 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12553 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12554 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12555 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12556 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12557 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12558 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12559 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12560" call Dret("s:SaveWinVars")
12561endfun
12562
12563" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012564" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012565" To allow separate windows to have their own activities, such as
12566" Explore **/pattern, several variables have been made window-oriented.
12567" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012568" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012569" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012570fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012571" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012572 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12573 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12574 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12575 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12576 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12577 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12578 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12579 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12580 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12581 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12582" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012583endfun
12584
12585" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012586" s:SetRexDir: set directory for :Rexplore {{{2
12587fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012588" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012589 let w:netrw_rexdir = a:dirname
12590 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012591 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012592" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12593" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012594" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012595" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012596" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012597endfun
12598
12599" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012600" s:ShowLink: used to modify thin and tree listings to show links {{{2
12601fun! s:ShowLink()
12602" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012603" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12604" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012605 if exists("b:netrw_curdir")
12606 norm! $?\a
12607 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12608 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012609" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12610" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12611" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12612 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012613 let dirlen = strlen(b:netrw_curdir)
12614 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012615" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012616 endif
12617 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012618" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12619" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012620 setl noro ma
12621 call setline(".",modline)
12622 setl ro noma nomod
12623 endif
12624" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12625endfun
12626
12627" ---------------------------------------------------------------------
12628" s:ShowStyle: {{{2
12629fun! s:ShowStyle()
12630 if !exists("w:netrw_liststyle")
12631 let liststyle= g:netrw_liststyle
12632 else
12633 let liststyle= w:netrw_liststyle
12634 endif
12635 if liststyle == s:THINLIST
12636 return s:THINLIST.":thin"
12637 elseif liststyle == s:LONGLIST
12638 return s:LONGLIST.":long"
12639 elseif liststyle == s:WIDELIST
12640 return s:WIDELIST.":wide"
12641 elseif liststyle == s:TREELIST
12642 return s:TREELIST.":tree"
12643 else
12644 return 'n/a'
12645 endif
12646endfun
12647
12648" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012649" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12650" Solution from Nicolai Weibull, vim docs (:help strlen()),
12651" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012652fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012653" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12654
12655 if v:version >= 703 && exists("*strdisplaywidth")
12656 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012657
Bram Moolenaar8d043172014-01-23 14:24:41 +010012658 elseif type(g:Align_xstrlen) == 1
12659 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12660 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012661
Bram Moolenaar8d043172014-01-23 14:24:41 +010012662 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012663 " number of codepoints (Latin a + combining circumflex is two codepoints)
12664 " (comment from TM, solution from NW)
12665 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012666
Bram Moolenaar8d043172014-01-23 14:24:41 +010012667 elseif g:Align_xstrlen == 2
12668 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012669 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12670 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012671 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012672
Bram Moolenaar8d043172014-01-23 14:24:41 +010012673 elseif g:Align_xstrlen == 3
12674 " virtual length (counting, for instance, tabs as anything between 1 and
12675 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012676 " preceded by lam, one otherwise, etc.)
12677 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012678 let modkeep= &l:mod
12679 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012680 call setline(line("."),a:x)
12681 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012682 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012683 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012684 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012685
Bram Moolenaar446cb832008-06-24 21:56:24 +000012686 else
12687 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012688 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012689 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012690" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012691 return ret
12692endfun
12693
12694" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012695" s:ShellEscape: shellescape(), or special windows handling {{{2
12696fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012697 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012698 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12699 endif
12700 let f = a:0 > 0 ? a:1 : 0
12701 return shellescape(a:s, f)
12702endfun
12703
12704" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012705" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012706fun! s:TreeListMove(dir)
12707" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012708 let curline = getline('.')
12709 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12710 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12711 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12712 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12713 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12714 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12715" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12716" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12717" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12718" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12719" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12720 " COMBAK : need to handle when on a directory
12721 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012722 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012723 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012724 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012725 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012726" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012727 elseif a:dir == '[]' && nxtline != ''
12728 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012729" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012730 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12731 if nl != 0
12732 NetrwKeepj norm! k
12733 else
12734 NetrwKeepj norm! G
12735 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012736" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012737 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012738 endif
12739
12740" call Dret("s:TreeListMove")
12741endfun
12742
12743" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012744" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12745" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12746" can't be called except via emenu. But due to locale, that menu line may not be called
12747" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12748fun! s:UpdateBuffersMenu()
12749" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012750 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012751 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012752 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012753 catch /^Vim\%((\a\+)\)\=:E/
12754 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012755 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012756 endtry
12757 endif
12758" call Dret("s:UpdateBuffersMenu")
12759endfun
12760
12761" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012762" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012763" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012764fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012765" call Dfunc("s:UseBufWinVars()")
12766 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012767 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12768 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12769 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12770 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12771 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12772 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12773 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12774 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12775 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 +000012776" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012777endfun
12778
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012779" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012780" s:UserMaps: supports user-defined UserMaps {{{2
12781" * calls a user-supplied funcref(islocal,curdir)
12782" * interprets result
12783" See netrw#UserMaps()
12784fun! s:UserMaps(islocal,funcname)
12785" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12786
12787 if !exists("b:netrw_curdir")
12788 let b:netrw_curdir= getcwd()
12789 endif
12790 let Funcref = function(a:funcname)
12791 let result = Funcref(a:islocal)
12792
12793 if type(result) == 1
12794 " if result from user's funcref is a string...
12795" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12796 if result == "refresh"
12797" call Decho("refreshing display",'~'.expand("<slnum>"))
12798 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12799 elseif result != ""
12800" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12801 exe result
12802 endif
12803
12804 elseif type(result) == 3
12805 " if result from user's funcref is a List...
12806" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12807 for action in result
12808 if action == "refresh"
12809" call Decho("refreshing display",'~'.expand("<slnum>"))
12810 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12811 elseif action != ""
12812" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12813 exe action
12814 endif
12815 endfor
12816 endif
12817
12818" call Dret("s:UserMaps")
12819endfun
12820
Bram Moolenaar85850f32019-07-19 22:05:51 +020012821" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012822" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012823" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012824let &cpo= s:keepcpo
12825unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012826
Bram Moolenaar85850f32019-07-19 22:05:51 +020012827" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012828" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012829" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012830" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012831" doing autoload/netrw.vim version v172g ~57
12832" varname<g:netrw_dirhistcnt> value=0 ~1
12833" varname<s:THINLIST> value=0 ~1
12834" varname<s:LONGLIST> value=1 ~1
12835" varname<s:WIDELIST> value=2 ~1
12836" varname<s:TREELIST> value=3 ~1
12837" varname<s:MAXLIST> value=4 ~1
12838" varname<g:netrw_use_errorwindow> value=2 ~1
12839" varname<g:netrw_http_xcmd> value=-q -O ~1
12840" varname<g:netrw_http_put_cmd> value=curl -T ~1
12841" varname<g:netrw_keepj> value=keepj ~1
12842" varname<g:netrw_rcp_cmd> value=rcp ~1
12843" varname<g:netrw_rsync_cmd> value=rsync ~1
12844" varname<g:netrw_rsync_sep> value=/ ~1
12845" varname<g:netrw_scp_cmd> value=scp -q ~1
12846" varname<g:netrw_sftp_cmd> value=sftp ~1
12847" varname<g:netrw_ssh_cmd> value=ssh ~1
12848" varname<g:netrw_alto> value=0 ~1
12849" varname<g:netrw_altv> value=1 ~1
12850" varname<g:netrw_banner> value=1 ~1
12851" varname<g:netrw_browse_split> value=0 ~1
12852" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12853" varname<g:netrw_chgwin> value=-1 ~1
12854" varname<g:netrw_clipboard> value=1 ~1
12855" varname<g:netrw_compress> value=gzip ~1
12856" varname<g:netrw_ctags> value=ctags ~1
12857" varname<g:netrw_cursor> value=2 ~1
12858" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12859" varname<g:netrw_cygdrive> value=/cygdrive ~1
12860" varname<s:didstarstar> value=0 ~1
12861" varname<g:netrw_dirhistcnt> value=0 ~1
12862" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12863" varname<g:netrw_dirhistmax> value=10 ~1
12864" varname<g:netrw_errorlvl> value=0 ~1
12865" varname<g:netrw_fastbrowse> value=1 ~1
12866" 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
12867" varname<g:netrw_ftpmode> value=binary ~1
12868" varname<g:netrw_hide> value=1 ~1
12869" varname<g:netrw_keepdir> value=1 ~1
12870" varname<g:netrw_list_hide> value= ~1
12871" varname<g:netrw_localmkdir> value=mkdir ~1
12872" varname<g:netrw_remote_mkdir> value=mkdir ~1
12873" varname<g:netrw_liststyle> value=0 ~1
12874" varname<g:netrw_markfileesc> value=*./[\~ ~1
12875" varname<g:netrw_maxfilenamelen> value=32 ~1
12876" varname<g:netrw_menu> value=1 ~1
12877" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12878" varname<g:netrw_mousemaps> value=1 ~1
12879" varname<g:netrw_retmap> value=0 ~1
12880" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12881" varname<g:netrw_preview> value=0 ~1