blob: 9650f6dffb6004162fb37e08910840375d891198 [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
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Luca Saccarolaa7d45612024-10-21 21:27:03 +02007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
8" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
yasudac75dad02024-08-22 21:06:32 +020025" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
Christian Brabandt0f5effb2024-09-15 19:17:23 +020026" 2024 Sep 15 by Vim Project: more strict confirmation dialog (#15680)
yasudac18a9d52024-09-19 18:09:51 +020027" 2024 Sep 19 by Vim Project: mf-selection highlight uses wrong pattern (#15700)
Peter Aronoffbe551da2024-09-22 11:29:40 +020028" 2024 Sep 21 by Vim Project: remove extraneous closing bracket (#15718)
Luca Saccarolaa7d45612024-10-21 21:27:03 +020029" 2024 Oct 21 by Vim Project: remove netrwFileHandlers (#15895)
Konfekt3d7e5672024-10-27 22:16:49 +010030" 2024 Oct 27 by Vim Project: clean up gx mapping (#15721)
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +010031" 2024 Oct 30 by Vim Project: fix filetype detection for remote files (#15961)
Christian Brabandt9f320692024-10-30 18:36:20 +010032" 2024 Oct 30 by Vim Project: fix x mapping on cygwin (#13687)
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010033" 2024 Oct 31 by Vim Project: add netrw#Launch() and netrw#Open() (#15962)
Tom Benham4d618002024-10-31 10:47:23 +010034" 2024 Oct 31 by Vim Project: fix E874 when browsing remote dir (#15964)
Christian Brabandta063b222024-11-07 14:30:30 +010035" 2024 Nov 07 by Vim Project: use keeppatterns to prevent polluting the search history
Tom Benham64a536d2024-11-07 21:15:03 +010036" 2024 Nov 07 by Vim Project: fix a few issues with netrw tree listing (#15996)
Christian Brabandt5b63b232024-11-10 20:22:34 +010037" 2024 Nov 10 by Vim Project: directory symlink not resolved in tree view (#16020)
Konfekt460799d2024-11-14 21:42:27 +010038" 2024 Nov 14 by Vim Project: small fixes to netrw#BrowseX (#16056)
Christian Brabandtcacfccf2024-11-23 13:28:01 +010039" 2024 Nov 23 by Vim Project: update decompress defaults (#16104)
GuyBrushd7745ac2024-11-23 14:13:10 +010040" 2024 Nov 23 by Vim Project: fix powershell escaping issues (#16094)
Konfekteda923e2024-12-04 20:12:44 +010041" 2024 Dec 04 by Vim Project: do not detach for gvim (#16168)
Travis Sheltone34d0e32024-07-30 21:08:56 +020042" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010043" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000044" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010045" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000046" Permission is hereby granted to use and distribute this code,
47" with or without modifications, provided that this copyright
48" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000049" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000050" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000051" expressed or implied. By using this plugin, you agree that
52" in no event will the copyright holder be liable for any damages
53" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010054"
55" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
56" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
57"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020058"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000059"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000060" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000061" (James 1:22 RSV)
62" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000063" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000064if &cp || exists("g:loaded_netrw")
65 finish
66endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020067
68" Check that vim has patches that netrw requires.
69" Patches needed for v7.4: 1557, and 213.
70" (netrw will benefit from vim's having patch#656, too)
71let s:needspatches=[1557,213]
72if exists("s:needspatches")
73 for ptch in s:needspatches
74 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
75 if !exists("s:needpatch{ptch}")
76 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
77 endif
78 let s:needpatch{ptch}= 1
79 finish
80 endif
81 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020082endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020083
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010084let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000085
Bram Moolenaar1afcace2005-11-25 19:54:28 +000086let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010087setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020088"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010089"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010090"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000091
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000092" ======================
93" Netrw Variables: {{{1
94" ======================
95
Bram Moolenaar071d4272004-06-13 20:20:40 +000096" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020097" netrw#ErrorMsg: {{{2
98" 0=note = s:NOTE
99" 1=warning = s:WARNING
100" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100101" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
102" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
103" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +0100104" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200105fun! netrw#ErrorMsg(level,msg,errnum)
106" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
107
108 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200109" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200110 return
111 endif
112
113 if a:level == 1
114 let level= "**warning** (netrw) "
115 elseif a:level == 2
116 let level= "**error** (netrw) "
117 else
118 let level= "**note** (netrw) "
119 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100120" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200121
Damienb4d11642024-08-15 22:00:45 +0200122 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200123 " use popup window
124 if type(a:msg) == 3
125 let msg = [level]+a:msg
126 else
127 let msg= level.a:msg
128 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200129 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200130 let s:popuperr_text= ""
131 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200132 " (default) netrw creates a one-line window to show error/warning
133 " messages (reliably displayed)
134
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100135 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200136 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100137" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200138
139 " getting messages out reliably is just plain difficult!
140 " This attempt splits the current window, creating a one line window.
141 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100142" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200143 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100144" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200145 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100146 if type(a:msg) == 3
147 for msg in a:msg
148 NetrwKeepj call setline(line("$")+1,level.msg)
149 endfor
150 else
151 NetrwKeepj call setline(line("$")+1,level.a:msg)
152 endif
153 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200154 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100155" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200156 bo 1split
157 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200158 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200159 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100160 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100161" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200162 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100163 if type(a:msg) == 3
164 for msg in a:msg
165 NetrwKeepj call setline(line("$")+1,level.msg)
166 endfor
167 else
168 NetrwKeepj call setline(line("$"),level.a:msg)
169 endif
170 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200171 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100172" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200173 if &fo !~ '[ta]'
174 syn clear
175 syn match netrwMesgNote "^\*\*note\*\*"
176 syn match netrwMesgWarning "^\*\*warning\*\*"
177 syn match netrwMesgError "^\*\*error\*\*"
178 hi link netrwMesgWarning WarningMsg
179 hi link netrwMesgError Error
180 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100181" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200182 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200183
184 else
185 " (optional) netrw will show messages using echomsg. Even if the
186 " message doesn't appear, at least it'll be recallable via :messages
187" redraw!
188 if a:level == s:WARNING
189 echohl WarningMsg
190 elseif a:level == s:ERROR
191 echohl Error
192 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100193
194 if type(a:msg) == 3
195 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100196 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100197 endfor
198 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100199 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100200 endif
201
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100202" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200203 echohl None
204 endif
205
206" call Dret("netrw#ErrorMsg")
207endfun
208
209" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100210" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100211" Loosely, varname = value.
212fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100213" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100214 if !exists(a:varname)
215 if type(a:value) == 0
216 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200217 elseif type(a:value) == 1 && a:value =~ '^[{[]'
218 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100219 elseif type(a:value) == 1
220 exe "let ".a:varname."="."'".a:value."'"
221 else
222 exe "let ".a:varname."=".a:value
223 endif
224 endif
225endfun
226
227" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000228" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200229call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000230if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100231 call s:NetrwInit("s:THINLIST",0)
232 call s:NetrwInit("s:LONGLIST",1)
233 call s:NetrwInit("s:WIDELIST",2)
234 call s:NetrwInit("s:TREELIST",3)
235 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000236endif
237
Damien7c754112024-08-15 21:58:57 +0200238let s:NOTE = 0
239let s:WARNING = 1
240let s:ERROR = 2
241call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
242
Bram Moolenaar9964e462007-05-05 17:54:07 +0000243" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200244" Default option values: {{{2
245let g:netrw_localcopycmdopt = ""
246let g:netrw_localcopydircmdopt = ""
247let g:netrw_localmkdiropt = ""
248let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200249
250" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000251" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200252if exists("*popup_atcursor")
253\ && has("syntax")
254\ && exists("g:syntax_on")
255\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200256 call s:NetrwInit("g:netrw_use_errorwindow",2)
257else
258 call s:NetrwInit("g:netrw_use_errorwindow",1)
259endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200260
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000261if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100262 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000263 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100264 elseif executable("curl")
265 let g:netrw_dav_cmd = "curl"
266 else
267 let g:netrw_dav_cmd = ""
268 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000270if !exists("g:netrw_fetch_cmd")
271 if executable("fetch")
272 let g:netrw_fetch_cmd = "fetch -o"
273 else
274 let g:netrw_fetch_cmd = ""
275 endif
276endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100277if !exists("g:netrw_file_cmd")
278 if executable("elinks")
279 call s:NetrwInit("g:netrw_file_cmd","elinks")
280 elseif executable("links")
281 call s:NetrwInit("g:netrw_file_cmd","links")
282 endif
283endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000284if !exists("g:netrw_ftp_cmd")
285 let g:netrw_ftp_cmd = "ftp"
286endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200287let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200288if !exists("g:netrw_ftp_options")
289 let g:netrw_ftp_options= "-i -n"
290endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000291if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100292 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100293 let g:netrw_http_cmd = "wget"
294 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100295 elseif executable("curl")
296 let g:netrw_http_cmd = "curl"
297 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200298 elseif executable("elinks")
299 let g:netrw_http_cmd = "elinks"
300 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000301 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100302 let g:netrw_http_cmd = "fetch"
303 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200304 elseif executable("links")
305 let g:netrw_http_cmd = "links"
306 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000307 else
308 let g:netrw_http_cmd = ""
309 endif
310endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100311call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100312call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100313call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
314call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200315call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200316if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200317 if executable("scp")
318 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
319 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200320 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200321 else
322 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
323 endif
324endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100325call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
326call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000327
Nir Lichtman1e34b952024-05-08 19:19:34 +0200328if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000329 \ && exists("g:netrw_use_nt_rcp")
330 \ && g:netrw_use_nt_rcp
331 \ && executable( $SystemRoot .'/system32/rcp.exe')
332 let s:netrw_has_nt_rcp = 1
333 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000334else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000335 let s:netrw_has_nt_rcp = 0
336 let s:netrw_rcpmode = ''
337endif
338
339" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000340" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000341" Cygwin Detection ------- {{{3
342if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200343 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
344 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000345 else
346 let g:netrw_cygwin= 0
347 endif
348endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000349" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100350call s:NetrwInit("g:netrw_alto" , &sb)
351call s:NetrwInit("g:netrw_altv" , &spr)
352call s:NetrwInit("g:netrw_banner" , 1)
353call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200354call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100355call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200356call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100357call s:NetrwInit("g:netrw_compress" , "gzip")
358call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200359if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
360 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
361 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000362endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200363call s:NetrwInit("g:netrw_cursor" , 2)
364let s:netrw_usercul = &cursorline
365let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200366"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100367call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000368" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200369call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200370call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Christian Brabandtcacfccf2024-11-23 13:28:01 +0100371let s:xz_opt = has('unix') ? "XZ_OPT=-T0" :
372 \ (has("win32") && &shell =~? '\vcmd(\.exe)?$' ?
373 \ "setx XZ_OPT=-T0 &&" : "")
374call s:NetrwInit("g:netrw_decompress ", "{"
375 \ .."'.lz4': 'lz4 -d',"
376 \ .."'.lzo': 'lzop -d',"
377 \ .."'.lz': 'lzip -dk',"
378 \ .."'.7z': '7za x',"
379 \ .."'.001': '7za x',"
380 \ .."'.zip': 'unzip',"
381 \ .."'.bz': 'bunzip2 -k',"
382 \ .."'.bz2': 'bunzip2 -k',"
383 \ .."'.gz': 'gunzip -k',"
384 \ .."'.lzma': 'unlzma -T0 -k',"
385 \ .."'.xz': 'unxz -T0 -k',"
386 \ .."'.zst': 'zstd -T0 -d',"
387 \ .."'.Z': 'uncompress -k',"
388 \ .."'.tar': 'tar -xvf',"
389 \ .."'.tar.bz': 'tar -xvjf',"
390 \ .."'.tar.bz2': 'tar -xvjf',"
391 \ .."'.tbz': 'tar -xvjf',"
392 \ .."'.tbz2': 'tar -xvjf',"
393 \ .."'.tar.gz': 'tar -xvzf',"
394 \ .."'.tgz': 'tar -xvzf',"
395 \ .."'.tar.lzma': '"..s:xz_opt.." tar -xvf --lzma',"
396 \ .."'.tlz': '"..s:xz_opt.." tar -xvf --lzma',"
397 \ .."'.tar.xz': '"..s:xz_opt.." tar -xvfJ',"
398 \ .."'.txz': '"..s:xz_opt.." tar -xvfJ',"
399 \ .."'.tar.zst': '"..s:xz_opt.." tar -xvf --use-compress-program=unzstd',"
400 \ .."'.tzst': '"..s:xz_opt.." tar -xvf --use-compress-program=unzstd',"
401 \ .."'.rar': '"..(executable("unrar")?"unrar x -ad":"rar x -ad").."'"
402 \ .."}")
403unlet s:xz_opt
Bram Moolenaar5c736222010-01-06 20:54:52 +0100404call s:NetrwInit("g:netrw_dirhistmax" , 10)
405call s:NetrwInit("g:netrw_fastbrowse" , 1)
406call 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 +0000407if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000408 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
409 let g:netrw_ftp_list_cmd = "ls -lF"
410 let g:netrw_ftp_timelist_cmd = "ls -tlF"
411 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000412 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000413 let g:netrw_ftp_list_cmd = "dir"
414 let g:netrw_ftp_timelist_cmd = "dir"
415 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000416 endif
417endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100418call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000419" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100420call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000421if !exists("g:netrw_ignorenetrc")
422 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
423 let g:netrw_ignorenetrc= 1
424 else
425 let g:netrw_ignorenetrc= 0
426 endif
427endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100428call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000429if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000430 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100431 if exists("g:netrw_list_cmd_options")
432 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
433 else
434 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
435 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000436 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200437 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100438 if exists("g:netrw_list_cmd_options")
439 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
440 else
441 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
442 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000443 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100444" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000445 let g:netrw_list_cmd= ""
446 endif
447endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100448call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000449" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200450if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200451 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200452 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
453endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100454if !exists("g:netrw_localcmdshell")
455 let g:netrw_localcmdshell= ""
456endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000457if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200458 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000459 if g:netrw_cygwin
460 let g:netrw_localcopycmd= "cp"
461 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000462 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200463 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000464 endif
465 elseif has("unix") || has("macunix")
466 let g:netrw_localcopycmd= "cp"
467 else
468 let g:netrw_localcopycmd= ""
469 endif
470endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100471if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200472 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100473 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200474 let g:netrw_localcopydircmd = "cp"
475 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100476 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000477 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200478 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100479 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200480 elseif has("unix")
481 let g:netrw_localcopydircmd = "cp"
482 let g:netrw_localcopydircmdopt= " -R"
483 elseif has("macunix")
484 let g:netrw_localcopydircmd = "cp"
485 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100486 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200487 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100488 endif
489endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200490if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100491 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200492 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
493endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200494if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200495 if g:netrw_cygwin
496 call s:NetrwInit("g:netrw_localmkdir","mkdir")
497 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000498 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200499 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200500 endif
501else
502 call s:NetrwInit("g:netrw_localmkdir","mkdir")
503endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200504call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200505if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200506 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200507 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
508endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000509if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200510 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000511 if g:netrw_cygwin
512 let g:netrw_localmovecmd= "mv"
513 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000514 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200515 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000516 endif
517 elseif has("unix") || has("macunix")
518 let g:netrw_localmovecmd= "mv"
519 else
520 let g:netrw_localmovecmd= ""
521 endif
522endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100523" following serves as an example for how to insert a version&patch specific test
524"if v:version < 704 || (v:version == 704 && !has("patch1107"))
525"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100526call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
527" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000528if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000529 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000530endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000531if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000532 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
533endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000534" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100535call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
536call s:NetrwInit("g:netrw_maxfilenamelen", 32)
537call s:NetrwInit("g:netrw_menu" , 1)
538call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200539call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100540call s:NetrwInit("g:netrw_retmap" , 0)
541if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
542 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200543elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100544 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
545else
546 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000547endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100548call s:NetrwInit("g:netrw_preview" , 0)
549call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100550call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100551call s:NetrwInit("g:netrw_sshport" , "-p")
552call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
553call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
554call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100555call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
556" Default values - q-s ---------- {{{3
557call s:NetrwInit("g:netrw_quickhelp",0)
558let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100559 \ "(create new) %:file d:directory",
560 \ "(windows split&open) o:horz v:vert p:preview",
561 \ "i:style qf:file info O:obtain r:reverse",
562 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
563 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
564 \ "(history) qb:list u:go up U:go down",
565 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100566" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
567call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100568if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
569 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
570else
571 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
572endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100573call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
574call s:NetrwInit("g:netrw_sort_options" , "")
575call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000576if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100577 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200578 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100579 else
580 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000581 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000582endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100583call s:NetrwInit("g:netrw_special_syntax" , 0)
584call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100585call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100586call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000587" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100588call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200589if !exists("g:netrw_xstrlen")
590 if exists("g:Align_xstrlen")
591 let g:netrw_xstrlen= g:Align_xstrlen
592 elseif exists("g:drawit_xstrlen")
593 let g:netrw_xstrlen= g:drawit_xstrlen
594 elseif &enc == "latin1" || !has("multi_byte")
595 let g:netrw_xstrlen= 0
596 else
597 let g:netrw_xstrlen= 1
598 endif
599endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100600call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200601call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100602call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200603if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000604" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000605" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100606call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200607if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200608 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200609else
Bram Moolenaarff034192013-04-24 18:51:19 +0200610 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200611endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200612call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100613call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
614call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100615if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100616 let s:treedepthstring= "│ "
617else
618 let s:treedepthstring= "| "
619endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200620call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000621
622" BufEnter event ignored by decho when following variable is true
623" Has a side effect that doau BufReadPost doesn't work, so
624" files read by network transfer aren't appropriately highlighted.
625"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626
Bram Moolenaaradc21822011-04-01 18:03:16 +0200627" ======================
628" Netrw Initialization: {{{1
629" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200630if 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 +0100631" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100632 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200633" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100634 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100635 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
636 au VimEnter * let s:initbeval= &beval
637"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100638" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
639" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
640" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
641" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
642" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
643" 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 +0200644endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200645au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200646
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200647if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100648 com! -nargs=* NetrwKeepj keepj <args>
649else
650 let g:netrw_keepj= ""
651 com! -nargs=* NetrwKeepj <args>
652endif
653
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000654" ==============================
655" Netrw Utility Functions: {{{1
656" ==============================
657
Bram Moolenaaradc21822011-04-01 18:03:16 +0200658" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100659" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100660if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100661" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100662 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100663 if &ft != "netrw"
664 return ""
665 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200666 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
667 " popup error window is still showing
668 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
669 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
670 " text under mouse hasn't changed; only close window when it changes
671 call popup_close(s:popuperr_id)
672 unlet s:popuperr_text
673 else
674 let s:popuperr_text= v:beval_text
675 endif
676 let mesg= ""
677 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 +0100678 let mesg= ""
679 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
680 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
681 elseif getline(v:beval_lnum) =~ '^"\s*/'
682 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
683 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100684 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100685 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
686 let mesg = "S: edit sorting sequence"
687 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
688 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
689 elseif v:beval_text == "Quick" || v:beval_text == "Help"
690 let mesg = "Help: press <F1>"
691 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
692 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
693 else
694 let mesg= ""
695 endif
696 return mesg
697 endfun
698"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100699" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
700" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
701" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
702" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
703" 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 +0200704endif
705
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200707" netrw#Explore: launch the local browser in the directory of the current file {{{2
708" indx: == -1: Nexplore
709" == -2: Pexplore
710" == +: this is overloaded:
711" * If Nexplore/Pexplore is in use, then this refers to the
712" indx'th item in the w:netrw_explore_list[] of items which
713" matched the */pattern **/pattern *//pattern **//pattern
714" * If Hexplore or Vexplore, then this will override
715" g:netrw_winsize to specify the qty of rows or columns the
716" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100717" 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 +0200718" dosplit==1: the window will be split before running the local browser
719" style == 0: Explore style == 1: Explore!
720" == 2: Hexplore style == 3: Hexplore!
721" == 4: Vexplore style == 5: Vexplore!
722" == 6: Texplore
723fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaarff034192013-04-24 18:51:19 +0200724 if !exists("b:netrw_curdir")
725 let b:netrw_curdir= getcwd()
Bram Moolenaarff034192013-04-24 18:51:19 +0200726 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100727
728 " record current file for Rexplore's benefit
729 if &ft != "netrw"
730 let w:netrw_rexfile= expand("%:p")
731 endif
732
733 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200734 let curdir = simplify(b:netrw_curdir)
735 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200736 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200737 let curdir= substitute(curdir,'\','/','g')
738 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100739
740 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
741 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
742 " try Explore again.
743 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100744 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200745 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
746 if a1 != a:1
747 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
748 return
749 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100750 endif
751 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200752
753 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200754 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100755" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100756 sil! let keepregstar = @*
757 sil! let keepregplus = @+
758 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200759 sil! let keepregslash= @/
760
Bram Moolenaar8d043172014-01-23 14:24:41 +0100761 " if dosplit
762 " -or- file has been modified AND file not hidden when abandoned
763 " -or- Texplore used
764 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200765 call s:SaveWinVars()
766 let winsz= g:netrw_winsize
767 if a:indx > 0
768 let winsz= a:indx
769 endif
770
771 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200772 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200773 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200774 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200775
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200776 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200778 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200779 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200780
781 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200783 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200784 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200785
786 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200788 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200789 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200790
791 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200792 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200793 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200794 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200795
796 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200797 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200798 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200799 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200800
801 elseif a:style == 6 " Texplore
802 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200803 exe "keepalt tabnew ".fnameescape(curdir)
804 call s:RestoreBufVars()
805 endif
806 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200807 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100808 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200809
810 if a:0 > 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200811 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaarff034192013-04-24 18:51:19 +0200812 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaarff034192013-04-24 18:51:19 +0200813 elseif a:1 == '.'
Bram Moolenaarff034192013-04-24 18:51:19 +0200814 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
815 if dirname !~ '/$'
816 let dirname= dirname."/"
817 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200818 elseif a:1 =~ '\$'
Bram Moolenaarff034192013-04-24 18:51:19 +0200819 let dirname= simplify(expand(a:1))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200820 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaarff034192013-04-24 18:51:19 +0200821 let dirname= simplify(a:1)
Bram Moolenaarff034192013-04-24 18:51:19 +0200822 else
Bram Moolenaarff034192013-04-24 18:51:19 +0200823 let dirname= a:1
824 endif
825 else
826 " clear explore
Bram Moolenaarff034192013-04-24 18:51:19 +0200827 call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200828 return
829 endif
830
Bram Moolenaarff034192013-04-24 18:51:19 +0200831 if dirname =~ '\.\./\=$'
832 let dirname= simplify(fnamemodify(dirname,':p:h'))
833 elseif dirname =~ '\.\.' || dirname == '.'
834 let dirname= simplify(fnamemodify(dirname,':p'))
835 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200836
837 if dirname =~ '^\*//'
838 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200839 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
840 let starpat= 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200841 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
842
843 elseif dirname =~ '^\*\*//'
844 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200845 let pattern= substitute(dirname,'^\*\*//','','')
846 let starpat= 2
Bram Moolenaarff034192013-04-24 18:51:19 +0200847
848 elseif dirname =~ '/\*\*/'
849 " handle .../**/.../filepat
Bram Moolenaarff034192013-04-24 18:51:19 +0200850 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200851 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200852 let b:netrw_curdir = prefixdir
853 else
854 let b:netrw_curdir= getcwd().'/'.prefixdir
855 endif
856 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
857 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200858
859 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200860 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200861 let starpat= 3
Bram Moolenaarff034192013-04-24 18:51:19 +0200862
863 elseif dirname=~ '^\*\*/'
864 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
865 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200866
867 else
868 let starpat= 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200869 endif
870
871 if starpat == 0 && a:indx >= 0
872 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaarff034192013-04-24 18:51:19 +0200873 if dirname == ""
874 let dirname= curfiledir
Bram Moolenaarff034192013-04-24 18:51:19 +0200875 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200876 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200877 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200878 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200879 if dirname == ""
880 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200881 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100882 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100883 " depending on whether backslashes have been converted to forward slashes by earlier code).
884 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200885 let dirname= b:netrw_curdir."/".dirname
886 endif
887 elseif dirname !~ '^/'
888 let dirname= b:netrw_curdir."/".dirname
889 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200890 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200891 endif
892 if exists("w:netrw_bannercnt")
893 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
894 " If one wants to return the same place in the netrw window, use :Rex instead.
895 exe w:netrw_bannercnt
896 endif
897
Bram Moolenaarff034192013-04-24 18:51:19 +0200898
899 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
900 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
901 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
902 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
903 elseif a:indx <= 0
904 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaarff034192013-04-24 18:51:19 +0200905 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200906 let s:didstarstar= 1
907 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
908 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
909 endif
910
911 if has("path_extra")
Bram Moolenaarff034192013-04-24 18:51:19 +0200912 if !exists("w:netrw_explore_indx")
913 let w:netrw_explore_indx= 0
914 endif
915
916 let indx = a:indx
Bram Moolenaarff034192013-04-24 18:51:19 +0200917
918 if indx == -1
919 " Nexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200920 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100921 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 +0200922 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100923 if @* != keepregstar | sil! let @* = keepregstar | endif
924 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100925 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200926 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200927 return
928 endif
929 let indx= w:netrw_explore_indx
930 if indx < 0 | let indx= 0 | endif
931 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
932 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200933 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
934 let indx= indx + 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200935 endwhile
936 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200937
938 elseif indx == -2
939 " Pexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200940 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100941 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 +0200942 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100943 if @* != keepregstar | sil! let @* = keepregstar | endif
944 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100945 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200946 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200947 return
948 endif
949 let indx= w:netrw_explore_indx
950 if indx < 0 | let indx= 0 | endif
951 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
952 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200953 while indx >= 0 && curfile == w:netrw_explore_list[indx]
954 let indx= indx - 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200955 endwhile
956 if indx < 0 | let indx= 0 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200957
958 else
959 " Explore -- initialize
960 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100961 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200962 let w:netrw_explore_indx= 0
963 if !exists("b:netrw_curdir")
964 let b:netrw_curdir= getcwd()
965 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200966
967 " switch on starpat to build the w:netrw_explore_list of files
968 if starpat == 1
969 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200970 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100971 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200972 catch /^Vim\%((\a\+)\)\=:E480/
973 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +0200974 return
975 endtry
976 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
977 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
978
979 elseif starpat == 2
980 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200981 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100982 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200983 catch /^Vim\%((\a\+)\)\=:E480/
984 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
985 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200986 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100987 if @* != keepregstar | sil! let @* = keepregstar | endif
988 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100989 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200990 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200991 return
992 endtry
993 let s:netrw_curdir = b:netrw_curdir
994 let w:netrw_explore_list = getqflist()
995 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
996 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
997
998 elseif starpat == 3
999 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +02001000 let filepat= substitute(dirname,'^\*/','','')
1001 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaarff034192013-04-24 18:51:19 +02001002 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1003 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1004
1005 elseif starpat == 4
1006 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +02001007 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1008 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1009 endif " switch on starpat to build w:netrw_explore_list
1010
1011 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaarff034192013-04-24 18:51:19 +02001012
1013 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001014 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001015 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001016 if @* != keepregstar | sil! let @* = keepregstar | endif
1017 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001018 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001019 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001020 return
1021 endif
1022 endif " if indx ... endif
1023
1024 " NetrwStatusLine support - for exploring support
1025 let w:netrw_explore_indx= indx
Bram Moolenaarff034192013-04-24 18:51:19 +02001026
1027 " wrap the indx around, but issue a note
1028 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaarff034192013-04-24 18:51:19 +02001029 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1030 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001031 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001032 endif
1033
1034 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaarff034192013-04-24 18:51:19 +02001035 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaarff034192013-04-24 18:51:19 +02001036
Bram Moolenaarff034192013-04-24 18:51:19 +02001037 call netrw#LocalBrowseCheck(newdir)
1038 if !exists("w:netrw_liststyle")
1039 let w:netrw_liststyle= g:netrw_liststyle
1040 endif
1041 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001042 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001043 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001044 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001045 endif
1046 let w:netrw_explore_mtchcnt = indx + 1
1047 let w:netrw_explore_bufnr = bufnr("%")
1048 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001049 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaarff034192013-04-24 18:51:19 +02001050
1051 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001052 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001053 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 +02001054 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001055 if has("clipboard") && g:netrw_clipboard
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
Bram Moolenaarff034192013-04-24 18:51:19 +02001060 return
1061 endif
1062
1063 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001064 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1065 sil! unlet w:netrw_treedict
1066 sil! unlet w:netrw_treetop
1067 endif
1068 let newdir= dirname
1069 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001070 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001071 else
Tom Benham64a536d2024-11-07 21:15:03 +01001072 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02001073 endif
1074 endif
1075
1076 " visual display of **/ **// */ Exploration files
Bram Moolenaarff034192013-04-24 18:51:19 +02001077 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +02001078 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001079 " only update match list when current directory isn't the same as before
Bram Moolenaarff034192013-04-24 18:51:19 +02001080 let s:explore_prvdir = b:netrw_curdir
1081 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001082 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001083 if b:netrw_curdir !~ '/$'
1084 let dirlen= dirlen + 1
1085 endif
1086 let prvfname= ""
1087 for fname in w:netrw_explore_list
Bram Moolenaarff034192013-04-24 18:51:19 +02001088 if fname =~ '^'.b:netrw_curdir
1089 if s:explore_match == ""
1090 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1091 else
1092 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1093 endif
1094 elseif fname !~ '^/' && fname != prvfname
1095 if s:explore_match == ""
1096 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1097 else
1098 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1099 endif
1100 endif
1101 let prvfname= fname
1102 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02001103 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1104 exe "2match netrwMarkFile /".s:explore_match."/"
1105 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001106 endif
1107 echo "<s-up>==Pexplore <s-down>==Nexplore"
1108 else
1109 2match none
1110 if exists("s:explore_match") | unlet s:explore_match | endif
1111 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001112 endif
1113
Bram Moolenaara6878372014-03-22 21:02:50 +01001114 " since Explore may be used to initialize netrw's browser,
1115 " there's no danger of a late FocusGained event on initialization.
1116 " Consequently, set s:netrw_events to 2.
1117 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001118 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001119 if @* != keepregstar | sil! let @* = keepregstar | endif
1120 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001121 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001122 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001123endfun
1124
1125" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001126" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001127" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1128" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1129" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1130" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1131" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001132fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001133" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001134 let curwin= winnr()
1135
Bram Moolenaara6878372014-03-22 21:02:50 +01001136 if a:0 > 0 && a:1 != ""
1137 " if a netrw window is already on the left-side of the tab
1138 " and a directory has been specified, explore with that
1139 " directory.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001140 let a1 = expand(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01001141 exe "1wincmd w"
1142 if &ft == "netrw"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001143 exe "Explore ".fnameescape(a1)
1144 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001145 let s:lexplore_win= curwin
1146 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001147 if exists("t:netrw_lexposn")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001148 unlet t:netrw_lexposn
1149 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001150 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001151 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001152 exe curwin."wincmd w"
1153 else
1154 let a1= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001155 endif
1156
Bram Moolenaar8d043172014-01-23 14:24:41 +01001157 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001158 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001159 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001160 else
1161 let lexwinnr= 0
1162 endif
1163
1164 if lexwinnr > 0
1165 " close down netrw explorer window
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001166 exe lexwinnr."wincmd w"
1167 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001168 let t:netrw_lexposn = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001169 close
1170 if lexwinnr < curwin
1171 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001172 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001173 if lexwinnr != curwin
1174 exe curwin."wincmd w"
1175 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001176 unlet t:netrw_lexbufnr
1177
1178 else
1179 " open netrw explorer window
1180 exe "1wincmd w"
1181 let keep_altv = g:netrw_altv
1182 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001183 if a:count != 0
1184 let netrw_winsize = g:netrw_winsize
1185 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001186 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001187 let curfile= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001188 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
1189 if a:0 > 0 && a1 != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001190 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001191 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001192 elseif curfile =~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02001193 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001194 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02001195 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001196 endif
1197 if a:count != 0
1198 let g:netrw_winsize = netrw_winsize
1199 endif
1200 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001201 let g:netrw_altv = keep_altv
1202 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001203 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1204 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001205 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001206 set bh=wipe
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207 if exists("t:netrw_lexposn")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001208 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001209 unlet t:netrw_lexposn
1210 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001211 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001212
1213 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001214 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001215 if a:rightside
1216 let g:netrw_chgwin= 1
1217 else
1218 let g:netrw_chgwin= 2
1219 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001220 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001221
Bram Moolenaar8d043172014-01-23 14:24:41 +01001222endfun
1223
1224" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001225" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001226" supports :NetrwClean -- remove netrw from first directory on runtimepath
1227" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001228fun! netrw#Clean(sys)
1229" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001230
1231 if a:sys
1232 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1233 else
1234 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1235 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001236" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001237 let diddel= 0
1238 let diddir= ""
1239
1240 if choice == 1
1241 for dir in split(&rtp,',')
1242 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001243" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001244 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1245 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1246 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1247 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1248 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1249 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 +00001250 let diddir= dir
1251 let diddel= diddel + 1
1252 if !a:sys|break|endif
1253 endif
1254 endfor
1255 endif
1256
1257 echohl WarningMsg
1258 if diddel == 0
1259 echomsg "netrw is either not installed or not removable"
1260 elseif diddel == 1
1261 echomsg "removed one copy of netrw from <".diddir.">"
1262 else
1263 echomsg "removed ".diddel." copies of netrw"
1264 endif
1265 echohl None
1266
Bram Moolenaara6878372014-03-22 21:02:50 +01001267" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001268endfun
1269
Bram Moolenaar5c736222010-01-06 20:54:52 +01001270" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001271" netrw#MakeTgt: make a target out of the directory name provided {{{2
1272fun! netrw#MakeTgt(dname)
1273" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1274 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001275 let svpos = winsaveview()
1276" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001277 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1278" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001279 if s:netrwmftgt_islocal
1280 let netrwmftgt= simplify(a:dname)
1281 else
1282 let netrwmftgt= a:dname
1283 endif
1284 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1285 " re-selected target, so just clear it
1286 unlet s:netrwmftgt s:netrwmftgt_islocal
1287 else
1288 let s:netrwmftgt= netrwmftgt
1289 endif
1290 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001291 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001292 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001293" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1294 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001295" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001296endfun
1297
Bram Moolenaara6878372014-03-22 21:02:50 +01001298" ---------------------------------------------------------------------
1299" netrw#Obtain: {{{2
1300" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001301" islocal=0 obtain from remote source
1302" =1 obtain from local source
1303" fname : a filename or a list of filenames
1304" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001305fun! netrw#Obtain(islocal,fname,...)
1306" 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 +02001307 " NetrwStatusLine support - for obtaining support
1308
1309 if type(a:fname) == 1
1310 let fnamelist= [ a:fname ]
1311 elseif type(a:fname) == 3
1312 let fnamelist= a:fname
1313 else
1314 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 +01001315" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001316 return
1317 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001318" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001319 if a:0 > 0
1320 let tgtdir= a:1
1321 else
1322 let tgtdir= getcwd()
1323 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001324" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001325
1326 if exists("b:netrw_islocal") && b:netrw_islocal
1327 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001328" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001329 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1330 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001331 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001332 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001333" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001334 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001335" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001336 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001337 if v:shell_error != 0
1338 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 +01001339" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001340 return
1341 endif
1342 endfor
1343 else
1344 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001345" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1346 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1347" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001348 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001349 if v:shell_error != 0
1350 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 +01001351" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001352 return
1353 endif
1354 endif
1355 elseif !exists("b:netrw_curdir")
1356 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1357 else
1358 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1359 endif
1360
1361 else
1362 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001363" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001364 if type(a:fname) == 1
1365 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1366 endif
1367 call s:NetrwMethod(b:netrw_curdir)
1368
1369 if b:netrw_method == 4
1370 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001371" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001372 if exists("g:netrw_port") && g:netrw_port != ""
1373 let useport= " ".g:netrw_scpport." ".g:netrw_port
1374 else
1375 let useport= ""
1376 endif
1377 if b:netrw_fname =~ '/'
1378 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1379 else
1380 let path= ""
1381 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001382 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001383 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 +02001384
1385 elseif b:netrw_method == 2
1386 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001387" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001388 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001389 let tmpbufnr= bufnr("%")
1390 setl ff=unix
1391 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001392 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001393" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001394 endif
1395
1396 if exists("b:netrw_fname") && b:netrw_fname != ""
1397 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001398" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001399 endif
1400
1401 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001402 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001403" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001404 endif
1405 for fname in fnamelist
1406 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001407" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001408 endfor
1409 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001410 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 +02001411 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001412 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001413 endif
1414 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1415 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1416 let debugkeep= &debug
1417 setl debug=msg
1418 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1419 let &debug= debugkeep
1420 endif
1421
1422 elseif b:netrw_method == 3
1423 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001424" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001425 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001426 let tmpbufnr= bufnr("%")
1427 setl ff=unix
1428
1429 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001430 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001431" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001432 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001433 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001434" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001435 endif
1436
1437 if exists("g:netrw_uid") && g:netrw_uid != ""
1438 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001439 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001440" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001441 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001442 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001443 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001444" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001445 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001446 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001447" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001448 endif
1449 endif
1450
1451 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001452 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001453" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001454 endif
1455
1456 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001457 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001458" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001459 endif
1460
1461 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001462 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001463" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001464 endif
1465
1466 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001467 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001468" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001469 endif
1470 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001471 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001472 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001473" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001474
1475 " perform ftp:
1476 " -i : turns off interactive prompting from ftp
1477 " -n unix : DON'T use <.netrc>, even though it exists
1478 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001479 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1480 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001481 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001482 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1483 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001484" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001485 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001486 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001487 endif
1488 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001489
1490 elseif b:netrw_method == 9
1491 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001492" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001493 if a:fname =~ '/'
1494 let localfile= substitute(a:fname,'^.*/','','')
1495 else
1496 let localfile= a:fname
1497 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001498 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 +02001499
Bram Moolenaarff034192013-04-24 18:51:19 +02001500 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001501 " probably a badly formed url; protocol not recognized
1502" call Dret("netrw#Obtain : unsupported method")
1503 return
1504
1505 else
1506 " protocol recognized but not supported for Obtain (yet?)
1507 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001508 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001509 endif
1510" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001511 return
1512 endif
1513
1514 " restore status line
1515 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001516 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001517 endif
1518
1519 endif
1520
1521 " cleanup
1522 if exists("tmpbufnr")
1523 if bufnr("%") != tmpbufnr
1524 exe tmpbufnr."bw!"
1525 else
1526 q!
1527 endif
1528 endif
1529
Bram Moolenaara6878372014-03-22 21:02:50 +01001530" call Dret("netrw#Obtain")
1531endfun
1532
1533" ---------------------------------------------------------------------
1534" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1535fun! netrw#Nread(mode,fname)
1536" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001537 let svpos= winsaveview()
1538" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001539 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001540" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1541 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001542
1543 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1544 if exists("w:netrw_bannercnt")
1545 " start with cursor just after the banner
1546 exe w:netrw_bannercnt
1547 endif
1548 endif
1549" call Dret("netrw#Nread")
1550endfun
1551
1552" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001553" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1554" Options get restored by s:NetrwOptionsRestore()
1555"
1556" Option handling:
1557" * save user's options (s:NetrwOptionsSave)
1558" * set netrw-safe options (s:NetrwOptionsSafe)
1559" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1560" * restore user's options (s:netrwOPtionsRestore)
1561" - restore a user option when != safe option (s:NetrwRestoreSetting)
1562" vt: (variable type) normally its either "w:" or "s:"
1563fun! s:NetrwOptionsSave(vt)
1564" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1565" 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 +02001566" 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>"))
1567" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001568
1569 if !exists("{a:vt}netrw_optionsave")
1570 let {a:vt}netrw_optionsave= 1
1571 else
1572" call Dret("s:NetrwOptionsSave : options already saved")
1573 return
1574 endif
1575" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1576
1577 " Save current settings and current directory
1578" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1579 let s:yykeep = @@
1580 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1581 let {a:vt}netrw_aikeep = &l:ai
1582 let {a:vt}netrw_awkeep = &l:aw
1583 let {a:vt}netrw_bhkeep = &l:bh
1584 let {a:vt}netrw_blkeep = &l:bl
1585 let {a:vt}netrw_btkeep = &l:bt
1586 let {a:vt}netrw_bombkeep = &l:bomb
1587 let {a:vt}netrw_cedit = &cedit
1588 let {a:vt}netrw_cikeep = &l:ci
1589 let {a:vt}netrw_cinkeep = &l:cin
1590 let {a:vt}netrw_cinokeep = &l:cino
1591 let {a:vt}netrw_comkeep = &l:com
1592 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001593 let {a:vt}netrw_cuckeep = &l:cuc
1594 let {a:vt}netrw_culkeep = &l:cul
1595" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001596 let {a:vt}netrw_diffkeep = &l:diff
1597 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001598 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1599 let {a:vt}netrw_ffkeep = &l:ff
1600 endif
1601 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1602 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001603 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001604 let {a:vt}netrw_hidkeep = &l:hidden
1605 let {a:vt}netrw_imkeep = &l:im
1606 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001607 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001608 let {a:vt}netrw_lskeep = &l:ls
1609 let {a:vt}netrw_makeep = &l:ma
1610 let {a:vt}netrw_magickeep = &l:magic
1611 let {a:vt}netrw_modkeep = &l:mod
1612 let {a:vt}netrw_nukeep = &l:nu
1613 let {a:vt}netrw_rnukeep = &l:rnu
1614 let {a:vt}netrw_repkeep = &l:report
1615 let {a:vt}netrw_rokeep = &l:ro
1616 let {a:vt}netrw_selkeep = &l:sel
1617 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001618 if !g:netrw_use_noswf
1619 let {a:vt}netrw_swfkeep = &l:swf
1620 endif
1621 let {a:vt}netrw_tskeep = &l:ts
1622 let {a:vt}netrw_twkeep = &l:tw " textwidth
1623 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1624 let {a:vt}netrw_wrapkeep = &l:wrap
1625 let {a:vt}netrw_writekeep = &l:write
1626
1627 " save a few selected netrw-related variables
1628" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1629 if g:netrw_keepdir
1630 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001631" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001632 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001633 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001634 sil! let {a:vt}netrw_starkeep = @*
1635 sil! let {a:vt}netrw_pluskeep = @+
1636 endif
1637 sil! let {a:vt}netrw_slashkeep= @/
1638
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001639" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001640" 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>"))
1641" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1642endfun
1643
1644" ---------------------------------------------------------------------
1645" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1646" Use s:NetrwSaveOptions() to save user settings
1647" Use s:NetrwOptionsRestore() to restore user settings
1648fun! s:NetrwOptionsSafe(islocal)
1649" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1650" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1651" 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>"))
1652 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1653 call s:NetrwSetSafeSetting("&l:ai",0)
1654 call s:NetrwSetSafeSetting("&l:aw",0)
1655 call s:NetrwSetSafeSetting("&l:bl",0)
1656 call s:NetrwSetSafeSetting("&l:bomb",0)
1657 if a:islocal
1658 call s:NetrwSetSafeSetting("&l:bt","nofile")
1659 else
1660 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1661 endif
1662 call s:NetrwSetSafeSetting("&l:ci",0)
1663 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001664 if g:netrw_fastbrowse > a:islocal
1665 call s:NetrwSetSafeSetting("&l:bh","hide")
1666 else
1667 call s:NetrwSetSafeSetting("&l:bh","delete")
1668 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001669 call s:NetrwSetSafeSetting("&l:cino","")
1670 call s:NetrwSetSafeSetting("&l:com","")
1671 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1672 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1673 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001674 if &go =~ 'a' | set go-=a | endif
1675 if &go =~ 'A' | set go-=A | endif
1676 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001677 call s:NetrwSetSafeSetting("&l:hid",0)
1678 call s:NetrwSetSafeSetting("&l:im",0)
1679 setl isk+=@ isk+=* isk+=/
1680 call s:NetrwSetSafeSetting("&l:magic",1)
1681 if g:netrw_use_noswf
1682 call s:NetrwSetSafeSetting("swf",0)
1683 endif
1684 call s:NetrwSetSafeSetting("&l:report",10000)
1685 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1686 call s:NetrwSetSafeSetting("&l:spell",0)
1687 call s:NetrwSetSafeSetting("&l:tw",0)
1688 call s:NetrwSetSafeSetting("&l:wig","")
1689 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001690
1691 " set up cuc and cul based on g:netrw_cursor and listing style
1692 " COMBAK -- cuc cul related
1693 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001694
1695 " allow the user to override safe options
1696" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1697 if &ft == "netrw"
1698" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1699 keepalt NetrwKeepj doau FileType netrw
1700 endif
1701
1702" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1703" 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>"))
1704" call Dret("s:NetrwOptionsSafe")
1705endfun
1706
1707" ---------------------------------------------------------------------
1708" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1709fun! s:NetrwOptionsRestore(vt)
Bram Moolenaara6878372014-03-22 21:02:50 +01001710 if !exists("{a:vt}netrw_optionsave")
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +01001711 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab)
1712 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match
1713 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+'
Bram Moolenaar71badf92023-04-22 22:40:14 +01001714 filetype detect
Bram Moolenaar71badf92023-04-22 22:40:14 +01001715 else
1716 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001717 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001718 return
1719 endif
1720 unlet {a:vt}netrw_optionsave
1721
1722 if exists("+acd")
1723 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara6878372014-03-22 21:02:50 +01001724 let curdir = getcwd()
1725 let &l:acd = {a:vt}netrw_acdkeep
1726 unlet {a:vt}netrw_acdkeep
1727 if &l:acd
1728 call s:NetrwLcd(curdir)
1729 endif
1730 endif
1731 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001732 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1733 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1734 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1735 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1736 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1737 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1738 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1739 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1740 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1741 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1742 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1743 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1744 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1745 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1746 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001747 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001748 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1749 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001750 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001751 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001752 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1753 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001754 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001755 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1756 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001757 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001758 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1759 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001760 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1761 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1762 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1763 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001764 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001765 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1766 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1767 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001768 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1769 call s:NetrwRestoreSetting("s:yykeep","@@")
1770 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1771 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1772 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1773 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1774
Bram Moolenaara6878372014-03-22 21:02:50 +01001775 if exists("{a:vt}netrw_swfkeep")
1776 if &directory == ""
1777 " user hasn't specified a swapfile directory;
1778 " netrw will temporarily set the swapfile directory
1779 " to the current directory as returned by getcwd().
1780 let &l:directory= getcwd()
1781 sil! let &l:swf = {a:vt}netrw_swfkeep
1782 setl directory=
1783 unlet {a:vt}netrw_swfkeep
1784 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001785 if !g:netrw_use_noswf
1786 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1787 sil! let &l:swf= {a:vt}netrw_swfkeep
1788 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001789 unlet {a:vt}netrw_swfkeep
1790 endif
1791 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001792 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001793 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1794 if exists("{a:vt}netrw_dirkeep")
1795 call s:NetrwLcd(dirkeep)
1796 unlet {a:vt}netrw_dirkeep
1797 endif
1798 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001799 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001800 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1801 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001802 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001803 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001804
Bram Moolenaara6878372014-03-22 21:02:50 +01001805 " Moved the filetype detect here from NetrwGetFile() because remote files
1806 " were having their filetype detect-generated settings overwritten by
1807 " NetrwOptionRestore.
1808 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001809 filetype detect
Bram Moolenaara6878372014-03-22 21:02:50 +01001810 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001811endfun
1812
1813" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001814" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1815" but only when the options' value and the safe setting differ
1816" Doing this means that netrw will not come up as having changed a
1817" setting last when it really didn't actually change it.
1818"
1819" Called from s:NetrwOptionsSafe
1820" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1821fun! s:NetrwSetSafeSetting(setting,safesetting)
1822" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001823
Bram Moolenaar85850f32019-07-19 22:05:51 +02001824 if a:setting =~ '^&'
1825" call Decho("fyi: a:setting starts with &")
1826 exe "let settingval= ".a:setting
1827" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001828
Bram Moolenaar85850f32019-07-19 22:05:51 +02001829 if settingval != a:safesetting
1830" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1831 if type(a:safesetting) == 0
1832 exe "let ".a:setting."=".a:safesetting
1833 elseif type(a:safesetting) == 1
1834 exe "let ".a:setting."= '".a:safesetting."'"
1835 else
1836 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1837 endif
1838 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001839 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001840
Bram Moolenaar85850f32019-07-19 22:05:51 +02001841" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001842endfun
1843
1844" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001845" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1846" but only if the setting value differs from the associated keepvar.
1847" Doing this means that netrw will not come up as having changed a
1848" setting last when it really didn't actually change it.
1849"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001850" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001851" keepvars are set up by s:NetrwOptionsSave
1852fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001853""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001854
Bram Moolenaar85850f32019-07-19 22:05:51 +02001855 " typically called from s:NetrwOptionsRestore
1856 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1857 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001858 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001859 if exists(a:keepvar)
1860 exe "let keepvarval= ".a:keepvar
1861 exe "let setting= ".a:setting
1862
1863"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1864"" call Decho("fyi: keepvarval=".keepvarval)
1865"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1866
1867 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001868"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001869 if type(a:setting) == 0
1870 exe "let ".a:setting."= ".keepvarval
1871 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001872 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001873 else
1874 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1875 endif
1876 endif
1877
1878 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001879 endif
1880
Bram Moolenaar85850f32019-07-19 22:05:51 +02001881"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001882endfun
1883
1884" ---------------------------------------------------------------------
1885" NetrwStatusLine: {{{2
1886fun! NetrwStatusLine()
1887
1888" vvv NetrwStatusLine() debugging vvv
1889" let g:stlmsg=""
1890" if !exists("w:netrw_explore_bufnr")
1891" let g:stlmsg="!X<explore_bufnr>"
1892" elseif w:netrw_explore_bufnr != bufnr("%")
1893" let g:stlmsg="explore_bufnr!=".bufnr("%")
1894" endif
1895" if !exists("w:netrw_explore_line")
1896" let g:stlmsg=" !X<explore_line>"
1897" elseif w:netrw_explore_line != line(".")
1898" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1899" endif
1900" if !exists("w:netrw_explore_list")
1901" let g:stlmsg=" !X<explore_list>"
1902" endif
1903" ^^^ NetrwStatusLine() debugging ^^^
1904
1905 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")
1906 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09001907 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02001908 let &laststatus = s:netrw_users_ls
1909 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1910 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1911 return ""
1912 else
1913 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1914 endif
1915endfun
1916
Bram Moolenaar85850f32019-07-19 22:05:51 +02001917" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001918" Netrw Transfer Functions: {{{1
1919" ===============================
1920
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001922" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001923" mode: =0 read remote file and insert before current line
1924" =1 read remote file and insert after current line
1925" =2 replace with remote file
1926" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001927fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001928" 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 +00001929
Bram Moolenaar5c736222010-01-06 20:54:52 +01001930 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001931 call s:NetrwOptionsSave("w:")
1932 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001933 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001934 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1935 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1936 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001937" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001938
Bram Moolenaar5c736222010-01-06 20:54:52 +01001939 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001940 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001941 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001942 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001943 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001944 elseif a:mode == 2 " replace with remote file
1945 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001946 elseif a:mode == 3 " skip read of file (leave as temporary)
1947 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001948 else
1949 exe a:mode
1950 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001951 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001952 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001953" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001954
Bram Moolenaar5c736222010-01-06 20:54:52 +01001955 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001956 let tmpfile= s:GetTempfile("")
1957 if tmpfile == ""
1958" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001959 return
1960 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001961
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001962 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001963
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001964 " attempt to repeat with previous host-file-etc
1965 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001966" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001967 let choice = b:netrw_lastfile
1968 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001969
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001970 else
1971 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001972" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001973
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001974 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001975 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001976 echomsg 'NetRead Usage:'
1977 echomsg ':Nread machine:path uses rcp'
1978 echomsg ':Nread "machine path" uses ftp with <.netrc>'
1979 echomsg ':Nread "machine id password path" uses ftp'
1980 echomsg ':Nread dav://machine[:port]/path uses cadaver'
1981 echomsg ':Nread fetch://machine/path uses fetch'
1982 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
1983 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001984 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01001985 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001986 echomsg ':Nread rcp://[user@]machine/path uses rcp'
1987 echomsg ':Nread rsync://machine[:port]/path uses rsync'
1988 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
1989 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001990 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001991 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001992
Bram Moolenaar9964e462007-05-05 17:54:07 +00001993 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001994 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001995" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001996 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001997 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02001998 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001999 else
2000 " case "... ... ..."
2001 let choice = strpart(choice,1,strlen(choice)-1)
2002 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002003
Bram Moolenaar9964e462007-05-05 17:54:07 +00002004 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002005 let wholechoice = wholechoice . " " . choice
2006 let ichoice = ichoice + 1
2007 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002008 if !exists("g:netrw_quiet")
2009 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2010 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002011" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002012 return
2013 endif
2014 let choice= a:{ichoice}
2015 endwhile
2016 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2017 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018 endif
2019 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002021" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002022 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002023
Bram Moolenaar5c736222010-01-06 20:54:52 +01002024 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002025 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002026 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002027" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002028 return
2029 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002030 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002031
Bram Moolenaar8d043172014-01-23 14:24:41 +01002032 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002033" 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 +02002034 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002035" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002036 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002037" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002038 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002040
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002041 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002042 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002043 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002044 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2045 echo "(netrw) Processing your read request..."
2046 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002047
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002048 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002049 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002050 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002051" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002052 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002053 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002054 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002055 " ER: the tmpfile is full path: rcp sees C:\... as host C
2056 if s:netrw_has_nt_rcp == 1
2057 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2058 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2059 else
2060 " Any way needed it machine contains a '.'
2061 let uid_machine = g:netrw_machine .'.'. $USERNAME
2062 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002063 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002064 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2065 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2066 else
2067 let uid_machine = g:netrw_machine
2068 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002069 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002070 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 +00002071 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002072 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002073
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002074 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002075 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002076 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002077" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002078 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002079 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002080 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002081 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002082 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002083" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002084 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002085 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002086" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002087 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002088 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002089" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002090 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002091 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 +00002092 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002093 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002094 endif
2095 " 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 +00002096 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002097 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002098 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002099 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002100 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002101 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002102 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002103 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002104 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2105 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002106 q!
2107 endif
2108 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002109 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002110 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002111
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002113 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002114 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2115 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002116" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002117 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002118 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002119 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002120 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002121 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002122 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002123" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002124 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002125 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002126" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002127 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002128
Bram Moolenaar97d62492012-11-15 21:28:22 +01002129 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002130 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002131 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002132" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002133 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002134 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002135 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002136" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002137 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002138 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002139" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002140 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002141 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002142
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002143 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002144 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002145" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002146 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002147 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002148 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002149" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002150 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002151 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002152" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002153
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002154 " perform ftp:
2155 " -i : turns off interactive prompting from ftp
2156 " -n unix : DON'T use <.netrc>, even though it exists
2157 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002158 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002159 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002160 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2161 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002162" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002163 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002164 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002165 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002167 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002168 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002169 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002170
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002171 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002172 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002173 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002174" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002175 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002176 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002177 else
2178 let useport= ""
2179 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002180 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2181 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002182 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002183 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2184 else
2185 let tmpfile_get = tmpfile
2186 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002187 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 +00002188 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002189 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002190
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002191 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002192 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002193 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002194" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002195 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002196 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002197 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002198 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002199" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002200 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002201 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002202
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002203 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2204 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002206 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002207 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 +00002208 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002209 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 +00002210 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002211 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002212
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002213 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002214 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002215" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002216 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2217 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002218" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2219" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2220 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 +00002221 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002222" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002223 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002224 endif
2225 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002226" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002227 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002228
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002230 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002231 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002232" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002233
Bram Moolenaar5c736222010-01-06 20:54:52 +01002234 if !executable(g:netrw_dav_cmd)
2235 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2236" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2237 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002238 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002239 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002240 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 +01002241 else
2242 " Construct execution string (four lines) which will be passed through filter
2243 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2244 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002245 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002246 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002247 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002248 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002249 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002250 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002251 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002252 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002253 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002254 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2255 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002256
Bram Moolenaar5c736222010-01-06 20:54:52 +01002257 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002258 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002259 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002260 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002261 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002262 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002263 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002264
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002265 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002266 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002267 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002268" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002269 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 +00002270 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002271 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002272
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002273 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002274 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002275 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002276 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002277" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002278 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002279 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002280 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002281 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002282" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002283 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002285 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002286 let netrw_option= "http"
2287 else
2288 let netrw_option= "ftp"
2289 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002290" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002291
Bram Moolenaar446cb832008-06-24 21:56:24 +00002292 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002293 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 +00002294 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002295 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 +00002296 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002297
Bram Moolenaar446cb832008-06-24 21:56:24 +00002298 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002299 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002300" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002301 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002302
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002303 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002304 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002305 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002306" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2307 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 +00002308 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002309 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002310
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002311 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002312 " NetRead: (file) NetRead Method #10 {{{3
2313 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002314" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2315 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002316 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2317 let b:netrw_lastfile = choice
2318
2319 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002320 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002321 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002322 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002323 endif
2324 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002325
Bram Moolenaar5c736222010-01-06 20:54:52 +01002326 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002327 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002328" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002329 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002330 unlet b:netrw_fname
2331 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002332 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 +01002333" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002334 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002335 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002336 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002337
Bram Moolenaar9964e462007-05-05 17:54:07 +00002338" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002339endfun
2340
2341" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002342" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002343fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002344" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002345
Bram Moolenaar5c736222010-01-06 20:54:52 +01002346 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002347 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002348 call s:NetrwOptionsSave("w:")
2349 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002350
Bram Moolenaar5c736222010-01-06 20:54:52 +01002351 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002352 let tmpfile= s:GetTempfile("")
2353 if tmpfile == ""
2354" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002355 return
2356 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002357
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002358 if a:0 == 0
2359 let ichoice = 0
2360 else
2361 let ichoice = 1
2362 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002363
Bram Moolenaar9964e462007-05-05 17:54:07 +00002364 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002365" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002366 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002367 " For binary writes, always write entire file.
2368 " (line numbers don't really make sense for that).
2369 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002370" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002371 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002372 elseif g:netrw_cygwin
2373 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002374 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002375" 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 +01002376 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002377 else
2378 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002379" 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 +01002380 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002381 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002382
Bram Moolenaar9964e462007-05-05 17:54:07 +00002383 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002384 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002385 " on the temporary file's name. Deletion of the temporary file during
2386 " cleanup then causes an error message.
2387 0file!
2388 endif
2389
Bram Moolenaar5c736222010-01-06 20:54:52 +01002390 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002392
Bram Moolenaar9964e462007-05-05 17:54:07 +00002393 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002394 " attempt to repeat with previous host-file-etc
2395 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002396" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002397 let choice = b:netrw_lastfile
2398 let ichoice= ichoice + 1
2399 else
2400 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002401
Bram Moolenaar8d043172014-01-23 14:24:41 +01002402 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002403 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002404 echomsg 'NetWrite Usage:"'
2405 echomsg ':Nwrite machine:path uses rcp'
2406 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2407 echomsg ':Nwrite "machine id password path" uses ftp'
2408 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2409 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2410 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2411 echomsg ':Nwrite rcp://machine/path uses rcp'
2412 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2413 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2414 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002415 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002416 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002417
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002418 elseif match(choice,"^\"") != -1
2419 if match(choice,"\"$") != -1
2420 " case "..."
2421 let choice=strpart(choice,1,strlen(choice)-2)
2422 else
2423 " case "... ... ..."
2424 let choice = strpart(choice,1,strlen(choice)-1)
2425 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002426
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002427 while match(choice,"\"$") == -1
2428 let wholechoice= wholechoice . " " . choice
2429 let ichoice = ichoice + 1
2430 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002431 if !exists("g:netrw_quiet")
2432 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2433 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002434" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002435 return
2436 endif
2437 let choice= a:{ichoice}
2438 endwhile
2439 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2440 endif
2441 endif
2442 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002443 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002444" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002445
Bram Moolenaar9964e462007-05-05 17:54:07 +00002446 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002447 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002448 if !exists("b:netrw_method") || b:netrw_method < 0
2449" call Dfunc("netrw#NetWrite : unsupported method")
2450 return
2451 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002452
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002453 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002454 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002455 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002456 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2457 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002458" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002459 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002460
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002461 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002462 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002463 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002464" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002465 if s:netrw_has_nt_rcp == 1
2466 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2467 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2468 else
2469 let uid_machine = g:netrw_machine .'.'. $USERNAME
2470 endif
2471 else
2472 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2473 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2474 else
2475 let uid_machine = g:netrw_machine
2476 endif
2477 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002478 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 +00002479 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002480
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002481 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002482 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002483 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002484" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002485 let netrw_fname = b:netrw_fname
2486
2487 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2488 let bhkeep = &l:bh
2489 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002490 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002491 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002492
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002493" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002494 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002495 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002496" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002497 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002498 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002499" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002500 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002501 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002502" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002503 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002504 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 +00002505 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002506" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2507 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 endif
2509 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2510 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002511 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002512 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002513 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002514 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002516
2517 " remove enew buffer (quietly)
2518 let filtbuf= bufnr("%")
2519 exe curbuf."b!"
2520 let &l:bh = bhkeep
2521 exe filtbuf."bw!"
2522
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002524
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002525 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002526 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002527 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002528 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002529" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002530 let netrw_fname = b:netrw_fname
2531 let bhkeep = &l:bh
2532
2533 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2534 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002535 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002536 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002537 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002538
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002539 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002540 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002541" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002542 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002543 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002544" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002545 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002546 if exists("g:netrw_uid") && g:netrw_uid != ""
2547 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002548 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002549" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002550 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002551 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002552 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002553" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002554 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002555 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002556" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002557 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002558 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002559 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002560" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002561 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002562 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002563" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002564 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002565 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002566" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002567 " save choice/id/password for future use
2568 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002569
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002570 " perform ftp:
2571 " -i : turns off interactive prompting from ftp
2572 " -n unix : DON'T use <.netrc>, even though it exists
2573 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002574 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002575 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002576 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2577 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002578 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002579 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002580 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002581 let mod=1
2582 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002583
2584 " remove enew buffer (quietly)
2585 let filtbuf= bufnr("%")
2586 exe curbuf."b!"
2587 let &l:bh= bhkeep
2588 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002589
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002590 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002591 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002592 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002593" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002594 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002595 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002596 else
2597 let useport= ""
2598 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002599 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 +00002600 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002601
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002602 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002603 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002604 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002605" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002606 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2607 if executable(curl)
2608 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609 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 +01002610 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002611 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002612 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002613
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002614 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002615 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002616 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002617" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002618
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002619 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002620 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2621 let bhkeep = &l:bh
2622
2623 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2624 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002625 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002626 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002627
Bram Moolenaarff034192013-04-24 18:51:19 +02002628 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002629 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002630 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002631 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002632 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002633 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002634 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002635 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002636 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002637 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002638
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002639 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002640 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002641 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002642
2643 " remove enew buffer (quietly)
2644 let filtbuf= bufnr("%")
2645 exe curbuf."b!"
2646 let &l:bh = bhkeep
2647 exe filtbuf."bw!"
2648
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002649 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002650
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002651 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002652 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002653 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002654" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002655 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 +00002656 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002657
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002658 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002659 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002660 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002661" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002662 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2664 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2665 else
2666 let uid_machine = g:netrw_machine
2667 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002668
2669 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2670 let bhkeep = &l:bh
2671 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002672 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002673 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002674
Bram Moolenaarff034192013-04-24 18:51:19 +02002675 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002676 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002677" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002678 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002679 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002680 let filtbuf= bufnr("%")
2681 exe curbuf."b!"
2682 let &l:bh = bhkeep
2683 exe filtbuf."bw!"
2684 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002685
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002686 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002687 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002688 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002689 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002690 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002692 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002693
Bram Moolenaar5c736222010-01-06 20:54:52 +01002694 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002695" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002696 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002697" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002698 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002699 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002700 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002701
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002702 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002703 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002704 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002705" 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 +02002706 elseif !exists("leavemod")
2707 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002708" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002709 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002710" 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 +00002711 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002712
Bram Moolenaar9964e462007-05-05 17:54:07 +00002713" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002714endfun
2715
2716" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002717" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002718" uses NetRead to get a copy of the file into a temporarily file,
2719" then sources that file,
2720" then removes that file.
2721fun! netrw#NetSource(...)
2722" call Dfunc("netrw#NetSource() a:0=".a:0)
2723 if a:0 > 0 && a:1 == '?'
2724 " give help
2725 echomsg 'NetSource Usage:'
2726 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2727 echomsg ':Nsource fetch://machine/path uses fetch'
2728 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002729 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002730 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2731 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2732 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2733 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2734 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002735 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002736 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002737 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002738 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002739" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002740 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002741" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002742 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002743" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002744 if delete(s:netrw_tmpfile)
2745 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2746 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002747 unlet s:netrw_tmpfile
2748 else
2749 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2750 endif
2751 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002752 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002753 endif
2754" call Dret("netrw#NetSource")
2755endfun
2756
Bram Moolenaar8d043172014-01-23 14:24:41 +01002757" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002758" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2759" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002760fun! netrw#SetTreetop(iscmd,...)
Bram Moolenaara6878372014-03-22 21:02:50 +01002761
Bram Moolenaar85850f32019-07-19 22:05:51 +02002762 " iscmd==0: netrw#SetTreetop called using gn mapping
2763 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
Bram Moolenaar8d043172014-01-23 14:24:41 +01002764 " clear out the current tree
2765 if exists("w:netrw_treetop")
2766 let inittreetop= w:netrw_treetop
2767 unlet w:netrw_treetop
2768 endif
2769 if exists("w:netrw_treedict")
2770 unlet w:netrw_treedict
2771 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002772
Bram Moolenaar85850f32019-07-19 22:05:51 +02002773 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002774 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaar8d043172014-01-23 14:24:41 +01002775 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002776 if isdirectory(s:NetrwFile(a:1))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002777 let treedir = a:1
2778 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002779 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002780 let treedir = b:netrw_curdir."/".a:1
2781 let s:netrw_treetop = treedir
Bram Moolenaar8d043172014-01-23 14:24:41 +01002782 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002783 " normally the cursor is left in the message window.
2784 " However, here this results in the directory being listed in the message window, which is not wanted.
2785 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002786 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002787 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002788 let treedir = "."
2789 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002790 endif
2791 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002792
2793 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002794 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02002795
2796 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002797 if islocal
Tom Benham64a536d2024-11-07 21:15:03 +01002798 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002799 else
Tom Benham64a536d2024-11-07 21:15:03 +01002800 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002801 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002802
Bram Moolenaar8d043172014-01-23 14:24:41 +01002803endfun
2804
Bram Moolenaar9964e462007-05-05 17:54:07 +00002805" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002806" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002807" readcmd == %r : replace buffer with newly read file
2808" == 0r : read file at top of buffer
2809" == r : read file after current line
2810" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002811fun! s:NetrwGetFile(readcmd, tfile, method)
2812" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002813
2814 " readcmd=='t': simply do nothing
2815 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002816" 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 +01002817" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002818 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002819 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002820
Bram Moolenaar9964e462007-05-05 17:54:07 +00002821 " get name of remote filename (ie. url and all)
2822 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002823" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002824
Bram Moolenaar9964e462007-05-05 17:54:07 +00002825 if exists("*NetReadFixup")
2826 " for the use of NetReadFixup (not otherwise used internally)
2827 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002828 endif
2829
Bram Moolenaar9964e462007-05-05 17:54:07 +00002830 if a:readcmd[0] == '%'
2831 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002832" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002833
2834 " rename the current buffer to the temp file (ie. tfile)
2835 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002836 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002837 else
2838 let tfile= a:tfile
2839 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002840 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002841
2842 " edit temporary file (ie. read the temporary file in)
2843 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002844" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002845 call zip#Browse(tfile)
2846 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002847" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002848 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002849 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002850" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002851 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002852 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002853" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002854 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002855 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002856" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002857 call tar#Browse(tfile)
2858 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002859" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002860 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002861 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002862" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002863 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002864 endif
2865
2866 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002867 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002868
Bram Moolenaar71badf92023-04-22 22:40:14 +01002869 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002870 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002871 " Note that isk must not include a "/" for scripts.vim
2872 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002873" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2874" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002875" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002876" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2877 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002878 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002879 filetype detect
2880" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002881 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002882" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002883 let line1 = 1
2884 let line2 = line("$")
2885
Bram Moolenaar8d043172014-01-23 14:24:41 +01002886 elseif !&ma
2887 " 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 +01002888 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002889" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002890 return
2891
Bram Moolenaar9964e462007-05-05 17:54:07 +00002892 elseif s:FileReadable(a:tfile)
2893 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002894" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002895 let curline = line(".")
2896 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002897" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002898 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002899 let line1= curline + 1
2900 let line2= line("$") - lastline + 1
2901
2902 else
2903 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002904" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2905" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002906 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002907" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002908 return
2909 endif
2910
2911 " User-provided (ie. optional) fix-it-up command
2912 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002913" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002914 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002915" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002916" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002917 endif
2918
Bram Moolenaaradc21822011-04-01 18:03:16 +02002919 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002920 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002921 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002922 endif
2923
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002924" 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 +00002925
2926 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002927" redraw!
2928
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002929" 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 +00002930" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002931endfun
2932
Bram Moolenaar9964e462007-05-05 17:54:07 +00002933" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002934" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002935" Input:
2936" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2937" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002938" b:netrw_method= 1: rcp
2939" 2: ftp + <.netrc>
2940" 3: ftp + machine, id, password, and [path]filename
2941" 4: scp
2942" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002943" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002944" 7: rsync
2945" 8: fetch
2946" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002947" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01002948" g:netrw_machine= hostname
2949" b:netrw_fname = filename
2950" g:netrw_port = optional port number (for ftp)
2951" g:netrw_choice = copy of input url (choice)
2952fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002953" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002954
Bram Moolenaar251e1912011-06-19 05:09:16 +02002955 " sanity check: choice should have at least three slashes in it
2956 if strlen(substitute(a:choice,'[^/]','','g')) < 3
2957 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
2958 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02002959" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02002960 return
2961 endif
2962
Bram Moolenaar5c736222010-01-06 20:54:52 +01002963 " record current g:netrw_machine, if any
2964 " curmachine used if protocol == ftp and no .netrc
2965 if exists("g:netrw_machine")
2966 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002967" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002968 else
2969 let curmachine= "N O T A HOST"
2970 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002971 if exists("g:netrw_port")
2972 let netrw_port= g:netrw_port
2973 endif
2974
2975 " insure that netrw_ftp_cmd starts off every method determination
2976 " with the current g:netrw_ftp_cmd
2977 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002978
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002979 " initialization
2980 let b:netrw_method = 0
2981 let g:netrw_machine = ""
2982 let b:netrw_fname = ""
2983 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002984 let g:netrw_choice = a:choice
2985
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002986 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002987 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00002988 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
2989 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002990 " rcpurm : rcp://[user@]host/filename Use rcp
2991 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002992 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002993 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01002994 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002995 " rsyncurm : rsync://host[:port]/path Use rsync
2996 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
2997 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002998 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002999 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3000 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003001 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3002 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003003 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003004 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003005 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003006 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003007 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003008 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003009 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003010 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003011
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003012" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003013 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003014 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003015 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003016" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003017 let b:netrw_method = 1
3018 let userid = substitute(a:choice,rcpurm,'\1',"")
3019 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3020 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003021 if userid != ""
3022 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003024
Bram Moolenaaradc21822011-04-01 18:03:16 +02003025 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003026 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003027" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003028 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003029 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3030 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3031 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003032
Bram Moolenaar15146672011-10-20 22:22:38 +02003033 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003034 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003035" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003036 let b:netrw_method = 5
3037 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3038 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003039 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003040
Bram Moolenaaradc21822011-04-01 18:03:16 +02003041 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003042 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003043" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003044 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003045 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003046 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3047 else
3048 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3049 endif
3050 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003051
Bram Moolenaaradc21822011-04-01 18:03:16 +02003052 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003053 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003054" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003055 let b:netrw_method = 7
3056 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3057 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003058
Bram Moolenaaradc21822011-04-01 18:03:16 +02003059 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003060 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003061" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003062 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003063 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3064 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3065 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003066" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003067 if userid != ""
3068 let g:netrw_uid= userid
3069 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003070
Bram Moolenaaradc21822011-04-01 18:03:16 +02003071 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003072 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003073 call NetUserPass("ftp:".g:netrw_machine)
3074 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003075 " if there's a change in hostname, require password re-entry
3076 unlet s:netrw_passwd
3077 endif
3078 if exists("netrw_port")
3079 unlet netrw_port
3080 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003081 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003082
Bram Moolenaar446cb832008-06-24 21:56:24 +00003083 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003084 let b:netrw_method = 3
3085 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003086 let host= substitute(g:netrw_machine,'\..*$','','')
3087 if exists("s:netrw_hup[host]")
3088 call NetUserPass("ftp:".host)
3089
Nir Lichtman1e34b952024-05-08 19:19:34 +02003090 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003091" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3092" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003093 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003094 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003095" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003096 endif
3097 let b:netrw_method= 2
3098 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003099" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003100 let b:netrw_method= 2
3101 else
3102 if !exists("g:netrw_uid") || g:netrw_uid == ""
3103 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003104 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003105 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003106 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003107 endif
3108 let b:netrw_method= 3
3109 endif
3110 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003111
Bram Moolenaaradc21822011-04-01 18:03:16 +02003112 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003113 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003114" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003115 let b:netrw_method = 8
3116 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3117 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3118 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3119 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003120
Bram Moolenaaradc21822011-04-01 18:03:16 +02003121 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003122 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003123" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003125 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3126 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003127 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003128 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003129 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003130
Bram Moolenaaradc21822011-04-01 18:03:16 +02003131 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003132 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003133" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003134 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003135 let b:netrw_method = 3
3136 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3137 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003138
Bram Moolenaar9964e462007-05-05 17:54:07 +00003139 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003140 let b:netrw_method = 2
3141 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3142 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3143 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003144
Bram Moolenaaradc21822011-04-01 18:03:16 +02003145 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003146 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003147" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003148 let b:netrw_method = 9
3149 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3150 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003151
Bram Moolenaaradc21822011-04-01 18:03:16 +02003152 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003153 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003154" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003155 let b:netrw_method = 1
3156 let userid = substitute(a:choice,rcphf,'\2',"")
3157 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3158 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003159" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3160" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3161" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3162" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003163 if userid != ""
3164 let g:netrw_uid= userid
3165 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003166
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003167 " Method#10: file://user@hostname/...path-to-file {{{3
3168 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003169" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003170 let b:netrw_method = 10
3171 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003172" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003173
Bram Moolenaaradc21822011-04-01 18:03:16 +02003174 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003175 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003176 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003177 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003178 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003179 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003181 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003182
Bram Moolenaar81695252004-12-29 20:58:21 +00003183 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003184 " remove any leading [:#] from port number
3185 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3186 elseif exists("netrw_port")
3187 " retain port number as implicit for subsequent ftp operations
3188 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003189 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003190
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003191" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3192" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3193" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3194" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003195" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003196" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003197" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003198" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003199" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003200" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003201" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003202" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204
Bram Moolenaar9964e462007-05-05 17:54:07 +00003205" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003206" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003207" Usage: :call NetUserPass() -- will prompt for userid and password
3208" :call NetUserPass("uid") -- will prompt for password
3209" :call NetUserPass("uid","password") -- sets global userid and password
3210" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3211" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212fun! NetUserPass(...)
3213
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003214" call Dfunc("NetUserPass() a:0=".a:0)
3215
3216 if !exists('s:netrw_hup')
3217 let s:netrw_hup= {}
3218 endif
3219
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003221 " case: no input arguments
3222
3223 " change host and username if not previously entered; get new password
3224 if !exists("g:netrw_machine")
3225 let g:netrw_machine= input('Enter hostname: ')
3226 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003228 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003229 let g:netrw_uid= input('Enter username: ')
3230 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003231 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003232 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003233
3234 " set up hup database
3235 let host = substitute(g:netrw_machine,'\..*$','','')
3236 if !exists('s:netrw_hup[host]')
3237 let s:netrw_hup[host]= {}
3238 endif
3239 let s:netrw_hup[host].uid = g:netrw_uid
3240 let s:netrw_hup[host].passwd = s:netrw_passwd
3241
3242 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003243 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003244
3245 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003246 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003247 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003248" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003249 let host = substitute(a:1,'^ftp:','','')
3250 let host = substitute(host,'\..*','','')
3251 if exists("s:netrw_hup[host]")
3252 let g:netrw_uid = s:netrw_hup[host].uid
3253 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003254" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3255" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003256 else
3257 let g:netrw_uid = input("Enter UserId: ")
3258 let s:netrw_passwd = inputsecret("Enter Password: ")
3259 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003260
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003261 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003262 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003263" 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 +02003264 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003265 if g:netrw_machine =~ '[0-9.]\+'
3266 let host= g:netrw_machine
3267 else
3268 let host= substitute(g:netrw_machine,'\..*$','','')
3269 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003270 else
3271 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003272 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003273 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003274" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003275 if exists("g:netrw_passwd")
3276 " ask for password if one not previously entered
3277 let s:netrw_passwd= g:netrw_passwd
3278 else
3279 let s:netrw_passwd = inputsecret("Enter Password: ")
3280 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003281 endif
3282
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003283" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003284 if exists("host")
3285 if !exists('s:netrw_hup[host]')
3286 let s:netrw_hup[host]= {}
3287 endif
3288 let s:netrw_hup[host].uid = g:netrw_uid
3289 let s:netrw_hup[host].passwd = s:netrw_passwd
3290 endif
3291
3292 elseif a:0 == 2
3293 let g:netrw_uid = a:1
3294 let s:netrw_passwd = a:2
3295
3296 elseif a:0 == 3
3297 " enter hostname, user-id, and password into the hup dictionary
3298 let host = substitute(a:1,'^\a\+:','','')
3299 let host = substitute(host,'\..*$','','')
3300 if !exists('s:netrw_hup[host]')
3301 let s:netrw_hup[host]= {}
3302 endif
3303 let s:netrw_hup[host].uid = a:2
3304 let s:netrw_hup[host].passwd = a:3
3305 let g:netrw_uid = s:netrw_hup[host].uid
3306 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003307" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3308" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003310
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003311" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003312endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313
Bram Moolenaar85850f32019-07-19 22:05:51 +02003314" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003315" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003316" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003318" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003319" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3320fun! s:ExplorePatHls(pattern)
3321" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3322 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003323" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003324 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003325" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003326 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3327" call Dret("s:ExplorePatHls repat<".repat.">")
3328 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003329endfun
3330
3331" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003332" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003333" 0: (user: <mb>) bookmark current directory
3334" 1: (user: <gb>) change to the bookmarked directory
3335" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003336" 3: (browsing) records current directory history
3337" 4: (user: <u>) go up (previous) directory, using history
3338" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003339" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003340fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003341" 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 +02003342 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3343" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3344 return
3345 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003346
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003347 let ykeep = @@
3348 let curbufnr = bufnr("%")
3349
Bram Moolenaar9964e462007-05-05 17:54:07 +00003350 if a:chg == 0
3351 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003352" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003353 if exists("s:netrwmarkfilelist_{curbufnr}")
3354 call s:NetrwBookmark(0)
3355 echo "bookmarked marked files"
3356 else
3357 call s:MakeBookmark(a:curdir)
3358 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003359 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003360
KSR-Yasudaf4498252023-10-06 03:34:17 +09003361 try
3362 call s:NetrwBookHistSave()
3363 catch
3364 endtry
3365
Bram Moolenaar9964e462007-05-05 17:54:07 +00003366 elseif a:chg == 1
3367 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003368" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003369 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003370" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003371 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003372 else
3373 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3374 endif
3375
3376 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003377" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003378 let didwork= 0
3379 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003380" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003381 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003382" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003383 let cnt= 1
3384 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003385" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003386 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003387 let didwork = 1
3388 let cnt = cnt + 1
3389 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003390 endif
3391
3392 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003393 " Note: history is saved only when PerformListing is done;
3394 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3395 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003396 let first = 1
3397 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003398 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003399 while ( first || cnt != g:netrw_dirhistcnt )
3400" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003401 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003402" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003403 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003404 let didwork= 1
3405 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003406 let histcnt = histcnt + 1
3407 let first = 0
3408 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003409 if cnt < 0
3410 let cnt= cnt + g:netrw_dirhistmax
3411 endif
3412 endwhile
3413 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003414 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003415 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003416 if didwork
3417 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3418 endif
3419
3420 elseif a:chg == 3
3421 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003422" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003423 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 +02003424 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003425 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3426 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003427 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003428" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003429 endif
3430
3431 elseif a:chg == 4
3432 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003433" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003434 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003435 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3436 if g:netrw_dirhistcnt < 0
3437 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003438 endif
3439 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003440 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003441 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003442 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3443" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003444 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003445 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003446" call Decho("setl ma noro",'~'.expand("<slnum>"))
3447 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003448 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003449" call Decho("setl nomod",'~'.expand("<slnum>"))
3450" 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 +00003451 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003452" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3453 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003454 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003455 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003456 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003457 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003458 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003459 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003460 echo "Sorry, no predecessor directory exists yet"
3461 endif
3462
3463 elseif a:chg == 5
3464 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003465" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003466 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003467 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3468 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3469" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003470 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003471" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003472 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003473 sil! NetrwKeepj %d _
3474" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3475" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003476 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003477" 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 +02003478 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003479" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3480 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003481 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003482 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3483 if g:netrw_dirhistcnt < 0
3484 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003485 endif
3486 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003487 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003488 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003489 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003490 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003491 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003492
3493 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003494" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003495 if exists("s:netrwmarkfilelist_{curbufnr}")
3496 call s:NetrwBookmark(1)
3497 echo "removed marked files from bookmarks"
3498 else
3499 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003500 let iremove = v:count
3501 let dremove = g:netrw_bookmarklist[iremove - 1]
3502" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003503 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003504" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3505 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3506 echo "removed ".dremove." from g:netrw_bookmarklist"
3507" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003508 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003509" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003510
3511 try
3512 call s:NetrwBookHistSave()
3513 catch
3514 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003515 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003516 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003517 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003518 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003519" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003520endfun
3521
3522" ---------------------------------------------------------------------
3523" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003524" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003525" Sister function: s:NetrwBookHistSave()
3526fun! s:NetrwBookHistRead()
3527" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003528 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003529" 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 +02003530 return
3531 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003532 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003533
3534 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003535 if !exists("s:netrw_initbookhist")
3536 let home = s:NetrwHome()
3537 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003538 if filereadable(s:NetrwFile(savefile))
3539" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003540 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003541 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003542
3543 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003544 if g:netrw_dirhistmax > 0
3545 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003546 if filereadable(s:NetrwFile(savefile))
3547" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003548 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003549 endif
3550 let s:netrw_initbookhist= 1
3551 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003552 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003553 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003554
Bram Moolenaar97d62492012-11-15 21:28:22 +01003555 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003556" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3557" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003558" call Dret("s:NetrwBookHistRead")
3559endfun
3560
3561" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003562" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003563" Sister function: s:NetrwBookHistRead()
3564" I used to do this via viminfo but that appears to
3565" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003566" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3567" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003568" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003569fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003570" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003571 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003572" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003573 return
3574 endif
3575
Bram Moolenaar5c736222010-01-06 20:54:52 +01003576 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003577" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003578 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003579
3580 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003581 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003582" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003583 if g:netrw_use_noswf
3584 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3585 else
3586 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3587 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003588 setl nocin noai noci magic nospell nohid wig= noaw
3589 setl ma noro write
3590 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003591 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003592
Bram Moolenaar85850f32019-07-19 22:05:51 +02003593 " rename enew'd file: .netrwhist -- no attempt to merge
3594 " record dirhistmax and current dirhistcnt
3595 " save history
3596" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003597 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003598 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003599 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3600 if g:netrw_dirhistmax > 0
3601 let lastline = line("$")
3602 let cnt = g:netrw_dirhistcnt
3603 let first = 1
3604 while ( first || cnt != g:netrw_dirhistcnt )
3605 let lastline= lastline + 1
3606 if exists("g:netrw_dirhist_{cnt}")
3607 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3608" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3609 endif
3610 let first = 0
3611 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3612 if cnt < 0
3613 let cnt= cnt + g:netrw_dirhistmax
3614 endif
3615 endwhile
3616 exe "sil! w! ".savefile
3617" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3618 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003619
Bram Moolenaar85850f32019-07-19 22:05:51 +02003620 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003621 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003622 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003623" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003624 " merge and write .netrwbook
3625 let savefile= s:NetrwHome()."/.netrwbook"
3626
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003627 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003628 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003629 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003630 for bdm in booklist
3631 if index(g:netrw_bookmarklist,bdm) == -1
3632 call add(g:netrw_bookmarklist,bdm)
3633 endif
3634 endfor
3635 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003636 endif
3637
3638 " construct and save .netrwbook
3639 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003640 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003641" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003642 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003643
3644 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003645 let bgone= bufnr("%")
3646 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003647 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003648
3649" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003650endfun
3651
3652" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003653" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3654" list of the contents of a local or remote directory. It is assumed that the
3655" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3656" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003657" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003658fun! s:NetrwBrowse(islocal,dirname)
3659 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003660
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003661 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3662 " This is useful when one edits a local file, then :e ., then :Rex
3663 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3664 let w:netrw_rexfile= bufname("#")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003665 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003666
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003667 " s:NetrwBrowse : initialize history {{{3
3668 if !exists("s:netrw_initbookhist")
3669 NetrwKeepj call s:NetrwBookHistRead()
3670 endif
3671
3672 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003673 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003674 let dirname= simplify(a:dirname)
3675 else
3676 let dirname= a:dirname
3677 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003678
Bram Moolenaar85850f32019-07-19 22:05:51 +02003679 " repoint t:netrw_lexbufnr if appropriate
3680 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02003681 let repointlexbufnr= 1
3682 endif
3683
3684 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003685 if exists("s:netrw_skipbrowse")
3686 unlet s:netrw_skipbrowse
Bram Moolenaar446cb832008-06-24 21:56:24 +00003687 return
3688 endif
3689 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003690 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003691 return
3692 endif
3693 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003694 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003695 return
3696 endif
3697
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003698 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003699 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003700
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003701 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003702 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3703 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003704 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3705 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003706 endif
3707
3708 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003709 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003710 if s:NetrwLcd(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003711 return
3712 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003713
Bram Moolenaar5c736222010-01-06 20:54:52 +01003714 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003715 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003716 if bufname(dirname) != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003717 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003718 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003719 " attempt transfer of remote regular file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003720
3721 " remove any filetype indicator from end of dirname, except for the
3722 " "this is a directory" indicator (/).
3723 " There shouldn't be one of those here, anyway.
3724 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003725 call s:RemotePathAnalysis(dirname)
3726
3727 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3728 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003729 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003730 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003731 let b:netrw_curdir = dirname
3732 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003733 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003734 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3735 sil call netrw#NetRead(2,url)
3736 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003737 if s:path =~ '.bz2'
3738 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3739 elseif s:path =~ '.gz'
3740 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3741 elseif s:path =~ '.gz'
3742 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3743 else
3744 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3745 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003746 endif
3747
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003748 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003749 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003750 call s:NetrwOptionsRestore("w:")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003751 setl ma nomod noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00003752 return
3753 endif
3754
Bram Moolenaaradc21822011-04-01 18:03:16 +02003755 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003756 call s:UseBufWinVars()
3757
3758 " set up some variables {{{3
3759 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003760 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003761 let s:last_sort_by = g:netrw_sort_by
3762
3763 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003764 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003765
Bram Moolenaar97d62492012-11-15 21:28:22 +01003766 " get/set-up buffer {{{3
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003767 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01003768
3769 " NetrwGetBuffer might change buffers but s:rexposn_X was set for the
3770 " previous buffer
3771 let prevbufnr = bufnr('%')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003772 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Tom Benham64a536d2024-11-07 21:15:03 +01003773 if exists("s:rexposn_".prevbufnr)
3774 let s:rexposn_{bufnr('%')} = s:rexposn_{prevbufnr}
3775 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003776
Bram Moolenaar446cb832008-06-24 21:56:24 +00003777 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003778 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3779 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02003780 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3781 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003782 2match none
3783 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003784 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003785 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003786 call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003787 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003788 return
3789 endif
3790
3791 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003792 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003793 if b:netrw_curdir =~ '[/\\]$'
3794 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3795 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003796 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003797 let b:netrw_curdir= b:netrw_curdir."/"
3798 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003799 if b:netrw_curdir == ''
3800 if has("amiga")
3801 " On the Amiga, the empty string connotes the current directory
3802 let b:netrw_curdir= getcwd()
3803 else
3804 " under unix, when the root directory is encountered, the result
3805 " from the preceding substitute is an empty string.
3806 let b:netrw_curdir= '/'
3807 endif
3808 endif
3809 if !a:islocal && b:netrw_curdir !~ '/$'
3810 let b:netrw_curdir= b:netrw_curdir.'/'
3811 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003812
3813 " ------------
3814 " (local only) {{{3
3815 " ------------
3816 if a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00003817 " Set up ShellCmdPost handling. Append current buffer to browselist
3818 call s:LocalFastBrowser()
3819
3820 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3821 if !g:netrw_keepdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003822 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003823 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003824 return
3825 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003826 endif
3827 endif
3828
3829 " --------------------------------
3830 " remote handling: {{{3
3831 " --------------------------------
3832 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003833
Bram Moolenaar97d62492012-11-15 21:28:22 +01003834 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003835 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003836 let dirname= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003837 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3838 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3839 if dirname !~ '/$'
3840 let dirname= dirname.'/'
3841 endif
3842 let b:netrw_curdir = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003843 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003844 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003845 endif
3846
3847 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3848 if dirname !~ dirpat
3849 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003850 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003851 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003852 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003853 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003854 return
3855 endif
3856 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003857 endif " (additional remote handling)
3858
Bram Moolenaar85850f32019-07-19 22:05:51 +02003859 " -------------------------------
3860 " Perform Directory Listing: {{{3
3861 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003862 NetrwKeepj call s:NetrwMaps(a:islocal)
3863 NetrwKeepj call s:NetrwCommands(a:islocal)
3864 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003865
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003866 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003867 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003868
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003869 " If there is a rexposn: restore position with rexposn
3870 " Otherwise : set rexposn
3871 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003872 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3873 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3874 NetrwKeepj exe w:netrw_bannercnt
3875 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003876 else
3877 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3878 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003879 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003880 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara6878372014-03-22 21:02:50 +01003881 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003882 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003883
Bram Moolenaar85850f32019-07-19 22:05:51 +02003884 " repoint t:netrw_lexbufnr if appropriate
3885 if exists("repointlexbufnr")
3886 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003887 endif
3888
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003889 " restore position
3890 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003891 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003892 endif
3893
Bram Moolenaara6878372014-03-22 21:02:50 +01003894 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003895 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
3896 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003897 return
3898endfun
3899
3900" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003901" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
3902" may not apply correctly; ie. netrw's idea of the current directory may
3903" differ from vim's. This function insures that netrw's idea of the current
3904" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003905" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003906fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003907" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
3908" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
3909" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
3910" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
3911" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003912
3913 " clean up any leading treedepthstring
3914 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3915 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02003916" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003917 else
3918 let fname= a:fname
3919 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003920
3921 if g:netrw_keepdir
3922 " vim's idea of the current directory possibly may differ from netrw's
3923 if !exists("b:netrw_curdir")
3924 let b:netrw_curdir= getcwd()
3925 endif
3926
Nir Lichtman1e34b952024-05-08 19:19:34 +02003927 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003928 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003929 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003930 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003931" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003932 else
3933 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003934 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003935" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003936 endif
3937
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003938 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003939 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003940 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003941" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003942 else
3943 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003944 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003945" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003946 endif
3947 else
3948 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003949 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003950" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
3951" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
3952" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003953 endif
3954
Bram Moolenaar85850f32019-07-19 22:05:51 +02003955" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003956 return ret
3957endfun
3958
3959" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003960" s:NetrwFileInfo: supports qf (query for file information) {{{2
3961fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003962" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003963 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00003964 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003965 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003966 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003967 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003968 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003969 let lsopt= "-lsadh --si"
3970 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02003971" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003972 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003973
3974 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003975 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003976" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003977
Bram Moolenaara6878372014-03-22 21:02:50 +01003978 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003979 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003980" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003981
3982 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003983 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003984" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003985
Bram Moolenaar446cb832008-06-24 21:56:24 +00003986 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003987" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003988 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003989" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003990 endif
3991 else
3992 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003993" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
3994 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003995 let fname= substitute(a:fname,".$","","")
3996 else
3997 let fname= a:fname
3998 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003999 let t = getftime(s:NetrwFile(fname))
4000 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004001 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004002 let sz= s:NetrwHumanReadable(sz)
4003 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004004 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4005" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004006 endif
4007 else
4008 echo "sorry, \"qf\" not supported yet for remote files"
4009 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004010 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004011" call Dret("s:NetrwFileInfo")
4012endfun
4013
4014" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004015" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4016fun! s:NetrwFullPath(filename)
4017" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4018 let filename= a:filename
4019 if filename !~ '^/'
4020 let filename= resolve(getcwd().'/'.filename)
4021 endif
4022 if filename != "/" && filename =~ '/$'
4023 let filename= substitute(filename,'/$','','')
4024 endif
4025" " call Dret("s:NetrwFullPath <".filename.">")
4026 return filename
4027endfun
4028
4029" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004030" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004031" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004032" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004033" 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 +00004034fun! s:NetrwGetBuffer(islocal,dirname)
4035" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004036" 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 +02004037" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4038" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004039 let dirname= a:dirname
4040
4041 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004042" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004043 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004044" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004045 let s:netrwbuf= {}
4046 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004047" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4048" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4049
4050 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4051 let bufnum = -1
4052
4053 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4054 if has_key(s:netrwbuf,"NetrwTreeListing")
4055 let bufnum= s:netrwbuf["NetrwTreeListing"]
4056 else
4057 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4058 endif
4059" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4060 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004061 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004062 let bufnum= -1
4063 endif
4064 elseif bufnr("NetrwTreeListing") != -1
4065 let bufnum= bufnr("NetrwTreeListing")
4066" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4067 else
4068" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4069 let bufnum= -1
4070 endif
4071
4072 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004073 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004074" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004075 if !bufexists(bufnum)
4076 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4077 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004078 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004079
Bram Moolenaar446cb832008-06-24 21:56:24 +00004080 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004081" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004082 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004083 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004084" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4085
Bram Moolenaar71badf92023-04-22 22:40:14 +01004086 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004087 " IF the buffer already has the desired name
4088 " AND it is empty
4089 let curbuf = bufname("%")
4090 if curbuf == '.'
4091 let curbuf = getcwd()
4092 endif
4093" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004094" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004095" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4096" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4097" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4098" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4099 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004100" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4101 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004102 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004103" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004104 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004105 " 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 +00004106
4107 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004108 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004109" 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 +00004110 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004111" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004112 " name the buffer
4113 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4114 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004115" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004116 let w:netrw_treebufnr = bufnr("%")
4117 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004118 if g:netrw_use_noswf
4119 setl nobl bt=nofile noswf
4120 else
4121 setl nobl bt=nofile
4122 endif
4123 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4124 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4125 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4126 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004127" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004128 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004129 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004130 " enter the new buffer into the s:netrwbuf dictionary
4131 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4132" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4133" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004134 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004135" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004136
4137 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004138" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004139 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004140 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004141 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004142
4143 if &ft == "netrw"
4144" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4145 exe "sil! NetrwKeepj noswapfile b ".bufnum
4146" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004147 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004148" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4149 call s:NetrwEditBuf(bufnum)
4150" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004151 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004152" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004153 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004154 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004155 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004156
4157 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004158 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004159
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004160 if line("$") <= 1 && getline(1) == ""
4161 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004162 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004163" 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>"))
4164" 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 +01004165" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4166 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004167
Bram Moolenaar97d62492012-11-15 21:28:22 +01004168 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004169" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004170 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004171 sil NetrwKeepj %d _
4172" 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>"))
4173" 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 +01004174" 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 +00004175 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004176
Bram Moolenaar446cb832008-06-24 21:56:24 +00004177 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004178" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4179" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004180 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004181 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004182 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004183" 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>"))
4184" 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 +01004185" 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 +00004186 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004187
Bram Moolenaar446cb832008-06-24 21:56:24 +00004188 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004189" 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>"))
4190" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4191" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004192 return 1
4193 endif
4194 endif
4195
4196 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4197 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4198 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4199 " med 1 D H
4200 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004201" 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 +00004202 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004203 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004204 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004205
4206 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004207" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4208" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4209 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004210
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004211" 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>"))
4212" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4213" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004214 return 0
4215endfun
4216
4217" ---------------------------------------------------------------------
4218" s:NetrwGetcwd: get the current directory. {{{2
4219" Change backslashes to forward slashes, if any.
4220" If doesc is true, escape certain troublesome characters
4221fun! s:NetrwGetcwd(doesc)
4222" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4223 let curdir= substitute(getcwd(),'\\','/','ge')
4224 if curdir !~ '[\/]$'
4225 let curdir= curdir.'/'
4226 endif
4227 if a:doesc
4228 let curdir= fnameescape(curdir)
4229 endif
4230" call Dret("NetrwGetcwd <".curdir.">")
4231 return curdir
4232endfun
4233
4234" ---------------------------------------------------------------------
4235" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4236fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004237" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4238" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4239 let keepsol= &l:sol
4240 setl nosol
4241
Bram Moolenaar446cb832008-06-24 21:56:24 +00004242 call s:UseBufWinVars()
4243
4244 " insure that w:netrw_liststyle is set up
4245 if !exists("w:netrw_liststyle")
4246 if exists("g:netrw_liststyle")
4247 let w:netrw_liststyle= g:netrw_liststyle
4248 else
4249 let w:netrw_liststyle= s:THINLIST
4250 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004251" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004252 endif
4253
4254 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4255 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004256" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004257 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004258 let dirname= "./"
4259 let curline= getline('.')
4260
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004261 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004262 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004263 let s:netrw_skipbrowse= 1
4264 echo 'Pressing "s" also works'
4265
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004266 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004267 let s:netrw_skipbrowse= 1
4268 echo 'Press "S" to edit sorting sequence'
4269
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004270 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004271 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004272 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004273
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004274 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004275 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004276 let s:netrw_skipbrowse= 1
4277 echo 'Pressing "a" also works'
4278
4279 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004280 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004281 endif
4282
4283 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004284" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004285 NetrwKeepj norm! 0
4286 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004287
4288 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004289" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004290 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004291 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4292
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004293 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004294" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004295 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004296 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004297
4298 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004299" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004300 let dirname= getline('.')
4301
4302 if !exists("b:netrw_cpf")
4303 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004304 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 +01004305 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004306" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004307 endif
4308
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004309" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004310 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004311" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4312" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004313 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004314 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004315 else
4316 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004317 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004318 endif
Enno3146d632024-07-04 19:44:42 +02004319
4320 let dict={}
4321 " save the unnamed register and register 0-9 and a
4322 let dict.a=[getreg('a'), getregtype('a')]
4323 for i in range(0, 9)
4324 let dict[i] = [getreg(i), getregtype(i)]
4325 endfor
4326 let dict.unnamed = [getreg(''), getregtype('')]
4327
Bram Moolenaarc236c162008-07-13 17:41:49 +00004328 let eofname= filestart + b:netrw_cpf + 1
4329 if eofname <= col("$")
4330 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004331 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004332 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004333 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004334 endif
Enno3146d632024-07-04 19:44:42 +02004335
Bram Moolenaar446cb832008-06-24 21:56:24 +00004336 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004337 call s:RestoreRegister(dict)
4338
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004339" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004340 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004341" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004342 endif
4343
4344 " symlinks are indicated by a trailing "@". Remove it before further processing.
4345 let dirname= substitute(dirname,"@$","","")
4346
4347 " executables are indicated by a trailing "*". Remove it before further processing.
4348 let dirname= substitute(dirname,"\*$","","")
4349
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004350 let &l:sol= keepsol
4351
Bram Moolenaar446cb832008-06-24 21:56:24 +00004352" call Dret("s:NetrwGetWord <".dirname.">")
4353 return dirname
4354endfun
4355
4356" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004357" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4358" g:netrw_bufsettings will be used after the listing is produced.
4359" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004360fun! s:NetrwListSettings(islocal)
4361" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004362" 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 +00004363 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004364" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4365 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4366 setl bt=nofile nobl ma nonu nowrap noro nornu
4367 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004368 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004369 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004370 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004371" call Dredir("ls!","s:NetrwListSettings")
4372" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004373 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004374 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004375 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004376 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004377 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004378 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004379 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004380" 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 +00004381" call Dret("s:NetrwListSettings")
4382endfun
4383
4384" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004385" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004386" islocal=0: remote browsing
4387" =1: local browsing
4388fun! s:NetrwListStyle(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004389 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004390 let fname = s:NetrwGetWord()
4391 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004392 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004393 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004394
Bram Moolenaar85850f32019-07-19 22:05:51 +02004395 " repoint t:netrw_lexbufnr if appropriate
4396 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02004397 let repointlexbufnr= 1
4398 endif
4399
Bram Moolenaar446cb832008-06-24 21:56:24 +00004400 if w:netrw_liststyle == s:THINLIST
4401 " use one column listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004402 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4403
4404 elseif w:netrw_liststyle == s:LONGLIST
4405 " use long list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004406 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4407
4408 elseif w:netrw_liststyle == s:WIDELIST
4409 " give wide list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004410 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4411
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004412 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004413 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4414
4415 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004416 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004417 let g:netrw_liststyle = s:THINLIST
4418 let w:netrw_liststyle = g:netrw_liststyle
4419 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4420 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004421 setl ma noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00004422
4423 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004424 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004425 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004426 setl nomod
Bram Moolenaar446cb832008-06-24 21:56:24 +00004427
4428 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01004429 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004430 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004431
Bram Moolenaar85850f32019-07-19 22:05:51 +02004432 " repoint t:netrw_lexbufnr if appropriate
4433 if exists("repointlexbufnr")
4434 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004435 endif
4436
Bram Moolenaar13600302014-05-22 18:26:40 +02004437 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004438" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4439 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004440 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004441
Bram Moolenaar446cb832008-06-24 21:56:24 +00004442endfun
4443
4444" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004445" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4446fun! s:NetrwBannerCtrl(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004447 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004448 " toggle the banner (enable/suppress)
4449 let g:netrw_banner= !g:netrw_banner
4450
4451 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004452 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01004453 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004454
4455 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004456 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4457 let fname= s:NetrwGetWord()
4458 sil NetrwKeepj $
4459 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4460" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4461 if result <= 0 && exists("w:netrw_bannercnt")
4462 exe "NetrwKeepj ".w:netrw_bannercnt
4463 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004464 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004465 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004466" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4467endfun
4468
4469" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004470" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4471"
4472" No bang: enters files/directories into Netrw's bookmark system
4473" No argument and in netrw buffer:
4474" if there are marked files: bookmark marked files
4475" otherwise : bookmark file/directory under cursor
4476" No argument and not in netrw buffer: bookmarks current open file
4477" Has arguments: globs them individually and bookmarks them
4478"
4479" With bang: deletes files/directories from Netrw's bookmark system
4480fun! s:NetrwBookmark(del,...)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004481 if a:0 == 0
4482 if &ft == "netrw"
4483 let curbufnr = bufnr("%")
4484
4485 if exists("s:netrwmarkfilelist_{curbufnr}")
4486 " for every filename in the marked list
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004487 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004488 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004489 for fname in s:netrwmarkfilelist_{curbufnr}
4490 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4491 endfor
4492 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4493 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01004494 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004495 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004496 else
4497 let fname= s:NetrwGetWord()
4498 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4499 endif
4500
4501 else
4502 " bookmark currently open file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004503 let fname= expand("%")
4504 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4505 endif
4506
4507 else
4508 " bookmark specified files
4509 " attempts to infer if working remote or local
4510 " by deciding if the current file begins with an url
4511 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004512 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004513 let i = 1
4514 while i <= a:0
4515 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004516 if v:version > 704 || (v:version == 704 && has("patch656"))
4517 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004518 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004519 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004520 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004521 else
4522 let mbfiles= [a:{i}]
4523 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004524 for mbfile in mbfiles
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004525 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4526 endfor
4527 let i= i + 1
4528 endwhile
4529 endif
4530
4531 " update the menu
4532 call s:NetrwBookmarkMenu()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004533endfun
4534
4535" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004536" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4537" .2.[cnt] for bookmarks, and
4538" .3.[cnt] for history
4539" (see s:NetrwMenu())
4540fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004541 if !exists("s:netrw_menucnt")
4542 return
4543 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004544" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004545
4546 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004547 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004548 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004549" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004550 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4551 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004552 endif
4553 if !exists("s:netrw_initbookhist")
4554 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004555 endif
4556
4557 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004558 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004559 let cnt= 1
4560 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004561" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004562 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004563
4564 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004565 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004566
4567 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004568 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 +01004569 let cnt= cnt + 1
4570 endfor
4571
4572 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004573
4574 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004575 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004576 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004577 let first = 1
4578 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004579 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004580 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004581 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004582 if exists("g:netrw_dirhist_{cnt}")
4583 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004584" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004585 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4586 endif
4587 let first = 0
4588 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4589 if cnt < 0
4590 let cnt= cnt + g:netrw_dirhistmax
4591 endif
4592 endwhile
4593 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004594
Bram Moolenaar9964e462007-05-05 17:54:07 +00004595 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004596" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004597endfun
4598
4599" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004600" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4601" directory and a new directory name. Also, if the
4602" "new directory name" is actually a file,
4603" NetrwBrowseChgDir() edits the file.
Tom Benham64a536d2024-11-07 21:15:03 +01004604" cursor=0: newdir is relative to b:netrw_curdir
4605" =1: newdir is relative to the path to the word under the cursor in
4606" tree view
4607fun! s:NetrwBrowseChgDir(islocal,newdir,cursor,...)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004608 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004609 if !exists("b:netrw_curdir")
4610 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4611 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004612 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004613 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004614 endif
4615
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004616 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02004617 call s:SavePosn(s:netrw_posn)
4618 NetrwKeepj call s:NetrwOptionsSave("s:")
4619 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Tom Benham64a536d2024-11-07 21:15:03 +01004620
4621 let newdir = a:newdir
4622 if a:cursor && exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
4623 " dirname is the path to the word under the cursor
4624 let dirname = s:NetrwTreePath(w:netrw_treetop)
Christian Brabandt5b63b232024-11-10 20:22:34 +01004625 " newdir resolves to a directory and points to a directory in dirname
4626 " /tmp/test/folder_symlink/ -> /tmp/test/original_folder/
4627 if a:islocal && fnamemodify(dirname, ':t') == newdir && isdirectory(resolve(dirname)) && resolve(dirname) == resolve(newdir)
4628 let dirname = fnamemodify(resolve(dirname), ':p:h:h')
4629 let newdir = fnamemodify(resolve(newdir), ':t')
4630 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004631 " Remove trailing "/"
4632 let dirname = substitute(dirname, "/$", "", "")
4633
4634 " If the word under the cursor is a directory (except for ../), NetrwTreePath
4635 " returns the full path, including the word under the cursor, remove it
4636 if newdir =~ "/$" && newdir != "../"
4637 let dirname = fnamemodify(dirname, ":h")
4638 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004639 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004640 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004641 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004642 if has("win32")
4643 let dirname = substitute(dirname,'\\','/','ge')
4644 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004645 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004646 let dorestore = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004647
4648 " ignore <cr>s when done in the banner
4649 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01004650 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004651 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +01004652 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaar13600302014-05-22 18:26:40 +02004653 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004654 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004655 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004656 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara6878372014-03-22 21:02:50 +01004657 endif
4658 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004659 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004660
Bram Moolenaar446cb832008-06-24 21:56:24 +00004661 " set up o/s-dependent directory recognition pattern
4662 if has("amiga")
4663 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004664 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004665 let dirpat= '[\/]$'
4666 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004667
4668 if dirname !~ dirpat
4669 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004670 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004671 let dirname= dirname.'/'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004672 endif
4673
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004674 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004675 " ------------------------------
4676 " NetrwBrowseChgDir: edit a file {{{3
4677 " ------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004678
Bram Moolenaar97d62492012-11-15 21:28:22 +01004679 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004680 let s:rexposn_{bufnr("%")}= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01004681
Bram Moolenaar446cb832008-06-24 21:56:24 +00004682 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004683 if dirname =~ '/$'
4684 let dirname= dirname.newdir
4685 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004686 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004687 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004688 elseif newdir =~ '^\(/\|\a:\)'
4689 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004690 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004691 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004692 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004693 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004694 if a:0 < 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004695 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004696 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004697 if !exists("s:didsplit")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004698 if type(g:netrw_browse_split) == 3
4699 " open file in server
4700 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004701 call s:NetrwServerEdit(a:islocal,dirname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004702 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004703
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004704 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004705 " horizontally splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004706 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4707 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004708 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004709 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004710 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004711 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004712
Bram Moolenaar446cb832008-06-24 21:56:24 +00004713 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004714 " vertically splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004715 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4716 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004717 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004718 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004719 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004720 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004721
Bram Moolenaar446cb832008-06-24 21:56:24 +00004722 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004723 " open file in new tab
Bram Moolenaarff034192013-04-24 18:51:19 +02004724 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004725 if !exists("b:netrw_curdir")
4726 let b:netrw_curdir= getcwd()
4727 endif
4728 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004729
Bram Moolenaar446cb832008-06-24 21:56:24 +00004730 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004731 " act like "P" (ie. open previous window)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004732 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004733 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004734 return
4735 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004736 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004737
Bram Moolenaar9964e462007-05-05 17:54:07 +00004738 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004739 " handling a file, didn't split, so remove menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00004740 call s:NetrwMenu(0)
4741 " optional change to window
4742 if g:netrw_chgwin >= 1
Bram Moolenaar13600302014-05-22 18:26:40 +02004743 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004744 " if g:netrw_chgwin is set to one more than the last window, then
4745 " vertically split the last window to make that window available.
4746 let curwin= winnr()
4747 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4748 vs
4749 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004750 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004751 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004752 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004753 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004754 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004755
Bram Moolenaar9964e462007-05-05 17:54:07 +00004756 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004757
Bram Moolenaar446cb832008-06-24 21:56:24 +00004758 " the point where netrw actually edits the (local) file
4759 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004760 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004761 if !&mod
4762 " if e the new file would fail due to &mod, then don't change any of the flags
4763 let dolockout= 1
4764 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004765 if a:islocal
Bram Moolenaar8d043172014-01-23 14:24:41 +01004766 " some like c-^ to return to the last edited file
4767 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004768 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4769 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004770 call s:NetrwEditFile("e","",dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004771 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004772 if &hidden || &bufhidden == "hide"
4773 " file came from vim's hidden storage. Don't "restore" options with it.
4774 let dorestore= 0
4775 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004776 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00004777 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004778
4779 " handle g:Netrw_funcref -- call external-to-netrw functions
4780 " This code will handle g:Netrw_funcref as an individual function reference
4781 " or as a list of function references. It will ignore anything that's not
4782 " a function reference. See :help Funcref for information about function references.
4783 if exists("g:Netrw_funcref")
4784 if type(g:Netrw_funcref) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004785 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004786 elseif type(g:Netrw_funcref) == 3
4787 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004788 if type(Fncref) == 2
4789 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004790 endif
4791 endfor
4792 endif
4793 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004794 endif
4795
4796 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004797 " ----------------------------------------------------
4798 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4799 " ----------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004800 let dirname = newdir
4801 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004802 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004803 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004804
4805 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004806 " ---------------------------------------------
4807 " NetrwBrowseChgDir: refresh the directory list {{{3
4808 " ---------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004809 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004810 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004811
4812 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004813 " --------------------------------------
4814 " NetrwBrowseChgDir: go up one directory {{{3
4815 " --------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004816
4817 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4818 " force a refresh
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004819 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004820 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004821 endif
4822
4823 if has("amiga")
4824 " amiga
Bram Moolenaar446cb832008-06-24 21:56:24 +00004825 if a:islocal
4826 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4827 let dirname= substitute(dirname,'/$','','')
4828 else
4829 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4830 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004831
Nir Lichtman1e34b952024-05-08 19:19:34 +02004832 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004833 " windows
4834 if a:islocal
4835 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4836 if dirname == ""
4837 let dirname= '/'
4838 endif
4839 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004840 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01004841 endif
4842 if dirname =~ '^\a:$'
4843 let dirname= dirname.'/'
4844 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01004845
Bram Moolenaar446cb832008-06-24 21:56:24 +00004846 else
4847 " unix or cygwin
Bram Moolenaar446cb832008-06-24 21:56:24 +00004848 if a:islocal
4849 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4850 if dirname == ""
4851 let dirname= '/'
4852 endif
4853 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004854 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004855 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004856 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004857 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004858 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004859
4860 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004861 " --------------------------------------
4862 " NetrwBrowseChgDir: Handle Tree Listing {{{3
4863 " --------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004864 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004865 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004866 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004867 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004868 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004869 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004870 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004871 let haskey = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004872
4873 " search treedict for tree dir as-is
4874 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004875 let haskey= 1
4876 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004877 endif
4878
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004879 " search treedict for treedir with a [/@] appended
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004880 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004881 if has_key(w:netrw_treedict,treedir."/")
4882 let treedir= treedir."/"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004883 let haskey = 1
4884 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004885 endif
4886 endif
4887
4888 " search treedict for treedir with any trailing / elided
4889 if !haskey && treedir =~ '/$'
4890 let treedir= substitute(treedir,'/$','','')
4891 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004892 let haskey = 1
4893 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004894 endif
4895 endif
4896
4897 if haskey
4898 " close tree listing for selected subdirectory
Bram Moolenaar446cb832008-06-24 21:56:24 +00004899 call remove(w:netrw_treedict,treedir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004900 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901 else
4902 " go down one directory
4903 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004904 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004905 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004906 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004907
4908 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01004909 " ----------------------------------------
4910 " NetrwBrowseChgDir: Go down one directory {{{3
4911 " ----------------------------------------
4912 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004913 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004914 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00004915 endif
4916
Bram Moolenaar97d62492012-11-15 21:28:22 +01004917 " --------------------------------------
4918 " NetrwBrowseChgDir: Restore and Cleanup {{{3
4919 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02004920 if dorestore
4921 " dorestore is zero'd when a local file was hidden or bufhidden;
4922 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004923 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02004924 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02004925 if dolockout && dorestore
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004926 if filewritable(dirname)
Bram Moolenaar13600302014-05-22 18:26:40 +02004927 setl ma noro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004928 else
Bram Moolenaar13600302014-05-22 18:26:40 +02004929 setl ma ro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004930 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004931 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004932 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004933 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004934
Bram Moolenaar446cb832008-06-24 21:56:24 +00004935 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00004936endfun
4937
4938" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004939" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
4940" for thin, long, and wide: cursor placed just after banner
4941" for tree, keeps cursor on current filename
4942fun! s:NetrwBrowseUpDir(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004943 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
4944 " this test needed because occasionally this function seems to be incorrectly called
4945 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004946 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004947 " directories.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004948 return
4949 endif
4950
Bram Moolenaara6878372014-03-22 21:02:50 +01004951 norm! 0
4952 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara6878372014-03-22 21:02:50 +01004953 let curline= getline(".")
4954 let swwline= winline() - 1
4955 if exists("w:netrw_treetop")
4956 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02004957 elseif exists("b:netrw_curdir")
4958 let w:netrw_treetop= b:netrw_curdir
4959 else
4960 let w:netrw_treetop= getcwd()
4961 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01004962 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004963 let curfile = getline(".")
4964 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01004965 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004966 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004967 else
Tom Benham64a536d2024-11-07 21:15:03 +01004968 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004969 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004970 if w:netrw_treetop == '/'
4971 keepj call search('^\M'.curfile,"w")
4972 elseif curfile == '../'
4973 keepj call search('^\M'.curfile,"wb")
4974 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004975 while 1
4976 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
4977 let treepath= s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004978 if treepath == curpath
4979 break
4980 endif
4981 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01004982 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004983
Bram Moolenaara6878372014-03-22 21:02:50 +01004984 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004985 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004986 if exists("b:netrw_curdir")
4987 let curdir= b:netrw_curdir
4988 else
4989 let curdir= expand(getcwd())
4990 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004991 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004992 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004993 else
Tom Benham64a536d2024-11-07 21:15:03 +01004994 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004995 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004996 call s:RestorePosn(s:netrw_posn)
4997 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01004998 let curdir= '\<'. escape(curdir, '~'). '/'
4999 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005000 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005001endfun
5002
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005003func s:redir()
5004 " set up redirection (avoids browser messages)
5005 " by default if not set, g:netrw_suppress_gx_mesg is true
5006 if get(g:, 'netrw_suppress_gx_mesg', 1)
5007 if &srr =~# "%s"
5008 return printf(&srr, has("win32") ? "nul" : "/dev/null")
5009 else
5010 return &srr .. (has("win32") ? "nul" : "/dev/null")
5011 endif
5012 endif
5013 return ''
5014endfunc
5015
5016if has('unix')
5017 if has('win32unix')
5018 " Cygwin provides cygstart
5019 if executable('cygstart')
5020 fun! netrw#Launch(args)
5021 exe 'silent ! cygstart --hide' a:args s:redir() | redraw!
5022 endfun
5023 elseif !empty($MSYSTEM) && executable('start')
5024 " MSYS2/Git Bash comes by default without cygstart; see
5025 " https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
5026 " Instead it provides /usr/bin/start script running `cmd.exe //c start`
5027 " Adding "" //b` sets void title, hides cmd window and blocks path conversion
5028 " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
5029 fun! netrw#Launch(args)
5030 exe 'silent !start "" //b' a:args s:redir() | redraw!
5031 endfun
5032 else
5033 " imitate /usr/bin/start script for other environments and hope for the best
5034 fun! netrw#Launch(args)
5035 exe 'silent !cmd //c start "" //b' a:args s:redir() | redraw!
5036 endfun
5037 endif
5038 elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
5039 fun! netrw#Launch(args)
5040 let args = a:args
5041 exe 'silent !' ..
5042 \ ((args =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
Konfekt460799d2024-11-14 21:42:27 +01005043 \ 'cmd.exe /c start /b ' .. args :
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005044 \ 'nohup ' .. args .. ' ' .. s:redir() .. ' &')
5045 \ | redraw!
5046 endfun
5047 else
5048 fun! netrw#Launch(args)
Konfekteda923e2024-12-04 20:12:44 +01005049 exe ':silent ! nohup' a:args s:redir() (has('gui_running') ? '' : '&') | redraw!
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005050 endfun
5051 endif
5052elseif has('win32')
5053 fun! netrw#Launch(args)
5054 exe 'silent !' .. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
5055 \ 'start "" /b' a:args s:redir() | redraw!
5056 endfun
5057else
5058 fun! netrw#Launch(dummy)
5059 echom 'No common launcher found'
5060 endfun
5061endif
5062
5063" Git Bash
5064if has('win32unix')
5065 " (cyg)start suffices
5066 let s:os_viewer = ''
5067" Windows / WSL
5068elseif executable('explorer.exe')
5069 let s:os_viewer = 'explorer.exe'
5070" Linux / BSD
5071elseif executable('xdg-open')
5072 let s:os_viewer = 'xdg-open'
5073" MacOS
5074elseif executable('open')
5075 let s:os_viewer = 'open'
5076endif
5077
5078fun! s:viewer()
5079 if exists('g:netrw_browsex_viewer') && executable(g:netrw_browsex_viewer)
5080 " extract any viewing options. Assumes that they're set apart by spaces.
5081 " call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
5082 if g:netrw_browsex_viewer =~ '\s'
5083 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5084 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5085 let oviewer = ''
5086 let cnt = 1
5087 while !executable(viewer) && viewer != oviewer
5088 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5089 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5090 let cnt = cnt + 1
5091 let oviewer = viewer
5092 " call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5093 endwhile
5094 else
5095 let viewer = g:netrw_browsex_viewer
5096 let viewopt = ""
5097 endif
5098 " call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5099 return viewer .. ' ' .. viewopt
5100 else
5101 if !exists('s:os_viewer')
5102 call netrw#ErrorMsg(s:ERROR,"No program to open this path found. See :help Open for more information.",106)
5103 else
5104 return s:os_viewer
5105 endif
5106 endif
5107endfun
5108
5109fun! netrw#Open(file) abort
5110 call netrw#Launch(s:viewer() .. ' ' .. shellescape(a:file, 1))
5111endf
5112
5113if !exists('g:netrw_regex_url')
5114 let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
5115endif
5116
Bram Moolenaara6878372014-03-22 21:02:50 +01005117" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005118" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005119" given filename; typically this means given their extension.
5120" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005121fun! netrw#BrowseX(fname,remote)
Konfekt460799d2024-11-14 21:42:27 +01005122 if a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
Bram Moolenaar91359012019-11-30 17:57:03 +01005123 " remote directory, not a webpage access, looks like an attempt to do a directory listing
Bram Moolenaar91359012019-11-30 17:57:03 +01005124 norm! gf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005125 endif
5126
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005127 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5128 let remote = a:remote
5129 else
5130 let remote = 0
5131 endif
5132
Bram Moolenaar97d62492012-11-15 21:28:22 +01005133 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005134 let screenposn = winsaveview()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005135
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005136 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5137 let awkeep = &aw
5138 set noaw
5139
Bram Moolenaar5c736222010-01-06 20:54:52 +01005140 " special core dump handler
5141 if a:fname =~ '/core\(\.\d\+\)\=$'
5142 if exists("g:Netrw_corehandler")
5143 if type(g:Netrw_corehandler) == 2
5144 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005145 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005146 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005147 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005148 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005149 if type(Fncref) == 2
5150 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005151 endif
5152 endfor
5153 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005154 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005155 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005156 let &aw= awkeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005157 return
5158 endif
5159 endif
5160
Bram Moolenaar446cb832008-06-24 21:56:24 +00005161 " set up the filename
5162 " (lower case the extension, make a local copy of a remote file)
5163 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005164 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005165 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005166 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005167 if exten =~ "[\\/]"
5168 let exten= ""
5169 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005170
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005171 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005172 " create a local copy
Bram Moolenaarff034192013-04-24 18:51:19 +02005173 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005174 call netrw#NetRead(3,a:fname)
5175 " attempt to rename tempfile
5176 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005177 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02005178 if s:netrw_tmpfile != newname && newname != ""
5179 if rename(s:netrw_tmpfile,newname) == 0
5180 " renaming succeeded
Bram Moolenaar85850f32019-07-19 22:05:51 +02005181 let fname= newname
5182 else
5183 " renaming failed
Bram Moolenaar85850f32019-07-19 22:05:51 +02005184 let fname= s:netrw_tmpfile
5185 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005186 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005187 let fname= s:netrw_tmpfile
5188 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005189 else
5190 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005191 " special ~ handler for local
5192 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005193 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005194 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005195 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005196
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005197 " although shellescape(..., 1) is used in netrw#Open(), it's insufficient
5198 call netrw#Open(escape(fname, '#%'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005199
Bram Moolenaar446cb832008-06-24 21:56:24 +00005200 " cleanup: remove temporary file,
5201 " delete current buffer if success with handler,
5202 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005203 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005204 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005205" if remote == 1 && fname != a:fname
Bram Moolenaarc236c162008-07-13 17:41:49 +00005206" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005207" endif
5208
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005209 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005210 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005211 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005212 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005213 endif
Christian Brabandt9f320692024-10-30 18:36:20 +01005214 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005215 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005216 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005217 let @@ = ykeep
5218 let &aw= awkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005219endfun
5220
5221" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005222" netrw#GX: gets word under cursor for gx support {{{2
5223" See also: netrw#BrowseXVis
5224" netrw#BrowseX
5225fun! netrw#GX()
5226" call Dfunc("netrw#GX()")
5227 if &ft == "netrw"
5228 let fname= s:NetrwGetWord()
5229 else
Konfekt3d7e5672024-10-27 22:16:49 +01005230 let fname= exists("g:netrw_gx")? expand(g:netrw_gx) : s:GetURL()
Bram Moolenaar85850f32019-07-19 22:05:51 +02005231 endif
5232" call Dret("netrw#GX <".fname.">")
5233 return fname
5234endfun
5235
Konfekt3d7e5672024-10-27 22:16:49 +01005236fun! s:GetURL() abort
5237 let URL = ''
5238 if exists('*Netrw_get_URL_' .. &filetype)
5239 let URL = call('Netrw_get_URL_' .. &filetype, [])
5240 endif
5241 if !empty(URL) | return URL | endif
5242 " URLs end in letter, digit or forward slash
5243 let URL = matchstr(expand("<cWORD>"), '\<' .. g:netrw_regex_url .. '\ze[^A-Za-z0-9/]*$')
5244 if !empty(URL) | return URL | endif
5245
5246 " Is it a file in the current work dir ...
5247 let file = expand("<cfile>")
5248 if filereadable(file) | return file | endif
5249 " ... or in that of the current buffer?
5250 let path = fnamemodify(expand('%'), ':p')
5251 if isdirectory(path)
5252 let dir = path
5253 elseif filereadable(path)
5254 let dir = fnamemodify(path, ':h')
5255 endif
5256 if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif
5257
5258 return ''
5259endf
5260
Bram Moolenaar85850f32019-07-19 22:05:51 +02005261" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005262" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5263fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005264 let dict={}
5265 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005266 norm! gv"ay
5267 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005268 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005269 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005270endfun
5271
5272" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005273" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5274" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5275" to become an unlisted buffer, so in that case don't bwipe it.
5276fun! s:NetrwBufRename(newname)
5277" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5278" call Dredir("ls!","s:NetrwBufRename (before rename)")
5279 let oldbufname= bufname(bufnr("%"))
5280" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5281
5282 if oldbufname != a:newname
5283" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5284 let b:junk= 1
5285" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5286 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005287" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005288 let oldbufnr= bufnr(oldbufname)
5289" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5290" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5291 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5292" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5293 exe "bwipe! ".oldbufnr
5294" else " Decho
5295" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005296" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5297" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5298" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005299 endif
5300" call Dredir("ls!","s:NetrwBufRename (after rename)")
5301" else " Decho
5302" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5303 endif
5304
5305" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5306endfun
5307
5308" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005309" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005310fun! netrw#CheckIfRemote(...)
5311" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5312 if a:0 > 0
5313 let curfile= a:1
5314 else
5315 let curfile= expand("%")
5316 endif
5317" call Decho("curfile<".curfile.">")
5318 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005319" call Dret("netrw#CheckIfRemote 1")
5320 return 1
5321 else
5322" call Dret("netrw#CheckIfRemote 0")
5323 return 0
5324 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005325endfun
5326
5327" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005328" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5329fun! s:NetrwChgPerm(islocal,curdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005330 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005331 call inputsave()
5332 let newperm= input("Enter new permission: ")
5333 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005334 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5335 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005336 call system(chgperm)
5337 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005338 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005339 endif
5340 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005341 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005342 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005343 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005344endfun
5345
5346" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005347" s:CheckIfKde: checks if kdeinit is running {{{2
5348" Returns 0: kdeinit not running
5349" 1: kdeinit is running
5350fun! s:CheckIfKde()
5351" call Dfunc("s:CheckIfKde()")
5352 " seems kde systems often have gnome-open due to dependencies, even though
5353 " gnome-open's subsidiary display tools are largely absent. Kde systems
5354 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5355 if !exists("s:haskdeinit")
5356 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005357 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005358 if v:shell_error
5359 let s:haskdeinit = 0
5360 endif
5361 else
5362 let s:haskdeinit= 0
5363 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005364" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005365 endif
5366
5367" call Dret("s:CheckIfKde ".s:haskdeinit)
5368 return s:haskdeinit
5369endfun
5370
5371" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005372" s:NetrwClearExplore: clear explore variables (if any) {{{2
5373fun! s:NetrwClearExplore()
5374" call Dfunc("s:NetrwClearExplore()")
5375 2match none
5376 if exists("s:explore_match") |unlet s:explore_match |endif
5377 if exists("s:explore_indx") |unlet s:explore_indx |endif
5378 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5379 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5380 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5381 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5382 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5383 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5384 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5385" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005386" call Dret("s:NetrwClearExplore")
5387endfun
5388
5389" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005390" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5391fun! s:NetrwEditBuf(bufnum)
5392" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5393 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5394" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5395 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5396 else
5397" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005398 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005399 endif
5400" call Dret("s:NetrwEditBuf")
5401endfun
5402
5403" ---------------------------------------------------------------------
5404" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5405" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5406fun! s:NetrwEditFile(cmd,opt,fname)
5407" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5408 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5409" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5410 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5411 else
5412" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005413 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5414 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5415 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005416 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5417 endif
5418" call Dret("s:NetrwEditFile")
5419endfun
5420
5421" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005422" s:NetrwExploreListUniq: {{{2
5423fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005424 " this assumes that the list is already sorted
5425 let newexplist= []
5426 for member in a:explist
5427 if !exists("uniqmember") || member != uniqmember
5428 let uniqmember = member
5429 let newexplist = newexplist + [ member ]
5430 endif
5431 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01005432 return newexplist
5433endfun
5434
5435" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005436" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5437fun! s:NetrwForceChgDir(islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005438 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005439 if a:newdir !~ '/$'
5440 " ok, looks like force is needed to get directory-style treatment
5441 if a:newdir =~ '@$'
5442 let newdir= substitute(a:newdir,'@$','/','')
5443 elseif a:newdir =~ '[*=|\\]$'
5444 let newdir= substitute(a:newdir,'.$','/','')
5445 else
5446 let newdir= a:newdir.'/'
5447 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005448 else
5449 " should already be getting treatment as a directory
5450 let newdir= a:newdir
5451 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005452 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir,0)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005453 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005454 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005455endfun
5456
5457" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005458" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005459" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5460" expr : this is the expression to follow the directory. Will use s:ComposePath()
5461" pare =1: remove the current directory from the resulting glob() filelist
5462" =0: leave the current directory in the resulting glob() filelist
5463fun! s:NetrwGlob(direntry,expr,pare)
5464" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005465 if netrw#CheckIfRemote()
5466 keepalt 1sp
5467 keepalt enew
5468 let keep_liststyle = w:netrw_liststyle
5469 let w:netrw_liststyle = s:THINLIST
5470 if s:NetrwRemoteListing() == 0
5471 keepj keepalt %s@/@@
5472 let filelist= getline(1,$)
5473 q!
5474 else
5475 " remote listing error -- leave treedict unchanged
5476 let filelist= w:netrw_treedict[a:direntry]
5477 endif
5478 let w:netrw_liststyle= keep_liststyle
5479 else
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005480 let path= s:ComposePath(fnameescape(a:direntry), a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005481 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005482 " escape [ so it is not detected as wildcard character, see :h wildcard
5483 let path= substitute(path, '[', '[[]', 'g')
5484 endif
5485 if v:version > 704 || (v:version == 704 && has("patch656"))
5486 let filelist= glob(path,0,1,1)
5487 else
5488 let filelist= glob(path,0,1)
5489 endif
5490 if a:pare
5491 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5492 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005493 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005494 return filelist
5495endfun
5496
5497" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005498" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5499fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005500 if a:newfile =~ '[/@*=|\\]$'
5501 let newfile= substitute(a:newfile,'.$','','')
5502 else
5503 let newfile= a:newfile
5504 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005505 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005506 call s:NetrwBrowseChgDir(a:islocal,newfile,0)
Bram Moolenaarff034192013-04-24 18:51:19 +02005507 else
Tom Benham64a536d2024-11-07 21:15:03 +01005508 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02005509 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005510endfun
5511
5512" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005513" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5514" and switches the hiding mode. The actual hiding is done by
5515" s:NetrwListHide().
5516" g:netrw_hide= 0: show all
5517" 1: show not-hidden files
5518" 2: show hidden files only
5519fun! s:NetrwHide(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005520 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005521 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005522
5523 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005524
5525 " hide the files in the markfile list
5526 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00005527 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5528 " remove fname from hiding list
5529 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5530 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5531 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005532 else
5533 " append fname to hiding list
5534 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5535 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5536 else
5537 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5538 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005539 endif
5540 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005541 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005542 let g:netrw_hide= 1
5543
5544 else
5545
5546 " switch between show-all/show-not-hidden/show-hidden
5547 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005548 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005549 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005550 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005551 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005552 return
5553 endif
5554 endif
5555
Tom Benham64a536d2024-11-07 21:15:03 +01005556 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005557 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005558 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005559endfun
5560
5561" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005562" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5563fun! s:NetrwHideEdit(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005564 let ykeep= @@
5565 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005566 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005567
5568 " get new hiding list from user
5569 call inputsave()
5570 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5571 call inputrestore()
5572 let g:netrw_list_hide= newhide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005573
5574 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01005575 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./",0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005576
5577 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005578 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005579 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005580endfun
5581
5582" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005583" s:NetrwHidden: invoked by "gh" {{{2
5584fun! s:NetrwHidden(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005585 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005586 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005587 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005588
5589 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005590 " remove .file pattern from hiding list
Bram Moolenaar446cb832008-06-24 21:56:24 +00005591 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005592 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005593 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5594 else
5595 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5596 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005597 if g:netrw_list_hide =~ '^,'
5598 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5599 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005600
5601 " refresh screen and return to saved position
Tom Benham64a536d2024-11-07 21:15:03 +01005602 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005603 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005604 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005605endfun
5606
5607" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005608" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5609fun! s:NetrwHome()
5610 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005611 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005612 else
5613 " go to vim plugin home
5614 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005615 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005616 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005617 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005618 let home= basehome."/.vim"
5619 break
5620 endif
5621 endfor
5622 if home == ""
5623 " just pick the first directory
5624 let home= substitute(&rtp,',.*$','','')
5625 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005626 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005627 let home= substitute(home,'/','\\','g')
5628 endif
5629 endif
5630 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005631 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005632" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005633 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005634" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005635 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005636 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005637" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005638 call mkdir(home)
5639 endif
5640 endif
5641 let g:netrw_home= home
5642 return home
5643endfun
5644
5645" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005646" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5647fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005648 if exists("s:netrwdrag")
5649 return
5650 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005651 if &ft != "netrw"
5652 return
5653 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005654
Bram Moolenaar97d62492012-11-15 21:28:22 +01005655 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005656 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005657 while getchar(0) != 0
5658 "clear the input stream
5659 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005660 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005661 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005662 let mouse_lnum = v:mouse_lnum
5663 let wlastline = line('w$')
5664 let lastline = line('$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005665 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5666 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005667 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005668 return
5669 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005670 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005671 " 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 +01005672 " without this test when its disabled.
5673 " May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005674 if v:mouse_col > virtcol('.')
5675 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005676 return
5677 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005678
Bram Moolenaar446cb832008-06-24 21:56:24 +00005679 if a:islocal
5680 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005681 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005682 endif
5683 else
5684 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005685 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005686 endif
5687 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005688 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005689endfun
5690
5691" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005692" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5693fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005694 if &ft != "netrw"
5695 return
5696 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005697 call s:NetrwMarkFileTgt(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005698endfun
5699
5700" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005701" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5702" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005703" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005704" a:islocal=2 : <c-r> used, remote
5705" a:islocal=3 : <c-r> used, local
5706fun! s:NetrwServerEdit(islocal,fname)
5707" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5708 let islocal = a:islocal%2 " =0: remote =1: local
5709 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
5710
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005711 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005712 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005713 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005714 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005715 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005716 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5717 unlet s:netrw_browse_split_{winnr()}
5718 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005719 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005720 return
5721 endif
5722
5723 if has("clientserver") && executable("gvim")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005724
5725 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005726 let srvrname = g:netrw_browse_split[0]
5727 let tabnum = g:netrw_browse_split[1]
5728 let winnum = g:netrw_browse_split[2]
5729
5730 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005731 if !ctrlr
5732 " user must have closed the server window and the user did not use <c-r>, but
5733 " used something like <cr>.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005734 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005735 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005736 endif
5737 let g:netrw_browse_split= 0
5738 if exists("s:netrw_browse_split_".winnr())
5739 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5740 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005741 call s:NetrwBrowseChgDir(islocal,a:fname,0)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005742 return
5743
5744 elseif has("win32") && executable("start")
5745 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005746 call system("start gvim --servername ".srvrname)
5747
5748 else
5749 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005750 call system("gvim --servername ".srvrname)
5751 endif
5752 endif
5753
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005754 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5755 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005756 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005757 else
5758
5759 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5760
5761 if !ctrlr
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005762 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005763 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005764 endif
5765 let g:netrw_browse_split= 0
Tom Benham64a536d2024-11-07 21:15:03 +01005766 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005767 return
5768
5769 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005770 if has("win32") && executable("start")
5771 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005772 call system("start gvim --servername ".g:netrw_servername)
5773 else
5774 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005775 call system("gvim --servername ".g:netrw_servername)
5776 endif
5777 endif
5778 endif
5779
5780 while 1
5781 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005782 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005783 break
5784 catch /^Vim\%((\a\+)\)\=:E241/
5785 sleep 200m
5786 endtry
5787 endwhile
5788
5789 if exists("g:netrw_browse_split")
5790 if type(g:netrw_browse_split) != 3
5791 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
5792 endif
5793 unlet g:netrw_browse_split
5794 endif
5795 let g:netrw_browse_split= [g:netrw_servername,1,1]
5796 endif
5797
5798 else
5799 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
5800 endif
5801
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005802endfun
5803
5804" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005805" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
5806fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005807 if &ft != "netrw"
5808 return
5809 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005810" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005811
Bram Moolenaar8d043172014-01-23 14:24:41 +01005812 let s:ngw= s:NetrwGetWord()
5813 call s:NetrwMarkFile(a:islocal,s:ngw)
5814
5815" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02005816endfun
5817
5818" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005819" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
5820" Used to mark multiple files.
5821fun! s:NetrwSLeftdrag(islocal)
5822" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
5823 if !exists("s:netrwdrag")
5824 let s:netrwdrag = winnr()
5825 if a:islocal
5826 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005827 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01005828 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005829 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005830 endif
5831 let ngw = s:NetrwGetWord()
5832 if !exists("s:ngw") || s:ngw != ngw
5833 call s:NetrwMarkFile(a:islocal,ngw)
5834 endif
5835 let s:ngw= ngw
5836" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5837endfun
5838
5839" ---------------------------------------------------------------------
5840" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
5841fun! s:NetrwSLeftrelease(islocal)
5842" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5843 if exists("s:netrwdrag")
5844 nunmap <s-leftrelease>
5845 let ngw = s:NetrwGetWord()
5846 if !exists("s:ngw") || s:ngw != ngw
5847 call s:NetrwMarkFile(a:islocal,ngw)
5848 endif
5849 if exists("s:ngw")
5850 unlet s:ngw
5851 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005852 unlet s:netrwdrag
5853 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005854" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02005855endfun
5856
5857" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01005858" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
5859" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00005860fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005861" 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 +02005862" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005863 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005864
5865 " 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 +02005866 " How-it-works: take the hiding command, convert it into a range.
5867 " Duplicate characters don't matter.
5868 " Remove all such characters from the '/~@#...890' string.
5869 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005870" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005871 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01005872 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005873" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005874
5875 while listhide != ""
5876 if listhide =~ ','
5877 let hide = substitute(listhide,',.*$','','e')
5878 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
5879 else
5880 let hide = listhide
5881 let listhide = ""
5882 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005883" 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 +01005884 if g:netrw_sort_by =~ '^[ts]'
5885 if hide =~ '^\^'
5886" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
5887 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
5888 elseif hide =~ '^\\(\^'
5889 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
5890 endif
5891" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
5892 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005893
5894 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005895" 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 +00005896 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005897" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005898 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005899 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005900" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005901 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005902 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005903" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005904 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02005905
Bram Moolenaar446cb832008-06-24 21:56:24 +00005906 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005907 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005908" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005909 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005910" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005911 endif
5912
Bram Moolenaaradc21822011-04-01 18:03:16 +02005913 " remove any blank lines that have somehow remained.
5914 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005915 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02005916
Bram Moolenaar97d62492012-11-15 21:28:22 +01005917 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005918" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005919endfun
5920
5921" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005922" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005923" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005924fun! s:NetrwMakeDir(usrhost)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005925
Bram Moolenaar97d62492012-11-15 21:28:22 +01005926 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005927 " get name of new directory from user. A bare <CR> will skip.
5928 " if its currently a directory, also request will be skipped, but with
5929 " a message.
5930 call inputsave()
5931 let newdirname= input("Please give directory name: ")
5932 call inputrestore()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005933
5934 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01005935 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005936 return
5937 endif
5938
5939 if a:usrhost == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005940
5941 " Local mkdir:
5942 " sanity checks
5943 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005944 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005945 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005946 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005947 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005948 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005949 return
5950 endif
5951 if s:FileReadable(fullnewdir)
5952 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005953 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005954 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005955 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005956 return
5957 endif
5958
5959 " requested new local directory is neither a pre-existing file or
5960 " directory, so make it!
5961 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005962 if has("unix")
5963 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
5964 else
5965 call mkdir(fullnewdir,"p")
5966 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005967 else
5968 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005969 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005970 return
5971 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005972 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005973 if v:shell_error != 0
5974 let @@= ykeep
5975 call netrw#ErrorMsg(s:ERROR,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005976 return
5977 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005978 if !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02005979 if s:NetrwLcd(netrw_origdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005980 return
5981 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005982 endif
5983 endif
5984
5985 if v:shell_error == 0
5986 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005987 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01005988 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005989 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005990 elseif !exists("g:netrw_quiet")
5991 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
5992 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005993
5994 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01005995 " Remote mkdir: using ssh
Bram Moolenaar446cb832008-06-24 21:56:24 +00005996 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
5997 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005998 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005999 if v:shell_error == 0
6000 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006001 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01006002 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006003 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006004 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006005 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006006 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006007
6008 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006009 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006010 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01006011 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01006012 let remotepath= b:netrw_fname
6013 else
6014 let remotepath= ""
6015 endif
6016 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01006017 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006018 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006019
Bram Moolenaar446cb832008-06-24 21:56:24 +00006020 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006021 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006022 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01006023 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01006024 let remotepath= b:netrw_fname
6025 else
6026 let remotepath= ""
6027 endif
6028 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01006029 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006030 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006031 endif
6032
Bram Moolenaar97d62492012-11-15 21:28:22 +01006033 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006034endfun
6035
6036" ---------------------------------------------------------------------
6037" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6038fun! s:TreeSqueezeDir(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006039 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6040 " its a tree-listing style
6041 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006042 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006043 let depth = strchars(substitute(curdepth,' ','','g'))
6044 let srch = -1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006045 if depth >= 2
6046 NetrwKeepj norm! 0
6047 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6048 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006049 elseif depth == 1
6050 NetrwKeepj norm! 0
6051 let treedepthchr= substitute(s:treedepthstring,' ','','')
6052 let srch = search('^[^'.treedepthchr.']','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006053 endif
6054 if srch > 0
Tom Benham64a536d2024-11-07 21:15:03 +01006055 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord(),1))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006056 exe srch
6057 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006058 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006059endfun
6060
6061" ---------------------------------------------------------------------
6062" s:NetrwMaps: {{{2
6063fun! s:NetrwMaps(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006064
Bram Moolenaar85850f32019-07-19 22:05:51 +02006065 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006066 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006067" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006068 if !hasmapto("<Plug>NetrwReturn")
6069 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006070 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6071 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006072 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6073 endif
6074 endif
6075 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006076 endif
6077
Bram Moolenaar85850f32019-07-19 22:05:51 +02006078 " generate default <Plug> maps {{{3
6079 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006080 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006081 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6082 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6083 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6084 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6085 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6086 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6087 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6088 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6089 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6090 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006091
Bram Moolenaara6878372014-03-22 21:02:50 +01006092 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02006093 " local normal-mode maps {{{3
6094 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6095 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6096 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6097 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6098 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6099 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6100 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006101 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006102 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6103 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6104 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6105" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006106 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6107 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6108 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006109 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006110 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006111 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6112 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6113 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6114 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006115 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6116 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6117 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6118 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6119 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6120 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6121 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6122 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6123 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6124 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6125 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6126 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6127 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006128 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006129 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006130 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6131 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6132 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6133 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6134 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006135 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006136 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006137 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,1))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006138 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006139 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6140 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6141 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006142 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006143 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006144 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6145 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006146 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006147 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006148 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6149 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6150 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006151 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,0),0)"<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006152 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006153
Tom Benham64a536d2024-11-07 21:15:03 +01006154 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,'./',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006155 if !hasmapto('<Plug>NetrwHideEdit')
6156 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006157 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006158 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006159 if !hasmapto('<Plug>NetrwRefresh')
6160 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006161 endif
Tom Benham64a536d2024-11-07 21:15:03 +01006162 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 : './',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006163 if s:didstarstar || !mapcheck("<s-down>","n")
6164 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006165 endif
6166 if s:didstarstar || !mapcheck("<s-up>","n")
6167 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006168 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006169 if !hasmapto('<Plug>NetrwTreeSqueeze')
6170 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006171 endif
6172 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006173 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6174 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006175 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6176 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6177 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6178 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6179 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6180 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6181 imap <buffer> <leftmouse> <Plug>ILeftmouse
6182 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006183 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6184 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6185 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6186 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6187 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006188 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006189 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6190 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006191 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006192 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6193 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6194 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6195 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6196 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6197 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6198 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006199 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6200
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006201 " support user-specified maps
6202 call netrw#UserMaps(1)
6203
Bram Moolenaar85850f32019-07-19 22:05:51 +02006204 else
6205 " remote normal-mode maps {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006206 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006207 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6208 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6209 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6210 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6211 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6212 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6213 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006214 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
6215 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord(),1))<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006216 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6217 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6218" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006219 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6220 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6221 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6222 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6223 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6224 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6225 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6226 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006227 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006228 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006229 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6230 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6231 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6232 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6233 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6234 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6235 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6236 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6237 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6238 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6239 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006240 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006241 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006242 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6243 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6244 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6245 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6246 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006247 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6248 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006249 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,1))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006250 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006251 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006252 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6253 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006254 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006255 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,'./',0))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006256 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6257 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6258 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6259 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6260 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6261 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6262 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6263 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006264 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord(),1),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006265 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006266 if !hasmapto('<Plug>NetrwHideEdit')
6267 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006268 endif
6269 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6270 if !hasmapto('<Plug>NetrwRefresh')
6271 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006272 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006273 if !hasmapto('<Plug>NetrwTreeSqueeze')
6274 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006275 endif
6276 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006277
6278 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006279 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006280
Tom Benham64a536d2024-11-07 21:15:03 +01006281 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006282 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006283 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006284 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006285 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006286 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006287 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006288 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006289 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006290 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006291 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006292 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006293 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6294 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6295 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006296 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006297 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006298 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6299 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006300 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006301 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6302 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6303 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6304 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6305 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6306 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6307 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006308 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006309
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006310 " support user-specified maps
6311 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006312 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006313endfun
6314
6315" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006316" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006317" If -buffer, the command is only available from within netrw buffers
6318" Otherwise, the command is available from any window, so long as netrw
6319" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006320fun! s:NetrwCommands(islocal)
6321" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6322
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006323 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6324 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006325 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 +01006326 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006327 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006328 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006329 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006330 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006331 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006332
6333" call Dret("s:NetrwCommands")
6334endfun
6335
6336" ---------------------------------------------------------------------
6337" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6338" glob()ing only works with local files
6339fun! s:NetrwMarkFiles(islocal,...)
6340" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006341 let curdir = s:NetrwGetCurdir(a:islocal)
6342 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006343 while i <= a:0
6344 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006345 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006346 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006347 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006348 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006349 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006350 else
6351 let mffiles= [a:{i}]
6352 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006353" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006354 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006355" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006356 call s:NetrwMarkFile(a:islocal,mffile)
6357 endfor
6358 let i= i + 1
6359 endwhile
6360" call Dret("s:NetrwMarkFiles")
6361endfun
6362
6363" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006364" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006365fun! s:NetrwMarkTarget(...)
Bram Moolenaara6878372014-03-22 21:02:50 +01006366 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006367 let curdir = s:NetrwGetCurdir(1)
6368 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006369 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006370 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6371 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006372 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006373 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006374 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6375 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006376 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01006377 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006378 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006379endfun
6380
6381" ---------------------------------------------------------------------
6382" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6383" mark and unmark files. If a markfile list exists,
6384" then the rename and delete functions will use it instead
6385" of whatever may happen to be under the cursor at that
6386" moment. When the mouse and gui are available,
6387" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006388"
6389" Creates two lists
6390" s:netrwmarkfilelist -- holds complete paths to all marked files
6391" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6392"
6393" Creates a marked file match string
6394" s:netrwmarfilemtch_# -- used with 2match to display marked files
6395"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006396" Creates a buffer version of islocal
6397" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006398fun! s:NetrwMarkFile(islocal,fname)
6399" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006400" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006401
6402 " sanity check
6403 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006404" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006405 return
6406 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006407 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006408
Bram Moolenaar97d62492012-11-15 21:28:22 +01006409 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006410 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006411 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006412 if a:fname =~ '\a$'
6413 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6414 else
6415 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6416 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006417
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006418 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006419 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006420" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6421" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6422" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006423 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006424
6425 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006426 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006427" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006428 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006429 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006430
6431 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006432 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006433" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006434 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6435 if s:netrwmarkfilelist_{curbufnr} == []
6436 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006437" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006438 call s:NetrwUnmarkList(curbufnr,curdir)
6439 else
6440 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006441" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006442 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006443 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006444 for fname in s:netrwmarkfilelist_{curbufnr}
6445 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006446 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006447 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006448 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006449 endif
6450 let first= 0
6451 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006452" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006453 endif
6454 endif
6455
6456 else
6457 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006458" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006459
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006460" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006461 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006462 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6463" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006464
6465 " build initial markfile matching pattern
6466 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006467 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006468 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006469 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006470 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006471" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006472 endif
6473
6474 " handle global markfilelist
6475 if exists("s:netrwmarkfilelist")
6476 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6477 if index(s:netrwmarkfilelist,dname) == -1
6478 " append new filename to global markfilelist
6479 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006480" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006481 else
6482 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006483" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6484" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006485 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006486" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006487 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006488" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006489 unlet s:netrwmarkfilelist
6490 endif
6491 endif
6492 else
6493 " initialize new global-directory markfilelist
6494 let s:netrwmarkfilelist= []
6495 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006496" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006497 endif
6498
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006499 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006500 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6501 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6502" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6503 if exists("g:did_drchip_netrwlist_syntax")
6504 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6505 endif
6506 else
6507" " call Decho("2match none",'~'.expand("<slnum>"))
6508 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006509 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006510 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006511 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006512" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6513" 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 +00006514endfun
6515
6516" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006517" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6518" mA: move the argument list to marked file list (tomflist=1)
6519" Uses the global marked file list
6520fun! s:NetrwMarkFileArgList(islocal,tomflist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006521 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006522 let curdir = s:NetrwGetCurdir(a:islocal)
6523 let curbufnr = bufnr("%")
6524
6525 if a:tomflist
6526 " mA: move argument list to marked file list
6527 while argc()
6528 let fname= argv(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006529 exe "argdel ".fnameescape(fname)
6530 call s:NetrwMarkFile(a:islocal,fname)
6531 endwhile
6532
6533 else
6534 " ma: move marked file list to argument list
6535 if exists("s:netrwmarkfilelist")
6536
6537 " for every filename in the marked list
6538 for fname in s:netrwmarkfilelist
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006539 exe "argadd ".fnameescape(fname)
6540 endfor " for every file in the marked list
6541
6542 " unmark list and refresh
6543 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006544 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006545 NetrwKeepj call winrestview(svpos)
6546 endif
6547 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006548endfun
6549
6550" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006551" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6552" compress/decompress files using the programs
6553" in g:netrw_compress and g:netrw_uncompress,
6554" using g:netrw_compress_suffix to know which to
6555" do. By default:
6556" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006557" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006558fun! s:NetrwMarkFileCompress(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006559 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006560 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006561 let curbufnr = bufnr("%")
6562
Bram Moolenaarff034192013-04-24 18:51:19 +02006563 " sanity check
6564 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006565 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006566 return
6567 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006568
Bram Moolenaar446cb832008-06-24 21:56:24 +00006569 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006570
6571 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006572 for fname in s:netrwmarkfilelist_{curbufnr}
Christian Brabandtcacfccf2024-11-23 13:28:01 +01006573 let sfx= substitute(fname,'^.\{-}\(\.[[:alnum:]]\+\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006574 if exists("g:netrw_decompress['".sfx."']")
6575 " fname has a suffix indicating that its compressed; apply associated decompression routine
6576 let exe= g:netrw_decompress[sfx]
Bram Moolenaarff034192013-04-24 18:51:19 +02006577 let exe= netrw#WinPath(exe)
6578 if a:islocal
6579 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006580 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006581 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006582 call system(exe." ".fname)
6583 if v:shell_error
6584 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006585 endif
6586 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006587 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6588 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006589 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006590
Bram Moolenaarff034192013-04-24 18:51:19 +02006591 endif
6592 unlet sfx
6593
Bram Moolenaar446cb832008-06-24 21:56:24 +00006594 if exists("exe")
6595 unlet exe
6596 elseif a:islocal
6597 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006598 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006599 if v:shell_error
6600 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6601 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006602 else
6603 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006604 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006605 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006606 endfor " for every file in the marked list
6607
Bram Moolenaar446cb832008-06-24 21:56:24 +00006608 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006609 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006610 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006611 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006612endfun
6613
6614" ---------------------------------------------------------------------
6615" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6616" If no marked files, then set up directory as the
6617" target. Currently does not support copying entire
6618" directories. Uses the local-buffer marked file list.
6619" Returns 1=success (used by NetrwMarkFileMove())
6620" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006621fun! s:NetrwMarkFileCopy(islocal,...)
6622" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6623
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006624 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006625 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006626 if b:netrw_curdir !~ '/$'
6627 if !exists("b:netrw_curdir")
6628 let b:netrw_curdir= curdir
6629 endif
6630 let b:netrw_curdir= b:netrw_curdir."/"
6631 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006632
Bram Moolenaarff034192013-04-24 18:51:19 +02006633 " sanity check
6634 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006635 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006636" call Dret("s:NetrwMarkFileCopy")
6637 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006638 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006639" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006640
Bram Moolenaar446cb832008-06-24 21:56:24 +00006641 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006642 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006643" call Dret("s:NetrwMarkFileCopy 0")
6644 return 0
6645 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006646" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006647
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006648 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006649 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006650" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006651 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006652 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
6653" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
6654 return
6655 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006656
6657 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02006658 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006659 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
6660 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006661" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006662 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006663 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
6664 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006665" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006666 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006667 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006668 let oldname = a:1
6669 else
6670 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006671" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006672 let s:recursive= 1
6673 for oldname in s:netrwmarkfilelist_{bufnr("%")}
6674 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
6675 if ret == 0
6676 break
6677 endif
6678 endfor
6679 unlet s:recursive
6680 call s:NetrwUnmarkList(curbufnr,curdir)
6681" call Dret("s:NetrwMarkFileCopy ".ret)
6682 return ret
6683 endif
6684
6685 call inputsave()
6686 let newname= input("Copy ".oldname." to : ",oldname,"file")
6687 call inputrestore()
6688 if newname == ""
6689" call Dret("s:NetrwMarkFileCopy 0")
6690 return 0
6691 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006692 let args= s:ShellEscape(oldname)
6693 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006694 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006695 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
6696 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006697 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02006698 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02006699 let args= substitute(args,'/','\\','g')
6700 let tgt = substitute(tgt, '/','\\','g')
6701 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006702 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
6703 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
6704 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
6705 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
6706" call Decho("args <".args.">",'~'.expand("<slnum>"))
6707" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006708 if isdirectory(s:NetrwFile(args))
6709" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006710 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006711" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02006712 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006713 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
6714 " contents to a target. One must append the source directory name to the target to get xcopy to
6715 " do the right thing.
6716 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006717" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006718 endif
6719 else
6720 let copycmd= g:netrw_localcopycmd
6721 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006722 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006723 let copycmd = substitute(copycmd,'\s.*$','','')
6724 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006725 let copycmd = netrw#WinPath(copycmd).copycmdargs
6726 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006727 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02006728 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006729" call Decho("args <".args.">",'~'.expand("<slnum>"))
6730" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
6731" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
6732" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006733 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006734 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02006735 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02006736 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 +01006737 else
6738 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
6739 endif
6740" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006741 return 0
6742 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006743
6744 elseif a:islocal && !s:netrwmftgt_islocal
6745 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006746" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006747 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006748
6749 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006750 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006751" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006752 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006753
6754 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006755 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006756" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006757 let curdir = getcwd()
6758 let tmpdir = s:GetTempfile("")
6759 if tmpdir !~ '/'
6760 let tmpdir= curdir."/".tmpdir
6761 endif
6762 if exists("*mkdir")
6763 call mkdir(tmpdir)
6764 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006765 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006766 if v:shell_error != 0
6767 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 +01006768" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01006769 return
6770 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006771 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006772 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006773 if s:NetrwLcd(tmpdir)
6774" call Dret("s:NetrwMarkFileCopy : lcd failure")
6775 return
6776 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006777 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006778 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006779 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006780 if getcwd() == tmpdir
6781 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006782 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006783 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02006784 if s:NetrwLcd(curdir)
6785" call Dret("s:NetrwMarkFileCopy : lcd failure")
6786 return
6787 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01006788 if delete(tmpdir,"d")
6789 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006790 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006791 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006792 if s:NetrwLcd(curdir)
6793" call Dret("s:NetrwMarkFileCopy : lcd failure")
6794 return
6795 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006796 endif
6797 endif
6798 endif
6799
6800 " -------
6801 " cleanup
6802 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006803" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006804 " remove markings from local buffer
6805 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006806" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
6807" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
6808" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
6809" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
6810" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
6811" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
6812 if exists("s:recursive")
6813" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
6814 else
6815" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006816 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006817 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01006818 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006819 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006820 else
6821 " refresh local and targets for fast browsing
6822 if !exists("s:recursive")
6823 " remove markings from local buffer
6824" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
6825 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
6826 endif
6827
6828 " refresh buffers
6829 if s:netrwmftgt_islocal
6830" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
6831 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
6832 endif
6833 if a:islocal && s:netrwmftgt != curdir
6834" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
6835 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
6836 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006837 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006838
Bram Moolenaar446cb832008-06-24 21:56:24 +00006839" call Dret("s:NetrwMarkFileCopy 1")
6840 return 1
6841endfun
6842
6843" ---------------------------------------------------------------------
6844" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
6845" invoke vim's diff mode on the marked files.
6846" Either two or three files can be so handled.
6847" Uses the global marked file list.
6848fun! s:NetrwMarkFileDiff(islocal)
6849" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6850 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006851
Bram Moolenaarff034192013-04-24 18:51:19 +02006852 " sanity check
6853 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006854 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006855" call Dret("s:NetrwMarkFileDiff")
6856 return
6857 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006858 let curdir= s:NetrwGetCurdir(a:islocal)
6859" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006860
Bram Moolenaara6878372014-03-22 21:02:50 +01006861 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006862 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00006863 for fname in s:netrwmarkfilelist
6864 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006865 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006866" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006867 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006868 diffthis
6869 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09006870 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006871" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006872 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006873 diffthis
6874 else
6875 break
6876 endif
6877 endfor
6878 call s:NetrwUnmarkList(curbufnr,curdir)
6879 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006880
Bram Moolenaar446cb832008-06-24 21:56:24 +00006881" call Dret("s:NetrwMarkFileDiff")
6882endfun
6883
6884" ---------------------------------------------------------------------
6885" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
6886" Uses global markfilelist
6887fun! s:NetrwMarkFileEdit(islocal)
6888" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
6889
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006890 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006891 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006892
6893 " sanity check
6894 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006895 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006896" call Dret("s:NetrwMarkFileEdit")
6897 return
6898 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006899" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006900
Bram Moolenaar446cb832008-06-24 21:56:24 +00006901 if exists("s:netrwmarkfilelist_{curbufnr}")
6902 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006903 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006904 " unmark markedfile list
6905" call s:NetrwUnmarkList(curbufnr,curdir)
6906 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006907" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02006908 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00006909 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006910 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006911
Bram Moolenaar446cb832008-06-24 21:56:24 +00006912" call Dret("s:NetrwMarkFileEdit")
6913endfun
6914
6915" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006916" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02006917fun! s:NetrwMarkFileQFEL(islocal,qfel)
6918" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
6919 call s:NetrwUnmarkAll()
6920 let curbufnr= bufnr("%")
6921
6922 if !empty(a:qfel)
6923 for entry in a:qfel
6924 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006925" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006926 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006927" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006928 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6929 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
6930 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
6931 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006932" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006933 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6934 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006935" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006936 endif
6937 endfor
6938 echo "(use me to edit marked files)"
6939 else
6940 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
6941 endif
6942
6943" call Dret("s:NetrwMarkFileQFEL")
6944endfun
6945
6946" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006947" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
6948" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
6949" mX enbloc=1: Uses the global marked-file list, applies command to entire list
6950fun! s:NetrwMarkFileExe(islocal,enbloc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006951 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006952 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006953 let curbufnr = bufnr("%")
6954
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006955 if a:enbloc == 0
6956 " individually apply command to files, one at a time
6957 " sanity check
6958 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6959 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006960 return
6961 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006962
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006963 if exists("s:netrwmarkfilelist_{curbufnr}")
6964 " get the command
6965 call inputsave()
6966 let cmd= input("Enter command: ","","file")
6967 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006968 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006969 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006970 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006971
6972 " apply command to marked files, individually. Substitute: filename -> %
6973 " If no %, then append a space and the filename to the command
6974 for fname in s:netrwmarkfilelist_{curbufnr}
6975 if a:islocal
6976 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09006977 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006978 endif
6979 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006980 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006981 endif
6982 if cmd =~ '%'
6983 let xcmd= substitute(cmd,'%',fname,'g')
6984 else
6985 let xcmd= cmd.' '.fname
6986 endif
6987 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006988 let ret= system(xcmd)
6989 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006990 let ret= s:RemoteSystem(xcmd)
6991 endif
6992 if v:shell_error < 0
6993 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
6994 break
6995 else
yasudac75dad02024-08-22 21:06:32 +02006996 if ret !=# ''
6997 echo "\n"
6998 " skip trailing new line
6999 echo ret[0:-2]
7000 else
7001 echo ret
7002 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007003 endif
7004 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007005
7006 " unmark marked file list
7007 call s:NetrwUnmarkList(curbufnr,curdir)
7008
7009 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007010 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007011 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007012 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007013 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007014 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007015
7016 else " apply command to global list of files, en bloc
7017
7018 call inputsave()
7019 let cmd= input("Enter command: ","","file")
7020 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007021 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007022 return
7023 endif
7024 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007025 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007026 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007027 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007028 endif
7029 if a:islocal
7030 call system(cmd)
7031 if v:shell_error < 0
7032 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7033 endif
7034 else
7035 let ret= s:RemoteSystem(cmd)
7036 endif
7037 call s:NetrwUnmarkAll()
7038
7039 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007040 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007041 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007042
7043 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007044endfun
7045
7046" ---------------------------------------------------------------------
7047" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7048" as the marked file(s) (toggles suffix presence)
7049" Uses the local marked file list.
7050fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007051 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007052 let curbufnr = bufnr("%")
7053
7054 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7055 if exists("s:netrwmarkfilelist_{curbufnr}")
7056
7057 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007058 " construct suffix pattern
7059 if fname =~ '\.'
7060 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7061 else
7062 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7063 endif
7064 " determine if its in the hiding list or not
7065 let inhidelist= 0
7066 if g:netrw_list_hide != ""
7067 let itemnum = 0
7068 let hidelist= split(g:netrw_list_hide,',')
7069 for hidepat in hidelist
7070 if sfxpat == hidepat
7071 let inhidelist= 1
7072 break
7073 endif
7074 let itemnum= itemnum + 1
7075 endfor
7076 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007077 if inhidelist
7078 " remove sfxpat from list
7079 call remove(hidelist,itemnum)
7080 let g:netrw_list_hide= join(hidelist,",")
7081 elseif g:netrw_list_hide != ""
7082 " append sfxpat to non-empty list
7083 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7084 else
7085 " set hiding list to sfxpat
7086 let g:netrw_list_hide= sfxpat
7087 endif
7088 endfor
7089
7090 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007091 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007092 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007093 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007094 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007095 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007096endfun
7097
7098" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007099" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007100" Uses the local marked-file list.
7101fun! s:NetrwMarkFileVimCmd(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007102 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007103 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007104 let curbufnr = bufnr("%")
7105
Bram Moolenaarff034192013-04-24 18:51:19 +02007106 " sanity check
7107 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007108 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007109 return
7110 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007111
Bram Moolenaar15146672011-10-20 22:22:38 +02007112 if exists("s:netrwmarkfilelist_{curbufnr}")
7113 " get the command
7114 call inputsave()
7115 let cmd= input("Enter vim command: ","","file")
7116 call inputrestore()
Bram Moolenaar15146672011-10-20 22:22:38 +02007117 if cmd == ""
Bram Moolenaar15146672011-10-20 22:22:38 +02007118 return
7119 endif
7120
7121 " apply command to marked files. Substitute: filename -> %
7122 " If no %, then append a space and the filename to the command
7123 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007124 if a:islocal
7125 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007126 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaar15146672011-10-20 22:22:38 +02007127 exe cmd
7128 exe "sil! keepalt wq!"
7129 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007130 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007131 endif
7132 endfor
7133
7134 " unmark marked file list
7135 call s:NetrwUnmarkList(curbufnr,curdir)
7136
7137 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007138 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007139 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007140 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007141 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007142 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007143endfun
7144
7145" ---------------------------------------------------------------------
7146" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7147" as the marked file(s) (toggles suffix presence)
7148" Uses the local marked file list.
7149fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007150 let svpos = winsaveview()
Bram Moolenaar15146672011-10-20 22:22:38 +02007151 let curbufnr = bufnr("%")
7152
7153 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7154 if exists("s:netrwmarkfilelist_{curbufnr}")
7155
7156 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007157 " construct suffix pattern
7158 if fname =~ '\.'
7159 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7160 else
7161 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7162 endif
7163 " determine if its in the hiding list or not
7164 let inhidelist= 0
7165 if g:netrw_list_hide != ""
7166 let itemnum = 0
7167 let hidelist= split(g:netrw_list_hide,',')
7168 for hidepat in hidelist
7169 if sfxpat == hidepat
7170 let inhidelist= 1
7171 break
7172 endif
7173 let itemnum= itemnum + 1
7174 endfor
7175 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007176 if inhidelist
7177 " remove sfxpat from list
7178 call remove(hidelist,itemnum)
7179 let g:netrw_list_hide= join(hidelist,",")
7180 elseif g:netrw_list_hide != ""
7181 " append sfxpat to non-empty list
7182 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7183 else
7184 " set hiding list to sfxpat
7185 let g:netrw_list_hide= sfxpat
7186 endif
7187 endfor
7188
7189 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007190 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007191 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007192 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007193 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007194 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007195endfun
7196
7197" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007198" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7199" Uses the global markfilelist
7200fun! s:NetrwMarkFileGrep(islocal)
7201" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007202 let svpos = winsaveview()
7203" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007204 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007205 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007206
7207 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007208" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007209 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007210" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007211 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007212 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007213" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007214 let netrwmarkfilelist= "*"
7215 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007216
Bram Moolenaarff034192013-04-24 18:51:19 +02007217 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007218" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007219 call inputsave()
7220 let pat= input("Enter pattern: ","")
7221 call inputrestore()
7222 let patbang = ""
7223 if pat =~ '^!'
7224 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007225 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007226 endif
7227 if pat =~ '^\i'
7228 let pat = escape(pat,'/')
7229 let pat = '/'.pat.'/'
7230 else
7231 let nonisi = pat[0]
7232 endif
7233
7234 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007235" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007236 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007237 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007238 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007239 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007240" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7241 return
7242 endtry
7243 echo "(use :cn, :cp to navigate, :Rex to return)"
7244
7245 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007246" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7247 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007248
7249 if exists("nonisi")
7250 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007251" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007252 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007253 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007254 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007255 endif
7256
7257" call Dret("s:NetrwMarkFileGrep")
7258endfun
7259
7260" ---------------------------------------------------------------------
7261" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7262" uses the global marked file list
7263" s:netrwmfloc= 0: target directory is remote
7264" = 1: target directory is local
7265fun! s:NetrwMarkFileMove(islocal)
7266" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007267 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007268 let curbufnr = bufnr("%")
7269
7270 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007271 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007272 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007273" call Dret("s:NetrwMarkFileMove")
7274 return
7275 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007276" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007277
Bram Moolenaar446cb832008-06-24 21:56:24 +00007278 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007279 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007280" call Dret("s:NetrwMarkFileCopy 0")
7281 return 0
7282 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007283" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007284
7285 if a:islocal && s:netrwmftgt_islocal
7286 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007287" call Decho("move from local to local",'~'.expand("<slnum>"))
7288" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007289 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007290 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7291" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7292 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007293 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007294 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007295" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007296 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007297 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007298" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007299 if g:netrw_localmovecmd =~ '\s'
7300 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7301 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7302 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007303" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007304 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007305 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007306" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007307 endif
7308 else
7309 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007310" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007311 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007312 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007313 if g:netrw_keepdir
7314 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7315 let fname= b:netrw_curdir."/".fname
7316 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007317 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007318 let fname= substitute(fname,'/','\\','g')
7319 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007320" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007321 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007322 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007323 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007324 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 +01007325 else
7326 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7327 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007328 break
7329 endif
7330 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007331
7332 elseif a:islocal && !s:netrwmftgt_islocal
7333 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007334" call Decho("move from local to remote",'~'.expand("<slnum>"))
7335" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007336 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007337 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007338" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007339 for fname in mflist
7340 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7341 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7342 endfor
7343 unlet mflist
7344
7345 elseif !a:islocal && s:netrwmftgt_islocal
7346 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007347" call Decho("move from remote to local",'~'.expand("<slnum>"))
7348" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007349 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007350 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007351" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007352 for fname in mflist
7353 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7354 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7355 endfor
7356 unlet mflist
7357
7358 elseif !a:islocal && !s:netrwmftgt_islocal
7359 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007360" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7361" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007362 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007363 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007364" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007365 for fname in mflist
7366 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7367 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7368 endfor
7369 unlet mflist
7370 endif
7371
7372 " -------
7373 " cleanup
7374 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007375" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007376
7377 " remove markings from local buffer
7378 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7379
7380 " refresh buffers
7381 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007382" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007383 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007384 endif
7385 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007386" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007387 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007388 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007389 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007390" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007391 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007392 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007393
Bram Moolenaar446cb832008-06-24 21:56:24 +00007394" call Dret("s:NetrwMarkFileMove")
7395endfun
7396
7397" ---------------------------------------------------------------------
7398" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7399" using the hardcopy command. Local marked-file list only.
7400fun! s:NetrwMarkFilePrint(islocal)
7401" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7402 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007403
7404 " sanity check
7405 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007406 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007407" call Dret("s:NetrwMarkFilePrint")
7408 return
7409 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007410" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7411 let curdir= s:NetrwGetCurdir(a:islocal)
7412
Bram Moolenaar446cb832008-06-24 21:56:24 +00007413 if exists("s:netrwmarkfilelist_{curbufnr}")
7414 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007415 call s:NetrwUnmarkList(curbufnr,curdir)
7416 for fname in netrwmarkfilelist
7417 if a:islocal
7418 if g:netrw_keepdir
7419 let fname= s:ComposePath(curdir,fname)
7420 endif
7421 else
7422 let fname= curdir.fname
7423 endif
7424 1split
7425 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007426" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007427 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007428" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007429 hardcopy
7430 q
7431 endfor
7432 2match none
7433 endif
7434" call Dret("s:NetrwMarkFilePrint")
7435endfun
7436
7437" ---------------------------------------------------------------------
7438" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7439" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007440" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007441fun! s:NetrwMarkFileRegexp(islocal)
7442" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7443
7444 " get the regular expression
7445 call inputsave()
7446 let regexp= input("Enter regexp: ","","file")
7447 call inputrestore()
7448
7449 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007450 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007451" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007452 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007453" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007454 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007455 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007456 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007457 else
7458 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007459 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007460 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007461" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007462
7463 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007464 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007465 if fname =~ '^'.fnameescape(curdir)
7466" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7467 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7468 else
7469" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7470 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7471 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007472 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007473
7474 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007475" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007476
7477 " convert displayed listing into a filelist
7478 let eikeep = &ei
7479 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007480 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007481 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007482" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007483 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007484 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007485 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007486 sil NetrwKeepj norm! "ap
7487 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007488 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007489 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007490 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007491 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007492 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007493 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007494 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007495 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007496 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007497 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007498 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7499 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007500 call histdel("/",-1)
7501 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007502 endif
7503 " convert regexp into the more usual glob-style format
7504 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007505" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007506 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007507 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007508 let filelist= getline(1,line("$"))
7509 q!
7510 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007511 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007512 endfor
7513 unlet filelist
7514 let @a = areg
7515 let &ei = eikeep
7516 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007517 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007518
7519" call Dret("s:NetrwMarkFileRegexp")
7520endfun
7521
7522" ---------------------------------------------------------------------
7523" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7524" Uses the local marked file list.
7525fun! s:NetrwMarkFileSource(islocal)
7526" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7527 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007528
7529 " sanity check
7530 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007531 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007532" call Dret("s:NetrwMarkFileSource")
7533 return
7534 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007535" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7536 let curdir= s:NetrwGetCurdir(a:islocal)
7537
Bram Moolenaar446cb832008-06-24 21:56:24 +00007538 if exists("s:netrwmarkfilelist_{curbufnr}")
7539 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007540 call s:NetrwUnmarkList(curbufnr,curdir)
7541 for fname in netrwmarkfilelist
7542 if a:islocal
7543 if g:netrw_keepdir
7544 let fname= s:ComposePath(curdir,fname)
7545 endif
7546 else
7547 let fname= curdir.fname
7548 endif
7549 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007550" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007551 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007552 endfor
7553 2match none
7554 endif
7555" call Dret("s:NetrwMarkFileSource")
7556endfun
7557
7558" ---------------------------------------------------------------------
7559" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7560" Uses the global markfilelist
7561fun! s:NetrwMarkFileTag(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007562 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007563 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007564 let curbufnr = bufnr("%")
7565
Bram Moolenaarff034192013-04-24 18:51:19 +02007566 " sanity check
7567 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007568 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007569 return
7570 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007571
Bram Moolenaar446cb832008-06-24 21:56:24 +00007572 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007573 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007574 call s:NetrwUnmarkAll()
7575
7576 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02007577
Bram Moolenaar85850f32019-07-19 22:05:51 +02007578 call system(g:netrw_ctags." ".netrwmarkfilelist)
7579 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007580 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7581 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007582
Bram Moolenaar446cb832008-06-24 21:56:24 +00007583 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007584 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007585 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007586 let curdir= b:netrw_curdir
7587 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007588 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007589 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007590 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007591 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007592 wq!
7593 endif
7594 2match none
Tom Benham64a536d2024-11-07 21:15:03 +01007595 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007596 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007597 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007598endfun
7599
7600" ---------------------------------------------------------------------
7601" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007602" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02007603" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00007604" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02007605" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00007606fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007607 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007608 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007609 let hadtgt = exists("s:netrwmftgt")
7610 if !exists("w:netrw_bannercnt")
7611 let w:netrw_bannercnt= b:netrw_bannercnt
7612 endif
7613
7614 " set up target
7615 if line(".") < w:netrw_bannercnt
Bram Moolenaarff034192013-04-24 18:51:19 +02007616 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
7617 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007618 unlet s:netrwmftgt s:netrwmftgt_islocal
7619 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007620 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02007621 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007622 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007623 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007624 return
7625 else
7626 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007627 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007628
7629 else
7630 " get word under cursor.
7631 " * If directory, use it for the target.
7632 " * If file, use b:netrw_curdir for the target
7633 let curword= s:NetrwGetWord()
7634 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007635 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007636 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007637 elseif !a:islocal && tgtdir =~ '/$'
7638 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007639 else
7640 let s:netrwmftgt = curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007641 endif
7642 endif
7643 if a:islocal
7644 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
7645 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007646 endif
7647 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007648 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007649 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
7650 endif
7651 let s:netrwmftgt_islocal= a:islocal
7652
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007653 " need to do refresh so that the banner will be updated
7654 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01007655 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007656 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007657 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007658" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007659 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Tom Benham64a536d2024-11-07 21:15:03 +01007660 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop,0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007661 else
Tom Benham64a536d2024-11-07 21:15:03 +01007662 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007663 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007664 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007665 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007666 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00007667 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007668endfun
7669
7670" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007671" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
7672fun! s:NetrwGetCurdir(islocal)
7673" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
7674
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007675 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007676 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
7677" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
7678 elseif !exists("b:netrw_curdir")
7679 let b:netrw_curdir= getcwd()
7680" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
7681 endif
7682
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007683" 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 +01007684 if b:netrw_curdir !~ '\<\a\{3,}://'
7685 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007686" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007687 if g:netrw_keepdir == 0
7688 call s:NetrwLcd(curdir)
7689 endif
7690 endif
7691
7692" call Dret("s:NetrwGetCurdir <".curdir.">")
7693 return b:netrw_curdir
7694endfun
7695
7696" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007697" s:NetrwOpenFile: query user for a filename and open it {{{2
7698fun! s:NetrwOpenFile(islocal)
7699" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007700 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00007701 call inputsave()
7702 let fname= input("Enter filename: ")
7703 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02007704" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
7705
7706 " determine if Lexplore is in use
7707 if exists("t:netrw_lexbufnr")
7708 " check if t:netrw_lexbufnr refers to a netrw window
7709" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
7710 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
7711 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
7712" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
7713 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
7714 exe "NetrwKeepj e ".fnameescape(fname)
7715 let @@= ykeep
7716" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
7717 endif
7718 endif
7719
7720 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00007721 if fname !~ '[/\\]'
7722 if exists("b:netrw_curdir")
7723 if exists("g:netrw_quiet")
7724 let netrw_quiet_keep = g:netrw_quiet
7725 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007726 let g:netrw_quiet = 1
7727 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007728 let s:rexposn_{bufnr("%")}= winsaveview()
7729" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007730 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007731 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007732 else
7733 exe "e ".fnameescape(b:netrw_curdir."/".fname)
7734 endif
7735 if exists("netrw_quiet_keep")
7736 let g:netrw_quiet= netrw_quiet_keep
7737 else
7738 unlet g:netrw_quiet
7739 endif
7740 endif
7741 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007742 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007743 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007744 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00007745" call Dret("s:NetrwOpenFile")
7746endfun
7747
7748" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007749" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
7750" For the mapping to this function be made via
7751" netrwPlugin, you'll need to have had
7752" g:netrw_usetab set to non-zero.
7753fun! netrw#Shrink()
7754" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
7755 let curwin = winnr()
7756 let wiwkeep = &wiw
7757 set wiw=1
7758
7759 if &ft == "netrw"
7760 if winwidth(0) > g:netrw_wiw
7761 let t:netrw_winwidth= winwidth(0)
7762 exe "vert resize ".g:netrw_wiw
7763 wincmd l
7764 if winnr() == curwin
7765 wincmd h
7766 endif
7767" call Decho("vert resize 0",'~'.expand("<slnum>"))
7768 else
7769 exe "vert resize ".t:netrw_winwidth
7770" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
7771 endif
7772
7773 elseif exists("t:netrw_lexbufnr")
7774 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
7775 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
7776 let t:netrw_winwidth= winwidth(0)
7777 exe "vert resize ".g:netrw_wiw
7778 wincmd l
7779 if winnr() == curwin
7780 wincmd h
7781 endif
7782" call Decho("vert resize 0",'~'.expand("<slnum>"))
7783 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
7784 exe "vert resize ".t:netrw_winwidth
7785" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01007786 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007787 call netrw#Lexplore(0,0)
7788 endif
7789
7790 else
7791 call netrw#Lexplore(0,0)
7792 endif
7793 let wiw= wiwkeep
7794
7795" call Dret("netrw#Shrink")
7796endfun
7797
7798" ---------------------------------------------------------------------
7799" s:NetSortSequence: allows user to edit the sorting sequence {{{2
7800fun! s:NetSortSequence(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007801 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007802 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007803 call inputsave()
7804 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
7805 call inputrestore()
7806
7807 " refresh the listing
7808 let g:netrw_sort_sequence= newsortseq
Tom Benham64a536d2024-11-07 21:15:03 +01007809 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007810 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007811 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007812endfun
7813
7814" ---------------------------------------------------------------------
7815" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
7816" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02007817" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007818fun! s:NetrwUnmarkList(curbufnr,curdir)
7819" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
7820
7821 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007822 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007823 for mfile in s:netrwmarkfilelist_{a:curbufnr}
7824 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
7825 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
7826 call remove(s:netrwmarkfilelist,idx) " remove from global list
7827 endfor
7828 if s:netrwmarkfilelist == []
7829 unlet s:netrwmarkfilelist
7830 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007831
Bram Moolenaar446cb832008-06-24 21:56:24 +00007832 " getting rid of the local marked-file lists is easy
7833 unlet s:netrwmarkfilelist_{a:curbufnr}
7834 endif
7835 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
7836 unlet s:netrwmarkfilemtch_{a:curbufnr}
7837 endif
7838 2match none
7839" call Dret("s:NetrwUnmarkList")
7840endfun
7841
7842" ---------------------------------------------------------------------
7843" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
7844fun! s:NetrwUnmarkAll()
7845" call Dfunc("s:NetrwUnmarkAll()")
7846 if exists("s:netrwmarkfilelist")
7847 unlet s:netrwmarkfilelist
7848 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02007849 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007850 2match none
7851" call Dret("s:NetrwUnmarkAll")
7852endfun
7853
7854" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02007855" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007856fun! s:NetrwUnmarkAll2()
7857" call Dfunc("s:NetrwUnmarkAll2()")
7858 redir => netrwmarkfilelist_let
7859 let
7860 redir END
7861 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007862 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00007863 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
7864 for flist in netrwmarkfilelist_list
7865 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
7866 unlet s:netrwmarkfilelist_{curbufnr}
7867 unlet s:netrwmarkfilemtch_{curbufnr}
7868 endfor
7869" call Dret("s:NetrwUnmarkAll2")
7870endfun
7871
7872" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007873" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
7874"
7875" Marked files are in two types of lists:
7876" s:netrwmarkfilelist -- holds complete paths to all marked files
7877" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
7878"
7879" Marked files suitable for use with 2match are in:
7880" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00007881fun! s:NetrwUnMarkFile(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007882 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007883 let curbufnr = bufnr("%")
7884
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007885 " unmark marked file list
7886 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
7887 if exists("s:netrwmarkfilelist")
7888" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007889 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007890 endif
7891
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007892 let ibuf= 1
7893 while ibuf < bufnr("$")
7894 if exists("s:netrwmarkfilelist_".ibuf)
7895 unlet s:netrwmarkfilelist_{ibuf}
7896 unlet s:netrwmarkfilemtch_{ibuf}
7897 endif
7898 let ibuf = ibuf + 1
7899 endwhile
7900 2match none
7901
Tom Benham64a536d2024-11-07 21:15:03 +01007902" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007903call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007904endfun
7905
7906" ---------------------------------------------------------------------
7907" s:NetrwMenu: generates the menu for gvim and netrw {{{2
7908fun! s:NetrwMenu(domenu)
7909
7910 if !exists("g:NetrwMenuPriority")
7911 let g:NetrwMenuPriority= 80
7912 endif
7913
Bram Moolenaaradc21822011-04-01 18:03:16 +02007914 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00007915" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
7916
7917 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007918" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007919 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02007920 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
7921 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
7922 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
7923 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
7924 if g:netrw_dirhistmax > 0
7925 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
7926 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
7927 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
7928 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
7929 else
7930 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
7931 endif
7932 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
7933 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
7934 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
7935 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
7936 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
7937 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
7938 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
7939 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
7940 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
7941 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
7942 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
7943 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
7944 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
7945 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
7946 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 +01007947 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 +02007948 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
7949 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
7950 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
7951 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
7952 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
7953 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
7954 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
7955 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
7956 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
7957 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
7958 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
7959 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
7960 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
7961 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
7962 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
7963 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
7964 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
7965 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
7966 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
7967 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
7968 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
7969 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
7970 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
7971 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
7972 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
7973 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
7974 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
7975 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
7976 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
7977 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>'
7978 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>'
7979 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>'
7980 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
7981 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>'
7982 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>'
7983 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 +01007984 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 +02007985 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
7986 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007987 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02007988 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
7989 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00007990
7991 elseif !a:domenu
7992 let s:netrwcnt = 0
7993 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007994 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007995 exe curwin."wincmd w"
7996
7997 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007998" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007999 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008000" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008001 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008002 endif
8003 endif
8004" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008005 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006 endif
8007
8008endfun
8009
8010" ---------------------------------------------------------------------
8011" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8012" Used by the O maps (as <SID>NetrwObtain())
8013fun! s:NetrwObtain(islocal)
8014" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8015
Bram Moolenaar97d62492012-11-15 21:28:22 +01008016 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008017 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008018 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008019 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008020 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8021 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008022 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008023 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008024 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008025
8026" call Dret("NetrwObtain")
8027endfun
8028
8029" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008030" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8031" If there's only one window, then the window will first be split.
8032" Returns:
8033" choice = 0 : didn't have to choose
8034" choice = 1 : saved modified file in window first
8035" choice = 2 : didn't save modified file, opened window
8036" choice = 3 : cancel open
8037fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008038 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008039 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008040 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008041
8042 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008043 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008044 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008045 let curword = s:NetrwGetWord()
8046 let choice = 0
8047 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008048 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008049 let curdir = s:treedir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008050
Bram Moolenaar8d043172014-01-23 14:24:41 +01008051 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008052 if lastwinnr == 1
8053 " if only one window, open a new one first
Bram Moolenaar85850f32019-07-19 22:05:51 +02008054 " g:netrw_preview=0: preview window shown in a horizontally split window
8055 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008056 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008057 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008058 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008059 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008060 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008061 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008062 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008063 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008064 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008065 let didsplit = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008066
8067 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008068 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008069 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008070 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008071 wincmd p
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008072
Bram Moolenaar71badf92023-04-22 22:40:14 +01008073 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8074 " whoops -- user trying to open file in the Lexplore window.
8075 " Use Lexplore's opening-file window instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01008076" exe g:netrw_chgwin."wincmd w"
8077 wincmd p
Tom Benham64a536d2024-11-07 21:15:03 +01008078 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008079 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008080
8081 " prevwinnr: the window number of the "prev" window
8082 " prevbufnr: the buffer number of the buffer in the "prev" window
8083 " bnrcnt : the qty of windows open on the "prev" buffer
8084 let prevwinnr = winnr()
8085 let prevbufnr = bufnr("%")
8086 let prevbufname = bufname("%")
8087 let prevmod = &mod
8088 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008089 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008090
8091 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008092 " and it doesn't appear in any other extant window, then ask the
8093 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008094 if prevmod
Bram Moolenaar8d043172014-01-23 14:24:41 +01008095 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008096 exe prevwinnr."wincmd w"
8097
8098 if bnrcnt == 1 && &hidden == 0
8099 " only one copy of the modified buffer in a window, and
8100 " hidden not set, so overwriting will lose the modified file. Ask first...
8101 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008102 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008103
8104 if choice == 1
8105 " Yes -- write file & then browse
8106 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008107 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008108 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008109 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008110 exe origwin."wincmd w"
8111 let &ei = eikeep
8112 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008113 return choice
8114 endif
8115
8116 elseif choice == 2
8117 " No -- don't worry about changed file, just browse anyway
Bram Moolenaar8d043172014-01-23 14:24:41 +01008118 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119
8120 else
8121 " Cancel -- don't do this
Bram Moolenaar8d043172014-01-23 14:24:41 +01008122 exe origwin."wincmd w"
8123 let &ei= eikeep
8124 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008125 return choice
8126 endif
8127 endif
8128 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008129 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008130 endif
8131
8132 " restore b:netrw_curdir (window split/enew may have lost it)
8133 let b:netrw_curdir= curdir
8134 if a:islocal < 2
8135 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01008136 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008137 else
Tom Benham64a536d2024-11-07 21:15:03 +01008138 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008139 endif
8140 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008141 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008142 return choice
8143endfun
8144
8145" ---------------------------------------------------------------------
8146" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8147" Always assumed to be local -> remote
8148" call s:NetrwUpload(filename, target)
8149" call s:NetrwUpload(filename, target, fromdirectory)
8150fun! s:NetrwUpload(fname,tgt,...)
8151" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8152
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008153 if a:tgt =~ '^\a\{3,}://'
8154 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008155 else
8156 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8157 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008158" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008159
8160 if a:0 > 0
8161 let fromdir= a:1
8162 else
8163 let fromdir= getcwd()
8164 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008165" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008166
8167 if type(a:fname) == 1
8168 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008169" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008170 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008171" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8172 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8173" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008174 if a:tgt =~ '/$'
8175 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008176" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008177 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008178 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008179" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008180 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008181" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008182 endif
8183 q!
8184
8185 elseif type(a:fname) == 3
8186 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008187" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008188 let curdir= getcwd()
8189 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008190 if s:NetrwLcd(fromdir)
8191" call Dret("s:NetrwUpload : lcd failure")
8192 return
8193 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008194 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008195 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008196 if exists("g:netrw_port") && g:netrw_port != ""
8197 let useport= " ".g:netrw_scpport." ".g:netrw_port
8198 else
8199 let useport= ""
8200 endif
8201 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8202 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008203 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 +02008204 if s:NetrwLcd(curdir)
8205" call Dret("s:NetrwUpload : lcd failure")
8206 return
8207 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008208
8209 elseif a:tgt =~ '^ftp:'
8210 call s:NetrwMethod(a:tgt)
8211
8212 if b:netrw_method == 2
8213 " handle uploading a list of files via ftp+.netrc
8214 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008215 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008216" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008217
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008218 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008219" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008220
8221 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008222 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008223" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008224 endif
8225
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008226 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008227" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008228
Bram Moolenaaradc21822011-04-01 18:03:16 +02008229 if tgtdir == ""
8230 let tgtdir= '/'
8231 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008232 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008233" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008234
8235 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008236 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8237" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008238 endfor
8239
8240 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008241 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 +00008242 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008243" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8244 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008245 endif
8246 " 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 +01008247 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008248 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008249 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8250 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8251 else
8252 bw!|q
8253 endif
8254
8255 elseif b:netrw_method == 3
8256 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8257 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008258 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008259 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008260 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008261
8262 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008263 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008264" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008265 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008266 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008267" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008268 endif
8269
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008270 if exists("g:netrw_uid") && g:netrw_uid != ""
8271 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008272 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008273" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008274 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008275 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008276 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008277" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008278 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008279 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008280" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008281 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008282 endif
8283
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008284 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008285" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008286
8287 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008288 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008289" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008290 endif
8291
8292 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008293 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008294" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008295 endif
8296
8297 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008298 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008299" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008300 endfor
8301
8302 " perform ftp:
8303 " -i : turns off interactive prompting from ftp
8304 " -n unix : DON'T use <.netrc>, even though it exists
8305 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008306 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008307 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008308 " 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 +01008309 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008310 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008311 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8312 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008313 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008314 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8315 let &debug = debugkeep
8316 let mod = 1
8317 else
8318 bw!|q
8319 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008320 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008321" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008322 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008323 endif
8324 else
8325 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8326 endif
8327 endif
8328
8329" call Dret("s:NetrwUpload")
8330endfun
8331
8332" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008333" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008334fun! s:NetrwPreview(path) range
8335" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008336" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8337" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008338 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008339 NetrwKeepj call s:NetrwOptionsSave("s:")
8340 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8341 NetrwKeepj call s:NetrwOptionsSafe(1)
8342 else
8343 NetrwKeepj call s:NetrwOptionsSafe(0)
8344 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008345 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008346" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008347 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008348" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8349 if g:netrw_preview
8350 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008351 let pvhkeep = &pvh
8352 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8353 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008354" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8355 else
8356 " horizontal split
8357 let pvhkeep = &pvh
8358 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8359 let &pvh = winheight(0) - winsz
8360" 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 +02008361 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008362 " g:netrw_preview g:netrw_alto
8363 " 1 : vert 1: top -- preview window is vertically split off and on the left
8364 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8365 " 0 : 1: top -- preview window is horizontally split off and on the top
8366 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8367 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008368 " 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 +02008369 " the BufEnter event set up in netrwPlugin.vim
8370" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8371 let eikeep = &ei
8372 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008373 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008374 let &ei= eikeep
8375" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008376 if exists("pvhkeep")
8377 let &pvh= pvhkeep
8378 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008379 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008380 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008381 endif
8382 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008383 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 +00008384 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008385 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008386 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008387" call Dret("NetrwPreview")
8388endfun
8389
8390" ---------------------------------------------------------------------
8391" s:NetrwRefresh: {{{2
8392fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008393" 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 +00008394 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008395 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008396" call Decho("setl ma noro",'~'.expand("<slnum>"))
8397" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008398 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008399 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8400 if !exists("w:netrw_treetop")
8401 if exists("b:netrw_curdir")
8402 let w:netrw_treetop= b:netrw_curdir
8403 else
8404 let w:netrw_treetop= getcwd()
8405 endif
8406 endif
8407 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8408 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008409
8410 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008411 let screenposn = winsaveview()
8412" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008413
8414" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8415" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8416 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008417 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008418 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008419 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008420 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008421 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008422
8423 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008424" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8425 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008426
8427 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008428 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8429 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8430" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8431 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8432 else
8433" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8434 2match none
8435 endif
8436 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008437
Bram Moolenaar97d62492012-11-15 21:28:22 +01008438" restore
8439 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008440" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008441endfun
8442
8443" ---------------------------------------------------------------------
8444" s:NetrwRefreshDir: refreshes a directory by name {{{2
8445" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008446" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008447fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008448 if g:netrw_fastbrowse == 0
8449 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008450 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008451
8452 if tgtwin > 0
8453 " tgtwin is being displayed, so refresh it
8454 let curwin= winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008455 exe tgtwin."wincmd w"
Tom Benham64a536d2024-11-07 21:15:03 +01008456 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008457 exe curwin."wincmd w"
8458
8459 elseif bufnr(a:dirname) > 0
8460 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008461 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008462 endif
8463
8464 elseif g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008465 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008466 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008467endfun
8468
8469" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008470" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8471" window number to do its editing in.
8472" Supports [count]C where the count, if present, is used to specify
8473" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008474fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008475" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008476 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008477" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008478 if a:1 == "" " :NetrwC win#
8479 let g:netrw_chgwin= winnr()
8480 else " :NetrwC
8481 let g:netrw_chgwin= a:1
8482 endif
8483 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008484 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008485 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008486 let g:netrw_chgwin= winnr()
8487 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008488 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008489" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008490endfun
8491
8492" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008493" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8494" What this function does is to compute a priority for the patterns
8495" in the g:netrw_sort_sequence. It applies a substitute to any
8496" "files" that satisfy each pattern, putting the priority / in
8497" front. An "*" pattern handles the default priority.
8498fun! s:NetrwSetSort()
8499" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008500 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008501 if w:netrw_liststyle == s:LONGLIST
8502 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8503 else
8504 let seqlist = g:netrw_sort_sequence
8505 endif
8506 " sanity check -- insure that * appears somewhere
8507 if seqlist == ""
8508 let seqlist= '*'
8509 elseif seqlist !~ '\*'
8510 let seqlist= seqlist.',*'
8511 endif
8512 let priority = 1
8513 while seqlist != ""
8514 if seqlist =~ ','
8515 let seq = substitute(seqlist,',.*$','','e')
8516 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8517 else
8518 let seq = seqlist
8519 let seqlist = ""
8520 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008521 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008522 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008523 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008524 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008525 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008526 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008527 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008528" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008529
8530 " sanity check
8531 if w:netrw_bannercnt > line("$")
8532 " apparently no files were left after a Hiding pattern was used
8533" call Dret("SetSort : no files left after hiding")
8534 return
8535 endif
8536 if seq == '*'
8537 let starpriority= spriority
8538 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008539 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008540 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008541 " sometimes multiple sorting patterns will match the same file or directory.
8542 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008543 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8544 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008545 endif
8546 let priority = priority + 1
8547 endwhile
8548 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008549 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8550 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008551 endif
8552
8553 " Following line associated with priority -- items that satisfy a priority
8554 " pattern get prefixed by ###/ which permits easy sorting by priority.
8555 " Sometimes files can satisfy multiple priority patterns -- only the latest
8556 " priority pattern needs to be retained. So, at this point, these excess
8557 " priority prefixes need to be removed, but not directories that happen to
8558 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008559 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
8560 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008561 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008562
8563" call Dret("SetSort")
8564endfun
8565
Bram Moolenaarff034192013-04-24 18:51:19 +02008566" ---------------------------------------------------------------------
8567" s:NetrwSetTgt: sets the target to the specified choice index {{{2
8568" Implements [count]Tb (bookhist<b>)
8569" [count]Th (bookhist<h>)
8570" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008571fun! s:NetrwSetTgt(islocal,bookhist,choice)
8572" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02008573
8574 if a:bookhist == 'b'
8575 " supports choosing a bookmark as a target using a qb-generated list
8576 let choice= a:choice - 1
8577 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008578 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02008579 else
8580 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
8581 endif
8582
8583 elseif a:bookhist == 'h'
8584 " supports choosing a history stack entry as a target using a qb-generated list
8585 let choice= (a:choice % g:netrw_dirhistmax) + 1
8586 if exists("g:netrw_dirhist_".choice)
8587 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01008588 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02008589 else
8590 echomsg "Sorry, history#".a:choice." not available!"
8591 endif
8592 endif
8593
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008594 " refresh the display
8595 if !exists("b:netrw_curdir")
8596 let b:netrw_curdir= getcwd()
8597 endif
8598 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
8599
Bram Moolenaarff034192013-04-24 18:51:19 +02008600" call Dret("s:NetrwSetTgt")
8601endfun
8602
Bram Moolenaar446cb832008-06-24 21:56:24 +00008603" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02008604" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008605fun! s:NetrwSortStyle(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008606 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008607 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008608
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008609 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 +01008610 NetrwKeepj norm! 0
Tom Benham64a536d2024-11-07 21:15:03 +01008611 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008612 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008613endfun
8614
8615" ---------------------------------------------------------------------
8616" s:NetrwSplit: mode {{{2
8617" =0 : net and o
8618" =1 : net and t
8619" =2 : net and v
8620" =3 : local and o
8621" =4 : local and t
8622" =5 : local and v
8623fun! s:NetrwSplit(mode)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008624
Bram Moolenaar97d62492012-11-15 21:28:22 +01008625 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008626 call s:SaveWinVars()
8627
8628 if a:mode == 0
8629 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008630 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008631 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008632 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008633 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008634 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008635 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008636 unlet s:didsplit
8637
8638 elseif a:mode == 1
8639 " remote and t
Tom Benham64a536d2024-11-07 21:15:03 +01008640 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008641 tabnew
8642 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008643 NetrwKeepj call s:RestoreWinVars()
8644 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645 unlet s:didsplit
8646
8647 elseif a:mode == 2
8648 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008649 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008650 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008651 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008652 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008653 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008654 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008655 unlet s:didsplit
8656
8657 elseif a:mode == 3
8658 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008659 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008660 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008661 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008662 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008663 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008664 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008665 unlet s:didsplit
8666
8667 elseif a:mode == 4
8668 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00008669 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008670 let eikeep = &ei
8671 let netrw_winnr = winnr()
8672 let netrw_line = line(".")
8673 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008674 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008675 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01008676 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008677 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8678 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008679 let &ei = eikeep
8680 let netrw_curdir = s:NetrwTreeDir(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008681 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01008682 let b:netrw_curdir = netrw_curdir
8683 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008684 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008685 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword,0))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008686 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01008687 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008688 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8689 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01008690 let &ei= eikeep
8691 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008692 unlet s:didsplit
8693
8694 elseif a:mode == 5
8695 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008696 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008697 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008698 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008699 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008700 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008701 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008702 unlet s:didsplit
8703
8704 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008705 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008706 endif
8707
Bram Moolenaar97d62492012-11-15 21:28:22 +01008708 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008709endfun
8710
8711" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008712" s:NetrwTgtMenu: {{{2
8713fun! s:NetrwTgtMenu()
8714 if !exists("s:netrw_menucnt")
8715 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008716 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008717" call Dfunc("s:NetrwTgtMenu()")
8718
8719 " the following test assures that gvim is running, has menus available, and has menus enabled.
8720 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
8721 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008722" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008723 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
8724 endif
8725 if !exists("s:netrw_initbookhist")
8726 call s:NetrwBookHistRead()
8727 endif
8728
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008729 " try to cull duplicate entries
8730 let tgtdict={}
8731
Bram Moolenaarff034192013-04-24 18:51:19 +02008732 " target bookmarked places
8733 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008734" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008735 let cnt= 1
8736 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008737 if has_key(tgtdict,bmd)
8738 let cnt= cnt + 1
8739 continue
8740 endif
8741 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008742 let ebmd= escape(bmd,g:netrw_menu_escape)
8743 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008744" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008745 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 +02008746 let cnt= cnt + 1
8747 endfor
8748 endif
8749
8750 " target directory browsing history
8751 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008752" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008753 let histcnt = 1
8754 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02008755 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008756 if exists("g:netrw_dirhist_{histcnt}")
8757 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008758 if has_key(tgtdict,histentry)
8759 let histcnt = histcnt + 1
8760 continue
8761 endif
8762 let tgtdict[histentry] = histcnt
8763 let ehistentry = escape(histentry,g:netrw_menu_escape)
8764" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008765 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 +02008766 endif
8767 let histcnt = histcnt + 1
8768 endwhile
8769 endif
8770 endif
8771" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008772endfun
8773
8774" ---------------------------------------------------------------------
8775" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
8776" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008777fun! s:NetrwTreeDir(islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008779 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008780 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
8781 let treedir= s:treedir
8782 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008783 unlet s:prevwinopen
Bram Moolenaar8d043172014-01-23 14:24:41 +01008784 return treedir
8785 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008786 if exists("s:prevwinopen")
8787 unlet s:prevwinopen
8788 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008789
Bram Moolenaar8d043172014-01-23 14:24:41 +01008790 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
8791 let b:netrw_curdir= getcwd()
8792 endif
8793 let treedir = b:netrw_curdir
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008794 let s:treecurpos= winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008795
8796 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar5c736222010-01-06 20:54:52 +01008797
8798 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008799 let curline= substitute(getline('.'),"\t -->.*$",'','')
8800 if curline =~ '/$'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008801 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008802 elseif curline =~ '@$'
Tom Benham64a536d2024-11-07 21:15:03 +01008803 let potentialdir= resolve(s:NetrwTreePath(w:netrw_treetop))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008804 else
8805 let treedir= ""
8806 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008807
8808 " detect user attempting to close treeroot
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008809 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008810 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008811 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008812 return b:netrw_curdir
8813 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008814
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008815 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
8816" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
8817" let newdir = w:netrw_treetop.'/'.potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008818 if a:islocal && curline =~ '@$'
8819 if isdirectory(s:NetrwFile(potentialdir))
Tom Benham64a536d2024-11-07 21:15:03 +01008820 let treedir = potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008821 let w:netrw_treetop = treedir
8822 endif
8823 else
8824 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
8825 let treedir = s:NetrwTreePath(w:netrw_treetop)
8826 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008827 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008828
8829 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00008830 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008831 return treedir
8832endfun
8833
8834" ---------------------------------------------------------------------
8835" s:NetrwTreeDisplay: recursive tree display {{{2
8836fun! s:NetrwTreeDisplay(dir,depth)
Tom Benham64a536d2024-11-07 21:15:03 +01008837 " ensure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02008838 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00008839
8840 " install ../ and shortdir
8841 if a:depth == ""
8842 call setline(line("$")+1,'../')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008843 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008844 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008845 if a:dir == w:netrw_treetop
8846 let shortdir= a:dir
8847 else
8848 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
8849 endif
8850 call setline(line("$")+1,a:depth.shortdir)
8851 else
8852 let shortdir= substitute(a:dir,'^.*/','','e')
8853 call setline(line("$")+1,a:depth.shortdir.'/')
8854 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008855 " append a / to dir if its missing one
8856 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008857
8858 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008859 let depth= s:treedepthstring.a:depth
Bram Moolenaar446cb832008-06-24 21:56:24 +00008860
Bram Moolenaar85850f32019-07-19 22:05:51 +02008861 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
8862 if g:netrw_hide == 1
8863 " hide given patterns
8864 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008865 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02008866 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008867 endfor
8868
8869 elseif g:netrw_hide == 2
8870 " show given patterns (only)
8871 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008872 let entries=[]
8873 for entry in w:netrw_treedict[dir]
8874 for pat in listhide
8875 if entry =~ pat
8876 call add(entries,entry)
8877 break
8878 endif
8879 endfor
8880 endfor
8881 let w:netrw_treedict[dir]= entries
8882 endif
8883 if depth != ""
8884 " always remove "." and ".." entries when there's depth
8885 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008886 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008887 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008888 call filter(w:netrw_treedict[dir],'v:val !~ "\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008889 endif
8890
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008891 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008892 if dir =~ '/$'
8893 let direntry= substitute(dir.entry,'[@/]$','','e')
8894 else
8895 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
8896 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008897 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008898 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008899 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008900 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
8901 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Tom Benham64a536d2024-11-07 21:15:03 +01008902 NetrwKeepj call s:NetrwTreeDisplay(direntry.'@',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008903 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008904 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008905 endif
8906 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008907endfun
8908
8909" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008910" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
8911fun! s:NetrwRefreshTreeDict(dir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008912 if !exists("w:netrw_treedict")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008913 return
8914 endif
8915
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008916 for entry in w:netrw_treedict[a:dir]
8917 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008918
8919 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008920 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Tom Benham64a536d2024-11-07 21:15:03 +01008921 let filelist = s:NetrwLocalListingList(direntry,0)
8922 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008923
8924 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008925 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Tom Benham64a536d2024-11-07 21:15:03 +01008926 let filelist = s:NetrwLocalListingList(direntry.'/',0)
8927 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008928
8929 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008930 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008931 let liststar = s:NetrwGlob(direntry.'/','*',1)
8932 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008933
8934 else
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008935 endif
8936 endfor
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008937endfun
8938
8939" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008940" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008941" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008942fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008943 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00008944
8945 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008946 if !exists("w:netrw_treetop")
8947 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008948 let s:netrw_treetop= w:netrw_treetop
Tom Benham4d618002024-10-31 10:47:23 +01008949 " use \V in case the directory contains specials chars like '$' or '~'
8950 elseif (w:netrw_treetop =~ ('^'.'\V'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop))
8951 \ || a:dirname !~ ('^'.'\V'.w:netrw_treetop)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008952 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008953 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008954 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008955 if exists("w:netrw_treetop")
8956 let s:netrw_treetop= w:netrw_treetop
8957 else
8958 let w:netrw_treetop= getcwd()
8959 let s:netrw_treetop= w:netrw_treetop
8960 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008961
Bram Moolenaar446cb832008-06-24 21:56:24 +00008962 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008963 " insure that we have a treedict, albeit empty
Bram Moolenaar446cb832008-06-24 21:56:24 +00008964 let w:netrw_treedict= {}
8965 endif
8966
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008967 " update the dictionary for the current directory
Christian Brabandta063b222024-11-07 14:30:30 +01008968 exe "sil! NetrwKeepj keepp ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008969 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008970 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008971
8972 " if past banner, record word
8973 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
8974 let fname= expand("<cword>")
8975 else
8976 let fname= ""
8977 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008978
8979 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008980 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008981
8982 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
8983 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008984 1d
8985 endwhile
8986
Bram Moolenaar13600302014-05-22 18:26:40 +02008987 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00008988
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008989 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008990 endif
8991endfun
8992
8993" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008994" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01008995" Normally, treetop is w:netrw_treetop, but a
8996" user of the function ( netrw#SetTreetop() )
8997" wipes that out prior to calling this function
8998fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008999" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9000 if line(".") < w:netrw_bannercnt + 2
9001 let treedir= a:treetop
9002 if treedir !~ '/$'
9003 let treedir= treedir.'/'
9004 endif
9005" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9006 return treedir
9007 endif
9008
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009009 let svpos = winsaveview()
9010" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009011 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009012" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009013 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009014" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9015 let curline= getline('.')
9016" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9017 if curline =~ '/$'
9018" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9019 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9020" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9021 elseif curline =~ '@\s\+-->'
9022" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9023 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9024 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9025" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009026 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009027" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009028 let treedir= ""
9029 endif
9030 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009031" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9032" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009033 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9034 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9035 let treedir= dirname.treedir
9036 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009037" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009038 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009039" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009040 if a:treetop =~ '/$'
9041 let treedir= a:treetop.treedir
9042 else
9043 let treedir= a:treetop.'/'.treedir
9044 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009045" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009046 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009047" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009048" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9049 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009050" call Dret("s:NetrwTreePath <".treedir.">")
9051 return treedir
9052endfun
9053
9054" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009055" s:NetrwWideListing: {{{2
9056fun! s:NetrwWideListing()
9057
9058 if w:netrw_liststyle == s:WIDELIST
9059" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9060 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009061 " cpf: characters per filename
9062 " fpl: filenames per line
9063 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009064 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009065 let dict={}
9066 " save the unnamed register and register 0-9 and a
9067 let dict.a=[getreg('a'), getregtype('a')]
9068 for i in range(0, 9)
9069 let dict[i] = [getreg(i), getregtype(i)]
9070 endfor
9071 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009072" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009073 let b:netrw_cpf= 0
9074 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009075 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009076 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9077 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009078 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009079 " restore stored registers
9080 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009081" call Dret("NetrwWideListing")
9082 return
9083 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009084 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009085 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009086" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009087
9088 " determine qty files per line (fpl)
9089 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9090 if w:netrw_fpl <= 0
9091 let w:netrw_fpl= 1
9092 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009093" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009094
9095 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009096 " fpc: files per column of wide listing
9097 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009098 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009099 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9100 let newcolstart = w:netrw_bannercnt + fpc
9101 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009102" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009103 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009104" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009105 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009106 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009107 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009108 while line("$") >= newcolstart
9109 if newcolend > line("$") | let newcolend= line("$") | endif
9110 let newcolqty= newcolend - newcolstart
9111 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009112 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009113 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009114 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009115 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009116 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009117 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009118 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009119 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009120 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009121 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009122" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009123 if @* != keepregstar | sil! let @* = keepregstar | endif
9124 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009125 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009126 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9127 NetrwKeepj call histdel("/",-1)
9128 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9129 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009130" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009131 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009132 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009133" 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 +00009134" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009135 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009136 else
9137 if hasmapto("w","n")
9138 sil! nunmap <buffer> w
9139 endif
9140 if hasmapto("b","n")
9141 sil! nunmap <buffer> b
9142 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009143 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009144endfun
9145
9146" ---------------------------------------------------------------------
9147" s:PerformListing: {{{2
9148fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009149" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9150" 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 +02009151" 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>"))
9152 sil! NetrwKeepj %d _
9153" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009154
Bram Moolenaar15146672011-10-20 22:22:38 +02009155 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009156" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009157 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009158
Bram Moolenaar85850f32019-07-19 22:05:51 +02009159 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009160 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009161" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009162
9163" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009164" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165" endif " Decho
9166
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009167" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009168 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9169 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009170" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9171 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009172 endif
9173
9174 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009175 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009176
9177 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009178 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009179" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009180 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009181 if exists("g:netrw_pchk")
9182 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9183 " failure detections.
9184 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009185 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009186 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9187 endif
9188 if exists("g:netrw_pchk")
9189 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9190 else
9191 let curdir= b:netrw_curdir
9192 endif
9193 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9194 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9195 else
9196 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009197 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009198 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009199 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009200 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009201" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009202 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009203 let w:netrw_bannercnt= 1
9204 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009205" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9206" 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 +00009207
Bram Moolenaar85850f32019-07-19 22:05:51 +02009208 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009209 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009210 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009211 let sortby= sortby." reversed"
9212 endif
9213
9214 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009215 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009216" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009217 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009218" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009219 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009220 NetrwKeepj put ='\" Sorted by '.sortby
9221 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009222 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9223 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009224" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009225 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009226 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009227 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9228 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009229 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009230" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009231" 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 +00009232 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009233
Bram Moolenaar85850f32019-07-19 22:05:51 +02009234 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009235 if g:netrw_banner
9236 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009237" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009238 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009239 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009240 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009241 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009242 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009243 endif
9244 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009245 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009246" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009247 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009248 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009249 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009250
9251 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009252 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009253" 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 +01009254 if g:netrw_list_hide != "" && g:netrw_hide
9255 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009256 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009257 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009258 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009259 endif
9260 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009261 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009262 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009263
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009264" 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 +01009265 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009266" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009267 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009268" 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 +01009269 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009270 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009271" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009272" 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 +00009273 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009274
9275 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009276 if g:netrw_banner
9277 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009278 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009279" 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 +01009280" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009281" 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 +01009282 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009283
Bram Moolenaar446cb832008-06-24 21:56:24 +00009284 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009285" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009287 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009288 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009289 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009290 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009291" 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 +01009292" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9293 return
9294 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009295 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009296
9297 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009298 if !exists("w:netrw_bannercnt")
9299 let w:netrw_bannercnt= 0
9300 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009301" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9302" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9303" 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 +01009304
Bram Moolenaar5c736222010-01-06 20:54:52 +01009305 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009306" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009307" 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 +00009308 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009309 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009310 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009311 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009312" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009313
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009314 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009315 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009316" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009317 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009318
Bram Moolenaar5c736222010-01-06 20:54:52 +01009319 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009320" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009321 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009322 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009323 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009324 else
9325 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009326 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009327 endif
9328 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009329
Bram Moolenaar446cb832008-06-24 21:56:24 +00009330 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009331" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009332 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9333 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009334
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009335 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009336 " exten: sort by extension
9337 " The histdel(...,-1) calls remove the last search from the search history
9338" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009339 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9340 NetrwKeepj call histdel("/",-1)
9341 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9342 NetrwKeepj call histdel("/",-1)
9343 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9344 NetrwKeepj call histdel("/",-1)
9345 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9346" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009347 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009348 " normal direction sorting
9349 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9350 else
9351 " reverse direction sorting
9352 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9353 endif
9354 endif
9355 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9356 NetrwKeepj call histdel("/",-1)
9357
Bram Moolenaar446cb832008-06-24 21:56:24 +00009358 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009359 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009360" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009361 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009362" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009363 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009364 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009365" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009366 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009367 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009368" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009369 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9370 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009371 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009372 endif
9373
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009374 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009375" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009376 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009377 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009378 call histdel("/",-1)
9379 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009380 endif
9381 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009382" 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 +00009383
9384 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9386" 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 +01009387 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009388" 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 +01009389 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009390" 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 +00009391
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009392 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009393 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009394" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Christian Brabandta063b222024-11-07 14:30:30 +01009395 sil! keepp g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009396 endif
9397
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009398 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009399 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009400" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9401 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009402 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009403" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9404 else
9405" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9406" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9407" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9408" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009409 endif
9410
9411 " record previous current directory
9412 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009413" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009414
9415 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009416" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
9417" 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 +01009418 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009419" 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 +02009420 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009421" 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 +00009422
9423 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009424" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009425 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009426" 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 +01009427 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009428" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009429 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9430 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009431" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009432" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009433
Bram Moolenaar8d043172014-01-23 14:24:41 +01009434 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009435" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
9436" 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 +01009437" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9438 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009439 unlet s:treecurpos
9440 endif
9441
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009442" 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>"))
9443" 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 +00009444" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
9445endfun
9446
9447" ---------------------------------------------------------------------
9448" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009449fun! s:SetupNetrwStatusLine(statline)
9450" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
9451
9452 if !exists("s:netrw_setup_statline")
9453 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009454" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009455
9456 if !exists("s:netrw_users_stl")
9457 let s:netrw_users_stl= &stl
9458 endif
9459 if !exists("s:netrw_users_ls")
9460 let s:netrw_users_ls= &laststatus
9461 endif
9462
9463 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +02009464 let dict={}
9465 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +00009466 redir @a
9467 try
9468 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009469 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +00009470 if &bg == "dark"
9471 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
9472 else
9473 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
9474 endif
9475 endtry
9476 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +02009477 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +00009478 endif
9479
9480 " set up status line (may use User9 highlighting)
9481 " insure that windows have a statusline
9482 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +09009483 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02009484 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009485" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009486 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00009487
9488" call Dret("SetupNetrwStatusLine : stl=".&stl)
9489endfun
9490
Bram Moolenaar85850f32019-07-19 22:05:51 +02009491" =========================================
9492" Remote Directory Browsing Support: {{{1
9493" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00009494
9495" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009496" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
9497" This function assumes that a long listing will be received. Size, time,
9498" and reverse sorts will be requested of the server but not otherwise
9499" enforced here.
9500fun! s:NetrwRemoteFtpCmd(path,listcmd)
9501" 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 +01009502" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009503 " sanity check: {{{3
9504 if !exists("w:netrw_method")
9505 if exists("b:netrw_method")
9506 let w:netrw_method= b:netrw_method
9507 else
9508 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
9509" call Dret("NetrwRemoteFtpCmd")
9510 return
9511 endif
9512 endif
9513
9514 " WinXX ftp uses unix style input, so set ff to unix " {{{3
9515 let ffkeep= &ff
9516 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009517" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009518
9519 " clear off any older non-banner lines " {{{3
9520 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009521" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
9522 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009523
9524 ".........................................
9525 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
9526 " ftp + <.netrc>: Method #2
9527 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009528 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009529 endif
9530 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009531 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009532" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009533 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009534 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009535" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +01009536 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009537" 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>"))
9538 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 +01009539 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009540" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
9541 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 +01009542 endif
9543
9544 ".........................................
9545 elseif w:netrw_method == 3 " {{{3
9546 " ftp + machine,id,passwd,filename: Method #3
9547 setl ff=unix
9548 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009549 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +01009550 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009551 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +01009552 endif
9553
9554 " handle userid and password
9555 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009556" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009557 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
9558 call NetUserPass("ftp:".host)
9559 endif
9560 if exists("g:netrw_uid") && g:netrw_uid != ""
9561 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009562 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +01009563 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009564 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009565 endif
9566 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009567 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009568 endif
9569 endif
9570
9571 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009572 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009573 endif
9574 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009575 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009576" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009577 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009578 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +01009579
9580 " perform ftp:
9581 " -i : turns off interactive prompting from ftp
9582 " -n unix : DON'T use <.netrc>, even though it exists
9583 " -n win32: quit being obnoxious about password
9584 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009585" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009586 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +01009587" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009588" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
9589" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009590 endif
9591
9592 ".........................................
9593 elseif w:netrw_method == 9 " {{{3
9594 " sftp username@machine: Method #9
9595 " s:netrw_sftp_cmd
9596 setl ff=unix
9597
9598 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +09009599 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009600" call Dret("NetrwRemoteFtpCmd")
9601 return
9602
9603 ".........................................
9604 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009605 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +01009606 endif
9607
9608 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +02009609 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009610 sil! NetrwKeepj %s/\r$//e
9611 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009612 endif
9613 if a:listcmd == "dir"
9614 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009615 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
9616 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
9617 NetrwKeepj call histdel("/",-1)
9618 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009619 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 +01009620 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
9621 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009622 endif
9623 endif
9624
9625 " ftp's listing doesn't seem to include ./ or ../ " {{{3
9626 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009627 exe 'NetrwKeepj '.w:netrw_bannercnt
9628 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +01009629 endif
9630 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009631 exe 'NetrwKeepj '.w:netrw_bannercnt
9632 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +01009633 endif
9634
9635 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +09009636 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009637" call Dret("NetrwRemoteFtpCmd")
9638endfun
9639
9640" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009641" s:NetrwRemoteListing: {{{2
9642fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009643" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00009644
Bram Moolenaara6878372014-03-22 21:02:50 +01009645 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
9646 let w:netrw_bannercnt= s:bannercnt
9647 endif
9648 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +09009649 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009650 endif
9651
Bram Moolenaar446cb832008-06-24 21:56:24 +00009652 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009653
Bram Moolenaar446cb832008-06-24 21:56:24 +00009654 " sanity check:
9655 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009656" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009657 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009658" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009659 if !exists("g:netrw_quiet")
9660 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
9661 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009662 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009663" call Dret("s:NetrwRemoteListing -1")
9664 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00009665 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009666
Bram Moolenaar8d043172014-01-23 14:24:41 +01009667 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009668" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009669 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009670 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009671 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 +00009672 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009673 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 +00009674 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009675 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009676
Bram Moolenaar85850f32019-07-19 22:05:51 +02009677 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009678" call Dret("s:NetrwRemoteListing -1")
9679 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009680 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009681" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009682
Bram Moolenaar446cb832008-06-24 21:56:24 +00009683 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009684" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009685 let w:netrw_method= b:netrw_method
9686 endif
9687
Bram Moolenaar13600302014-05-22 18:26:40 +02009688 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +02009689 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009690" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009691 let s:method = "ftp"
9692 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009693 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009694 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009695 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009696 let listcmd= g:netrw_ftp_sizelist_cmd
9697 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009698" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009699 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009700" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009701
Bram Moolenaara6878372014-03-22 21:02:50 +01009702 " report on missing file or directory messages
9703 if search('[Nn]o such file or directory\|Failed to change directory')
9704 let mesg= getline(".")
9705 if exists("w:netrw_bannercnt")
9706 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009707 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009708 setl noma
9709 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009710 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009711 call netrw#ErrorMsg(s:WARNING,mesg,96)
9712" call Dret("s:NetrwRemoteListing : -1")
9713 return -1
9714 endif
9715
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009716 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 +00009717 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009718" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009719 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009720
9721 " cleanup
9722 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009723 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
9724 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009725 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009726 sil! NetrwKeepj %s/\r$//e
9727 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009728
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009729 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009730 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009731 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +01009732 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009733" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009734 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009735" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009736 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009737 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009738 exe "sil! NetrwKeepj ".line1
9739 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009740
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009741" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009742 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009743" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009744 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
9745 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009746 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009747" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009748 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
9749 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
9750 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
9751 NetrwKeepj call histdel("/",-1)
9752 NetrwKeepj call histdel("/",-1)
9753 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009754 endif
9755 endif
9756
Bram Moolenaar13600302014-05-22 18:26:40 +02009757 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00009758 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009759" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009760 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009761" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009762 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009763" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
9764 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009765 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009766 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
9767 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
9768 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
9769 NetrwKeepj call histdel("/",-1)
9770 NetrwKeepj call histdel("/",-1)
9771 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009772 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009773 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
9774 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009775 endif
9776 else
9777 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009778" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009779 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00009780 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009781" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
9782 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
9783" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009784 endif
9785 endif
9786
9787 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +01009788 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009789" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009790 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
9791 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009792 endif
9793 endif
9794
9795 if w:netrw_liststyle == s:LONGLIST
9796 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009797" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009798
9799 if s:method == "ftp"
9800 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009801 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009802 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009803 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00009804 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009805 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009806 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009807 sil! NetrwKeepj 1
9808 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009809 let line2= line(".")
9810 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009811 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009812 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009813 endif
9814 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009815 exe "sil! NetrwKeepj ".line1
9816 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009817 endif
9818
9819 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009820" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009821 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 +00009822 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009823" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009824 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009825 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009826 exe 'sil NetrwKeepj '.w:netrw_bannercnt
9827 NetrwKeepj call histdel("/",-1)
9828 NetrwKeepj call histdel("/",-1)
9829 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009830 endif
9831 endif
9832
9833" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009834" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009835" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01009836
9837" call Dret("s:NetrwRemoteListing 0")
9838 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009839endfun
9840
Bram Moolenaar446cb832008-06-24 21:56:24 +00009841" ---------------------------------------------------------------------
9842" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
9843fun! s:NetrwRemoteRm(usrhost,path) range
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009844 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009845
9846 let all= 0
9847 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9848 " remove all marked files
9849 for fname in s:netrwmarkfilelist_{bufnr("%")}
9850 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009851 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009852 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009853 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009854 let all= 1
9855 endif
9856 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01009857 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009858
9859 else
9860 " remove files specified by range
9861
9862 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009863 let keepsol = &l:sol
9864 setl nosol
9865 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +00009866
9867 " remove multiple files and directories
9868 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009869 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009870 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009871 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009872 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009873 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009874 let all= 1
9875 endif
9876 let ctr= ctr + 1
9877 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009878 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +00009879 endif
9880
9881 " refresh the (remote) directory listing
Tom Benham64a536d2024-11-07 21:15:03 +01009882 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009883 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009884endfun
9885
9886" ---------------------------------------------------------------------
9887" s:NetrwRemoteRmFile: {{{2
9888fun! s:NetrwRemoteRmFile(path,rmfile,all)
9889" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
9890
9891 let all= a:all
9892 let ok = ""
9893
9894 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
9895 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009896" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009897 if !all
9898 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009899" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009900 call inputsave()
9901 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9902 call inputrestore()
9903 echohl NONE
9904 if ok == ""
9905 let ok="no"
9906 endif
9907 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009908 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009909 let all= 1
9910 endif
9911 endif
9912
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009913 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009914" 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 +00009915 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009916" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009917 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009918 if path =~ '^\a\{3,}://'
9919 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009920 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009921 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009922 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
9923 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009924" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009925 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009926" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009927 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009928 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009929 let ok="q"
9930 else
MiguelBarroc46c21b2024-01-31 20:07:17 +01009931 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009932" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
9933" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
9934" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009935 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009936 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009937 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009938 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009939 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009940" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009941 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009942 if v:shell_error != 0
9943 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09009944 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 +01009945 else
9946 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
9947 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009948 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009949 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009950 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009951" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009952 endif
9953 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009954 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009955" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009956 endif
9957
9958 else
9959 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009960" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009961 if !all
9962 call inputsave()
9963 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9964 call inputrestore()
9965 if ok == ""
9966 let ok="no"
9967 endif
9968 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009969 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009970 let all= 1
9971 endif
9972 endif
9973
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009974 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00009975 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009976 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009977 else
9978 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009979 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
9980" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009981 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009982" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009983
9984 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009985" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
9986 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
9987" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009988 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009989" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009990
9991 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009992 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009993 endif
9994 endif
9995 endif
9996
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009997 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009999 endif
10000 endif
10001
10002" call Dret("s:NetrwRemoteRmFile ".ok)
10003 return ok
10004endfun
10005
10006" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010007" s:NetrwRemoteRename: rename a remote file or directory {{{2
10008fun! s:NetrwRemoteRename(usrhost,path) range
Bram Moolenaar446cb832008-06-24 21:56:24 +000010009
10010 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010011 let svpos = winsaveview()
10012" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010013 let ctr = a:firstline
10014 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10015
10016 " rename files given by the markfilelist
10017 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10018 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +000010019 if exists("subfrom")
10020 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010021 else
10022 call inputsave()
10023 let newname= input("Moving ".oldname." to : ",oldname)
10024 call inputrestore()
10025 if newname =~ '^s/'
10026 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10027 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10028 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010029 endif
10030 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010031
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010033 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010034 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010035 let oldname= s:ShellEscape(a:path.oldname)
10036 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010037 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010038 endif
10039
10040 endfor
10041 call s:NetrwUnMarkFile(1)
10042
10043 else
10044
10045 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010046 let keepsol= &l:sol
10047 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010048 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010049 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010050
10051 let oldname= s:NetrwGetWord()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010052
10053 call inputsave()
10054 let newname= input("Moving ".oldname." to : ",oldname)
10055 call inputrestore()
10056
10057 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10058 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10059 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010060 let oldname= s:ShellEscape(a:path.oldname)
10061 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010062 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010063 endif
10064
10065 let ctr= ctr + 1
10066 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010067 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010068 endif
10069
10070 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010071 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010072 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010073endfun
10074
Bram Moolenaar85850f32019-07-19 22:05:51 +020010075" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010076" Local Directory Browsing Support: {{{1
10077" ==========================================
10078
10079" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010080" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010081" Should accept: file://localhost/etc/fstab
10082" file:///etc/fstab
10083" file:///c:/WINDOWS/clock.avi
10084" file:///c|/WINDOWS/clock.avi
10085" file://localhost/c:/WINDOWS/clock.avi
10086" file://localhost/c|/WINDOWS/clock.avi
10087" file://c:/foo.txt
10088" file:///c:/foo.txt
10089" 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 +020010090fun! netrw#FileUrlEdit(fname)
10091" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010092 let fname = a:fname
10093 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010094" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010095 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010096" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010097 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010098 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010099 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010100" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010101 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010102" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010103 endif
10104 endif
10105 let fname2396 = netrw#RFC2396(fname)
10106 let fname2396e= fnameescape(fname2396)
10107 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010108 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010109" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010110 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010111" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010112 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10113 endif
10114 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010115
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010116" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10117" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010118 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010119 exe 'NetrwKeepj keepalt edit '.plainfname
10120 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10121
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010122" 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 +020010123" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010124 exe "sil doau BufReadPost ".fname2396e
10125endfun
10126
10127" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010128" netrw#LocalBrowseCheck: {{{2
10129fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010130 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010131 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10132 "
10133 " unfortunate interaction -- split window debugging can't be used here, must use
10134 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10135 " another call to LocalBrowseCheck() when attempts to write
10136 " to the DBG buffer are made.
10137 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010138 " The &ft == "netrw" test was installed because the BufEnter event
10139 " would hit when re-entering netrw windows, creating unexpected
10140 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010141" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010142" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010143" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +010010144 " getting E930: Cannot use :redir inside execute
10145"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010146" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10147" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010148
Bram Moolenaar97d62492012-11-15 21:28:22 +010010149 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010150 if isdirectory(s:NetrwFile(a:dirname))
10151" 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 +010010152
Bram Moolenaar97d62492012-11-15 21:28:22 +010010153 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010154" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10155" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010156 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010157
Bram Moolenaar446cb832008-06-24 21:56:24 +000010158 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010159" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010160 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010161
Bram Moolenaar5c736222010-01-06 20:54:52 +010010162 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010163" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010164 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010165 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010166 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010167" 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 +010010168" call Dret("netrw#LocalBrowseCheck")
10169 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010170 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010171
Bram Moolenaar85850f32019-07-19 22:05:51 +020010172 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010173 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10174 " AND IF the listing style is not a tree listing
10175 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010176" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010177 let ibuf = 1
10178 let buflast = bufnr("$")
10179 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010180 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10181 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010182 endif
10183 let ibuf= ibuf + 1
10184 endwhile
10185 endif
10186 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010187" 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>"))
10188" 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 +000010189 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010190" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010191endfun
10192
10193" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010194" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010195" performed any shell command. The idea is to cause all local-browsing
10196" buffers to be refreshed after a user has executed some shell command,
10197" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010198fun! s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010199 " determine which buffers currently reside in a tab
10200 if !exists("s:netrw_browselist")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010201 return
10202 endif
10203 if !exists("w:netrw_bannercnt")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010204 return
10205 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010206 if !empty(getcmdwintype())
10207 " cannot move away from cmdline window, see :h E11
10208 return
10209 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010210 if exists("s:netrw_events") && s:netrw_events == 1
10211 " s:LocalFastBrowser gets called (indirectly) from a
10212 let s:netrw_events= 2
Bram Moolenaara6878372014-03-22 21:02:50 +010010213 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010214 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010215 let itab = 1
10216 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010217 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010218 while itab <= tabpagenr("$")
10219 let buftablist = buftablist + tabpagebuflist()
10220 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010221 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010222 endwhile
Bram Moolenaar446cb832008-06-24 21:56:24 +000010223 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10224 " | refresh any netrw window
10225 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010226 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010227 let ibl = 0
10228 for ibuf in s:netrw_browselist
Bram Moolenaar446cb832008-06-24 21:56:24 +000010229 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10230 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010231 " (ibuf not shown in a current window AND
10232 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010233 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010234 call remove(s:netrw_browselist,ibl)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010235 continue
10236 elseif index(tabpagebuflist(),ibuf) != -1
10237 " refresh any netrw buffer
Bram Moolenaar446cb832008-06-24 21:56:24 +000010238 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010239 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010240 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10241 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10242 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10243 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010244 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10245 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10246 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010247 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010248 endif
10249 let ibl= ibl + 1
10250 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010251 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010252 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010253endfun
10254
10255" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010256" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10257"
10258" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010259" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010260" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10261" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010262" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010263"
10264" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10265" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010266" (re-using a buffer may not be as accurate)
10267"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010268" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010269" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10270" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10271" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10272" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010273fun! s:LocalFastBrowser()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010274
10275 " initialize browselist, a list of buffer numbers that the local browser has used
10276 if !exists("s:netrw_browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010277 let s:netrw_browselist= []
10278 endif
10279
10280 " append current buffer to fastbrowse list
10281 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaar97d62492012-11-15 21:28:22 +010010282 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010283 endif
10284
10285 " enable autocmd events to handle refreshing/removing local browser buffers
10286 " If local browse buffer is currently showing: refresh it
10287 " If local browse buffer is currently hidden : wipe it
10288 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10289 " =1 : medium speed, re-use directory listing for remote only
10290 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010291 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10292 let s:netrw_events= 1
10293 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010294 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010295 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010296 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010297 else
Bram Moolenaara6878372014-03-22 21:02:50 +010010298 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010299 endif
10300 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010301
10302 " user must have changed fastbrowse to its fast setting, so remove
10303 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010304 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara6878372014-03-22 21:02:50 +010010305 unlet s:netrw_events
10306 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010307 au!
10308 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010309 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010310 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010311endfun
10312
Tom Benham64a536d2024-11-07 21:15:03 +010010313fun! s:NetrwLocalListingList(dirname,setmaxfilenamelen)
Bram Moolenaara6878372014-03-22 21:02:50 +010010314 " get the list of files contained in the current directory
Tom Benham64a536d2024-11-07 21:15:03 +010010315 let dirname = a:dirname
10316 let dirnamelen = strlen(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010317 let filelist = s:NetrwGlob(dirname,"*",0)
10318 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010319
Nir Lichtman1e34b952024-05-08 19:19:34 +020010320 if g:netrw_cygwin == 0 && has("win32")
Tom Benham64a536d2024-11-07 21:15:03 +010010321 elseif index(filelist,'..') == -1 && dirname !~ '/'
Bram Moolenaara6878372014-03-22 21:02:50 +010010322 " include ../ in the glob() entry if its missing
Tom Benham64a536d2024-11-07 21:15:03 +010010323 let filelist= filelist+[s:ComposePath(dirname,"../")]
Bram Moolenaara6878372014-03-22 21:02:50 +010010324 endif
10325
Tom Benham64a536d2024-11-07 21:15:03 +010010326 if a:setmaxfilenamelen && get(g:, 'netrw_dynamic_maxfilenamelen', 0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010327 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10328 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara6878372014-03-22 21:02:50 +010010329 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010330
Tom Benham64a536d2024-11-07 21:15:03 +010010331 let resultfilelist = []
Bram Moolenaara6878372014-03-22 21:02:50 +010010332 for filename in filelist
Bram Moolenaara6878372014-03-22 21:02:50 +010010333
10334 if getftype(filename) == "link"
10335 " indicate a symbolic link
Bram Moolenaara6878372014-03-22 21:02:50 +010010336 let pfile= filename."@"
10337
10338 elseif getftype(filename) == "socket"
10339 " indicate a socket
Bram Moolenaara6878372014-03-22 21:02:50 +010010340 let pfile= filename."="
10341
10342 elseif getftype(filename) == "fifo"
10343 " indicate a fifo
Bram Moolenaara6878372014-03-22 21:02:50 +010010344 let pfile= filename."|"
10345
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010346 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010347 " indicate a directory
Bram Moolenaara6878372014-03-22 21:02:50 +010010348 let pfile= filename."/"
10349
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010350 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020010351 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010352 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
10353 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010354 let pfile= filename."*"
10355 else
10356 " normal file
10357 let pfile= filename
10358 endif
10359 elseif executable(filename)
10360 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010361 let pfile= filename."*"
10362 else
10363 " normal file
10364 let pfile= filename
10365 endif
10366
10367 else
10368 " normal file
10369 let pfile= filename
10370 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010371
10372 if pfile =~ '//$'
10373 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010374 endif
10375 let pfile= strpart(pfile,dirnamelen)
10376 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010377
10378 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090010379 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
10380 let sz = getfsize(filename)
10381 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
10382 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010010383
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010384 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010385 let sz= s:NetrwHumanReadable(sz)
10386 endif
K.Takata8750e3c2023-11-22 18:20:01 +090010387 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090010388 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010389 endif
10390
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010391 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010010392 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010010393 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaara6878372014-03-22 21:02:50 +010010394 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010395 let ft = printf("%018d",t)
Bram Moolenaara6878372014-03-22 21:02:50 +010010396 let ftpfile= ft.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010397 let resultfilelist += [ftpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010398
10399 elseif g:netrw_sort_by =~ "^s"
10400 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaara6878372014-03-22 21:02:50 +010010401 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010402 let fsz = printf("%018d",sz)
Bram Moolenaara6878372014-03-22 21:02:50 +010010403 let fszpfile= fsz.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010404 let resultfilelist += [fszpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010405
10406 else
10407 " sort by name
Tom Benham64a536d2024-11-07 21:15:03 +010010408 let resultfilelist += [pfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010409 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010410 endfor
10411
10412 return resultfilelist
10413endfun
10414
10415" ---------------------------------------------------------------------
10416" s:LocalListing: does the job of "ls" for local directories {{{2
10417fun! s:LocalListing()
10418
10419 let filelist = s:NetrwLocalListingList(b:netrw_curdir, 1)
10420 for filename in filelist
10421 sil! NetrwKeepj put =filename
Bram Moolenaara6878372014-03-22 21:02:50 +010010422 endfor
10423
10424 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010425 sil! NetrwKeepj g/^$/d
10426 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010010427 call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010428 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010429endfun
10430
10431" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010432" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
10433fun! s:NetrwLocalExecute(cmd)
10434" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
10435 let ykeep= @@
10436 " sanity check
10437 if !executable(a:cmd)
10438 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
10439 let @@= ykeep
10440" call Dret("s:NetrwLocalExecute")
10441 return
10442 endif
10443
10444 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010445" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010446 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010447" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010448
10449 " strip any ansi escape sequences off
10450 let result = substitute(result,"\e\\[[0-9;]*m","","g")
10451
10452 " show user the result(s)
10453 echomsg result
10454 let @@= ykeep
10455
10456" call Dret("s:NetrwLocalExecute")
10457endfun
10458
10459" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010460" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010461fun! s:NetrwLocalRename(path) range
Bram Moolenaar97d62492012-11-15 21:28:22 +010010462
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010463 if !exists("w:netrw_bannercnt")
10464 let w:netrw_bannercnt= b:netrw_bannercnt
10465 endif
10466
Bram Moolenaar97d62492012-11-15 21:28:22 +010010467 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010010468 let ykeep = @@
10469 let ctr = a:firstline
10470 let svpos = winsaveview()
10471 let all = 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010472
10473 " rename files given by the markfilelist
10474 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10475 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar97d62492012-11-15 21:28:22 +010010476 if exists("subfrom")
10477 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010478 else
10479 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010480 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010481 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010482 if newname =~ ''
10483 " two ctrl-x's : ignore all of string preceding the ctrl-x's
10484 let newname = substitute(newname,'^.*','','')
10485 elseif newname =~ ''
10486 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
10487 let newname = substitute(newname,'[^/]*','','')
10488 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010489 if newname =~ '^s/'
10490 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10491 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010492 let newname = substitute(oldname,subfrom,subto,'')
10493 endif
10494 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010010495 if !all && filereadable(newname)
10496 call inputsave()
10497 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
10498 call inputrestore()
10499 if response == "all"
10500 let all= 1
10501 elseif response != "y" && response != "yes"
10502 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010503 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar29634562020-01-09 21:46:04 +010010504 NetrwKeepj call winrestview(svpos)
10505 let @@= ykeep
Bram Moolenaar29634562020-01-09 21:46:04 +010010506 return
10507 endif
10508 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010509 call rename(oldname,newname)
10510 endfor
10511 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010512
Bram Moolenaar97d62492012-11-15 21:28:22 +010010513 else
10514
10515 " attempt to rename files/directories
10516 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010517 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010010518
10519 " sanity checks
10520 if line(".") < w:netrw_bannercnt
10521 let ctr= ctr + 1
10522 continue
10523 endif
10524 let curword= s:NetrwGetWord()
10525 if curword == "./" || curword == "../"
10526 let ctr= ctr + 1
10527 continue
10528 endif
10529
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010530 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010531 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010532
10533 call inputsave()
10534 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
10535 call inputrestore()
10536
10537 call rename(oldname,newname)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010538 let ctr= ctr + 1
10539 endwhile
10540 endif
10541
10542 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010543 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010544 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010545 let @@= ykeep
Bram Moolenaar97d62492012-11-15 21:28:22 +010010546endfun
10547
10548" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010549" s:NetrwLocalRm: {{{2
10550fun! s:NetrwLocalRm(path) range
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010551 if !exists("w:netrw_bannercnt")
10552 let w:netrw_bannercnt= b:netrw_bannercnt
10553 endif
10554
Bram Moolenaar446cb832008-06-24 21:56:24 +000010555 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010010556 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010557 let ret = 0
10558 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010559 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010560
10561 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10562 " remove all marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +000010563 for fname in s:netrwmarkfilelist_{bufnr("%")}
10564 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010565 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010566 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010567 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010568 let all= 1
10569 endif
10570 endfor
10571 call s:NetrwUnMarkFile(1)
10572
10573 else
10574 " remove (multiple) files and directories
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010576 let keepsol= &l:sol
10577 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578 let ctr = a:firstline
10579 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010580 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010581
10582 " sanity checks
10583 if line(".") < w:netrw_bannercnt
10584 let ctr= ctr + 1
10585 continue
10586 endif
10587 let curword= s:NetrwGetWord()
10588 if curword == "./" || curword == "../"
10589 let ctr= ctr + 1
10590 continue
10591 endif
10592 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010593 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010594 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010595 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596 let all= 1
10597 endif
10598 let ctr= ctr + 1
10599 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010600 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601 endif
10602
10603 " refresh the directory
Bram Moolenaar446cb832008-06-24 21:56:24 +000010604 if bufname("%") != "NetrwMessage"
Tom Benham64a536d2024-11-07 21:15:03 +010010605 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010606 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010607 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010608 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010609endfun
10610
10611" ---------------------------------------------------------------------
10612" s:NetrwLocalRmFile: remove file fname given the path {{{2
10613" Give confirmation prompt unless all==1
10614fun! s:NetrwLocalRmFile(path,fname,all)
10615" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010616
Bram Moolenaar446cb832008-06-24 21:56:24 +000010617 let all= a:all
10618 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010619 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020010620 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010621" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010622
10623 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
10624 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010625" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010626 if !all
10627 echohl Statement
10628 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010629 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010630 call inputrestore()
10631 echohl NONE
10632 if ok == ""
10633 let ok="no"
10634 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010635" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010636 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010637" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010638 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010639 let all= 1
10640 endif
10641 endif
10642
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010643 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000010644 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010645" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010646 endif
10647
10648 else
10649 " attempt to remove directory
10650 if !all
10651 echohl Statement
10652 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010653 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010654 call inputrestore()
10655 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
10656 if ok == ""
10657 let ok="no"
10658 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010659 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010660 let all= 1
10661 endif
10662 endif
10663 let rmfile= substitute(rmfile,'[\/]$','','e')
10664
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010665 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020010666 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010010667 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010668 endif
10669 endif
10670 endif
10671
10672" call Dret("s:NetrwLocalRmFile ".ok)
10673 return ok
10674endfun
10675
Bram Moolenaar85850f32019-07-19 22:05:51 +020010676" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010677" Support Functions: {{{1
10678
Bram Moolenaar488c6512005-08-11 20:09:58 +000010679" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010680" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
10681" 0: marked file list of current buffer
10682" 1: marked file target
10683fun! netrw#Access(ilist)
10684 if a:ilist == 0
10685 if exists("s:netrwmarkfilelist_".bufnr('%'))
10686 return s:netrwmarkfilelist_{bufnr('%')}
10687 else
10688 return "no-list-buf#".bufnr('%')
10689 endif
10690 elseif a:ilist == 1
10691 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020010692 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010693endfun
10694
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010695" ---------------------------------------------------------------------
10696" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
10697fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010698 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010699endfun
10700
Bram Moolenaara6878372014-03-22 21:02:50 +010010701" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010702" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
10703" I expect this function to be used in
10704" :PChkAssert netrw#Expose("netrwmarkfilelist")
10705" for example.
10706fun! netrw#Expose(varname)
10707" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010708 if exists("s:".a:varname)
10709 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010710" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010711 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010712" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010713 if type(retval) == 3
10714 let retval = copy(retval)
10715 let i = 0
10716 while i < len(retval)
10717 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
10718 let i = i + 1
10719 endwhile
10720 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010721" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010722 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010723 else
10724" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010725 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010726 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010727" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010728 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010729 endif
10730
10731" call Dret("netrw#Expose ".string(retval))
10732 return retval
10733endfun
10734
10735" ---------------------------------------------------------------------
10736" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
10737fun! netrw#Modify(varname,newvalue)
10738" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
10739 exe "let s:".a:varname."= ".string(a:newvalue)
10740" call Dret("netrw#Modify")
10741endfun
10742
10743" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010744" netrw#RFC2396: converts %xx into characters {{{2
10745fun! netrw#RFC2396(fname)
10746" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090010747 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010010748" call Dret("netrw#RFC2396 ".fname)
10749 return fname
10750endfun
10751
10752" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010753" netrw#UserMaps: supports user-specified maps {{{2
10754" see :help function()
10755"
10756" g:Netrw_UserMaps is a List with members such as:
10757" [[keymap sequence, function reference],...]
10758"
10759" The referenced function may return a string,
10760" refresh : refresh the display
10761" -other- : this string will be executed
10762" or it may return a List of strings.
10763"
10764" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020010765" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010766" Related functions:
10767" netrw#Expose(varname) -- see s:varname variables
10768" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
10769" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
10770fun! netrw#UserMaps(islocal)
10771" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
10772" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
10773
10774 " set up usermaplist
10775 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
10776" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
10777 for umap in g:Netrw_UserMaps
10778" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
10779" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
10780 " if umap[0] is a string and umap[1] is a string holding a function name
10781 if type(umap[0]) == 1 && type(umap[1]) == 1
10782" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
10783 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
10784 else
10785 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
10786 endif
10787 endfor
10788 endif
10789" call Dret("netrw#UserMaps")
10790endfun
10791
10792" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010793" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
10794fun! netrw#WinPath(path)
10795" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010796 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010797 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010010798 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010799 " remove trailing slash (Win95)
10800 let path = substitute(path, '\(\\\|/\)$', '', 'g')
10801 " remove escaped spaces
10802 let path = substitute(path, '\ ', ' ', 'g')
10803 " convert slashes to backslashes
10804 let path = substitute(path, '/', '\', 'g')
10805 else
10806 let path= a:path
10807 endif
10808" call Dret("netrw#WinPath <".path.">")
10809 return path
10810endfun
10811
10812" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020010813" s:StripTrailingSlash: removes trailing slashes from a path {{{2
10814fun! s:StripTrailingSlash(path)
10815 " remove trailing slash
10816 return substitute(a:path, '[/\\]$', '', 'g')
10817endfun
10818
Travis Sheltone34d0e32024-07-30 21:08:56 +020010819" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010820" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
10821" cb : bl2mf=0 add marked files to buffer list
10822" cB : bl2mf=1 use bufferlist to mark files
10823" (mnemonic: cb = copy (marked files) to buffer list)
10824fun! s:NetrwBadd(islocal,bl2mf)
10825" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
10826 if a:bl2mf
10827 " cB: add buffer list to marked files
10828 redir => bufl
10829 ls
10830 redir END
10831 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
10832 for fname in bufl
10833 call s:NetrwMarkFile(a:islocal,fname)
10834 endfor
10835 else
10836 " cb: add marked files to buffer list
10837 for fname in s:netrwmarkfilelist_{bufnr("%")}
10838" " call Decho("badd ".fname,'~'.expand("<slnum>"))
10839 exe "badd ".fnameescape(fname)
10840 endfor
10841 let curbufnr = bufnr("%")
10842 let curdir = s:NetrwGetCurdir(a:islocal)
10843 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
10844 endif
10845" call Dret("s:NetrwBadd")
10846endfun
10847
10848" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010849" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
10850fun! s:ComposePath(base,subdir)
10851" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
10852
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010853 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010854" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010855 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000010856 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010857 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010858 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010859 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010860 endif
10861
Bram Moolenaar85850f32019-07-19 22:05:51 +020010862 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020010863 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010864" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010865 let ret= a:subdir
10866
Nir Lichtman1e34b952024-05-08 19:19:34 +020010867 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010868" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010869 if a:base =~ '[/\\]$'
10870 let ret= a:base.a:subdir
10871 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010872 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010010873 endif
10874
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010875 elseif a:base =~ '^\a\{3,}://'
10876" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010877 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
10878 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
10879 if a:subdir == '../'
10880 if curpath =~ '[^/]/[^/]\+/$'
10881 let curpath= substitute(curpath,'[^/]\+/$','','')
10882 else
10883 let curpath=""
10884 endif
10885 let ret= urlbase.curpath
10886 else
10887 let ret= urlbase.curpath.a:subdir
10888 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010889" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
10890" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
10891" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010892
10893 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010894" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010895 let ret = substitute(a:base."/".a:subdir,"//","/","g")
10896 if a:base =~ '^//'
10897 " keeping initial '//' for the benefit of network share listing support
10898 let ret= '/'.ret
10899 endif
10900 let ret= simplify(ret)
10901 endif
10902
10903" call Dret("s:ComposePath ".ret)
10904 return ret
10905endfun
10906
10907" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010908" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
10909" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
10910fun! s:DeleteBookmark(fname)
10911" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
10912 call s:MergeBookmarks()
10913
10914 if exists("g:netrw_bookmarklist")
10915 let indx= index(g:netrw_bookmarklist,a:fname)
10916 if indx == -1
10917 let indx= 0
10918 while indx < len(g:netrw_bookmarklist)
10919 if g:netrw_bookmarklist[indx] =~ a:fname
10920 call remove(g:netrw_bookmarklist,indx)
10921 let indx= indx - 1
10922 endif
10923 let indx= indx + 1
10924 endwhile
10925 else
10926 " remove exact match
10927 call remove(g:netrw_bookmarklist,indx)
10928 endif
10929 endif
10930
10931" call Dret("s:DeleteBookmark")
10932endfun
10933
10934" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010935" s:FileReadable: o/s independent filereadable {{{2
10936fun! s:FileReadable(fname)
10937" call Dfunc("s:FileReadable(fname<".a:fname.">)")
10938
10939 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010940 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010941 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010942 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010943 endif
10944
10945" call Dret("s:FileReadable ".ret)
10946 return ret
10947endfun
10948
10949" ---------------------------------------------------------------------
10950" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
10951" Places correct suffix on end of temporary filename,
10952" using the suffix provided with fname
10953fun! s:GetTempfile(fname)
10954" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
10955
10956 if !exists("b:netrw_tmpfile")
10957 " get a brand new temporary filename
10958 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010959" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010960
Bram Moolenaarc236c162008-07-13 17:41:49 +000010961 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010962" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010963
Bram Moolenaar9964e462007-05-05 17:54:07 +000010964 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010965 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
10966" 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 +010010967 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010968" call Dret("s:GetTempfile getcwd<".getcwd().">")
10969 return ""
10970 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010971
Bram Moolenaar9964e462007-05-05 17:54:07 +000010972 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010973 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010974" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010975
Bram Moolenaar9964e462007-05-05 17:54:07 +000010976 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000010977 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010010978 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020010979 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010980 if !exists("+shellslash") || !&ssl
10981 let tmpfile = substitute(tmpfile,'/','\','g')
10982 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010983 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010984 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000010985 endif
10986 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010987" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010988 else
10989 " re-use temporary filename
10990 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010991" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010992 endif
10993
10994 " use fname's suffix for the temporary file
10995 if a:fname != ""
10996 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010997" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010998 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000010999 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011000 elseif a:fname =~ '.txz$'
11001 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011002 else
11003 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11004 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011005" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011006 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011007" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011008 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011009" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011010 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11011 endif
11012 endif
11013
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011014" 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 +000011015" call Dret("s:GetTempfile <".tmpfile.">")
11016 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011017endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011018
11019" ---------------------------------------------------------------------
11020" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011021" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011022fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011023" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011024 if s:user == ""
11025 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11026 else
11027 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11028 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011029 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011030 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011031 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011032 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011033 else
11034 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11035 endif
11036" call Dret("s:MakeSshCmd <".sshcmd.">")
11037 return sshcmd
11038endfun
11039
11040" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011041" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11042fun! s:MakeBookmark(fname)
11043" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11044
11045 if !exists("g:netrw_bookmarklist")
11046 let g:netrw_bookmarklist= []
11047 endif
11048
11049 if index(g:netrw_bookmarklist,a:fname) == -1
11050 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011051 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011052 call add(g:netrw_bookmarklist,a:fname.'/')
11053 elseif a:fname !~ '/'
11054 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11055 else
11056 call add(g:netrw_bookmarklist,a:fname)
11057 endif
11058 call sort(g:netrw_bookmarklist)
11059 endif
11060
11061" call Dret("s:MakeBookmark")
11062endfun
11063
11064" ---------------------------------------------------------------------
11065" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11066fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011067" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011068 " get bookmarks from .netrwbook file
11069 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011070 if filereadable(s:NetrwFile(savefile))
11071" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011072 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011073" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011074 NetrwKeepj call delete(savefile)
11075 endif
11076" call Dret("s:MergeBookmarks")
11077endfun
11078
11079" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011080" s:NetrwBMShow: {{{2
11081fun! s:NetrwBMShow()
11082" call Dfunc("s:NetrwBMShow()")
11083 redir => bmshowraw
11084 menu
11085 redir END
11086 let bmshowlist = split(bmshowraw,'\n')
11087 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011088 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011089 if bmshowfuncs != []
11090 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011091 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011092 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011093 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011094 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011095 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011096" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11097endfun
11098
11099" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011100" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011101fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011102 if !exists("w:netrw_liststyle")
11103 let w:netrw_liststyle= g:netrw_liststyle
11104 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011105" 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 +020011106
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011107" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11108
Bram Moolenaaradc21822011-04-01 18:03:16 +020011109 if &ft != "netrw"
11110 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11111 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011112" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011113
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011114 elseif g:netrw_cursor == 8
11115 if w:netrw_liststyle == s:WIDELIST
11116 setl cursorline
11117 setl cursorcolumn
11118 else
11119 setl cursorline
11120 endif
11121 elseif g:netrw_cursor == 7
11122 setl cursorline
11123 elseif g:netrw_cursor == 6
11124 if w:netrw_liststyle == s:WIDELIST
11125 setl cursorline
11126 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011127 elseif g:netrw_cursor == 4
11128 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011129" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011130 setl cursorline
11131 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011132
11133 elseif g:netrw_cursor == 3
11134 " thin-long-tree: cursorline, user's cursorcolumn
11135 " wide : cursorline, cursorcolumn
11136 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011137" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011138 setl cursorline
11139 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011140 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011141" 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 +020011142 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011143 endif
11144
11145 elseif g:netrw_cursor == 2
11146 " thin-long-tree: cursorline, user's cursorcolumn
11147 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011148" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011149 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011150
11151 elseif g:netrw_cursor == 1
11152 " thin-long-tree: user's cursorline, user's cursorcolumn
11153 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011154 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011155" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011156 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011157 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011158" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011159 endif
11160
11161 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011162 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011163" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011164 let &l:cursorline = s:netrw_usercul
11165 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011166 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011167
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011168" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011169" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011170endfun
11171
11172" ---------------------------------------------------------------------
11173" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11174fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011175" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011176 if exists("s:netrw_usercul")
11177 let &l:cursorline = s:netrw_usercul
11178 endif
11179 if exists("s:netrw_usercuc")
11180 let &l:cursorcolumn = s:netrw_usercuc
11181 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011182" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011183" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11184endfun
11185
Christian Brabandt62f7b552024-06-23 20:23:40 +020011186" s:RestoreRegister: restores all registers given in the dict {{{2
11187fun! s:RestoreRegister(dict)
11188 for [key, val] in items(a:dict)
11189 if key == 'unnamed'
11190 let key = ''
11191 endif
11192 call setreg(key, val[0], val[1])
11193 endfor
11194endfun
11195
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011196" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011197" s:NetrwDelete: Deletes a file. {{{2
11198" Uses Steve Hall's idea to insure that Windows paths stay
11199" acceptable. No effect on Unix paths.
11200" Examples of use: let result= s:NetrwDelete(path)
11201fun! s:NetrwDelete(path)
11202" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11203
Bram Moolenaar5c736222010-01-06 20:54:52 +010011204 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011205 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011206 if exists("+shellslash")
11207 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011208 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011209 let result = delete(path)
11210 let &shellslash = sskeep
11211 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011212" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011213 let result= delete(path)
11214 endif
11215 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011216" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011217 let result= delete(path)
11218 endif
11219 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011220 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011221 endif
11222
11223" call Dret("s:NetrwDelete ".result)
11224 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011225endfun
11226
11227" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011228" s:NetrwBufRemover: removes a buffer that: {{{2s
11229" has buffer-id > 1
11230" is unlisted
11231" is unnamed
11232" does not appear in any window
11233fun! s:NetrwBufRemover(bufid)
11234" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11235" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11236" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11237" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11238" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11239
yasuda4dbb2662023-10-04 20:50:35 +020011240 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011241" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020011242 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011243 endif
11244
11245" call Dret("s:NetrwBufRemover")
11246endfun
11247
11248" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011249" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011250fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011251" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011252" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011253
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011254 " Clean out the last buffer:
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011255 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
11256 " If so, delete it.
11257 call s:NetrwBufRemover(bufnr("$"))
11258
Bram Moolenaar446cb832008-06-24 21:56:24 +000011259 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011260" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011261 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11262 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11263 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11264 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11265 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11266 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11267 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11268 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11269 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11270 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11271 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11272 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11273 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11274 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11275 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11276 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11277
Bram Moolenaar85850f32019-07-19 22:05:51 +020011278 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011279" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011280 " when tree listing uses file TreeListing... a new buffer is made.
11281 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011282 " COMBAK: this causes a problem, see P43
11283" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011284 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010011285 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011286 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011287" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020011288 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011289
Bram Moolenaar446cb832008-06-24 21:56:24 +000011290 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011291" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011292 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11293 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11294 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11295 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11296 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11297 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11298 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11299 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11300 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11301 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11302 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11303 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11304 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11305 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11306 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
11307 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
11308
Bram Moolenaar5c736222010-01-06 20:54:52 +010011309 if a:0 > 0
11310 let b:netrw_curdir= a:1
11311 if b:netrw_curdir =~ '/$'
11312 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011313 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010011314 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011315 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020011316 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
11317 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010011318 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011319 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010011320 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011321 endif
11322 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011323 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
11324 let &l:bexpr = "netrw#BalloonHelp()"
11325 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011326
Bram Moolenaar8d043172014-01-23 14:24:41 +010011327" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011328endfun
11329
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011330" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011331" s:NetrwExe: executes a string using "!" {{{2
11332fun! s:NetrwExe(cmd)
GuyBrushd7745ac2024-11-23 14:13:10 +010011333 if has("win32") && exepath(&shell) !~? '\v[\/]?(cmd|pwsh|powershell)(\.exe)?$' && !g:netrw_cygwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011334 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
11335 set shell& shellcmdflag& shellxquote& shellxescape&
11336 set shellquote& shellpipe& shellredir& shellslash&
Konfekt3d7e5672024-10-27 22:16:49 +010011337 try
11338 exe a:cmd
11339 finally
11340 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
11341 endtry
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011342 else
11343 exe a:cmd
11344 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011345 if v:shell_error
11346 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
11347 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011348endfun
11349
11350" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011351" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
11352fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011353 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011354" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011355 let curbuf = bufnr("%")
11356 let curwin = winnr()
11357 let iwin = 1
11358 while iwin <= winnr("$")
11359 exe iwin."wincmd w"
11360 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
11361 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
11362 let winvars= w:
11363 break
11364 endif
11365 let iwin= iwin + 1
11366 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020011367 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011368 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011369" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011370 for k in keys(winvars)
11371 let w:{k}= winvars[k]
11372 endfor
11373 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011374" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011375 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011376endfun
11377
Bram Moolenaara6878372014-03-22 21:02:50 +010011378" ---------------------------------------------------------------------
11379" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020011380" Returns: 0=success
11381" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010011382fun! s:NetrwLcd(newdir)
11383" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011384" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011385
Bram Moolenaar85850f32019-07-19 22:05:51 +020011386 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011387 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011388 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010011389 catch /^Vim\%((\a\+)\)\=:E344/
11390 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
11391 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011392 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010011393 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
11394 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020011395 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010011396 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
11397 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090011398 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010011399 endif
11400 endif
11401 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020011402 let err472= 1
11403 endtry
11404
11405 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010011406 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
11407 if exists("w:netrw_prvdir")
11408 let a:newdir= w:netrw_prvdir
11409 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011410 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011411" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020011412 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011413" 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 +010011414 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010011415 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011416" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
11417 return -1
11418 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011419
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011420" call Decho("getcwd <".getcwd().">")
11421" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011422" call Dret("s:NetrwLcd 0")
11423 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011424endfun
11425
Bram Moolenaar9964e462007-05-05 17:54:07 +000011426" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011427" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
11428" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
11429fun! s:NetrwSaveWordPosn()
11430" call Dfunc("NetrwSaveWordPosn()")
11431 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
11432" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
11433endfun
11434
11435" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011436" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
11437" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
11438fun! s:NetrwHumanReadable(sz)
11439" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
11440
11441 if g:netrw_sizestyle == 'h'
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011442 if a:sz >= 1000000000
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011443 let sz = printf("%.1f",a:sz/1000000000.0)."g"
11444 elseif a:sz >= 10000000
11445 let sz = printf("%d",a:sz/1000000)."m"
11446 elseif a:sz >= 1000000
11447 let sz = printf("%.1f",a:sz/1000000.0)."m"
11448 elseif a:sz >= 10000
11449 let sz = printf("%d",a:sz/1000)."k"
11450 elseif a:sz >= 1000
11451 let sz = printf("%.1f",a:sz/1000.0)."k"
11452 else
11453 let sz= a:sz
11454 endif
11455
11456 elseif g:netrw_sizestyle == 'H'
11457 if a:sz >= 1073741824
11458 let sz = printf("%.1f",a:sz/1073741824.0)."G"
11459 elseif a:sz >= 10485760
11460 let sz = printf("%d",a:sz/1048576)."M"
11461 elseif a:sz >= 1048576
11462 let sz = printf("%.1f",a:sz/1048576.0)."M"
11463 elseif a:sz >= 10240
11464 let sz = printf("%d",a:sz/1024)."K"
11465 elseif a:sz >= 1024
11466 let sz = printf("%.1f",a:sz/1024.0)."K"
11467 else
11468 let sz= a:sz
11469 endif
11470
11471 else
11472 let sz= a:sz
11473 endif
11474
11475" call Dret("s:NetrwHumanReadable ".sz)
11476 return sz
11477endfun
11478
11479" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011480" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
11481" changed sorting, etc. Also see s:NetrwSaveWordPosn().
11482fun! s:NetrwRestoreWordPosn()
11483" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011484 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000011485" call Dret("NetrwRestoreWordPosn")
11486endfun
11487
11488" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011489" s:RestoreBufVars: {{{2
11490fun! s:RestoreBufVars()
11491" call Dfunc("s:RestoreBufVars()")
11492
11493 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
11494 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
11495 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
11496 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
11497 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
11498 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
11499
11500" call Dret("s:RestoreBufVars")
11501endfun
11502
11503" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011504" s:RemotePathAnalysis: {{{2
11505fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020011506" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011507
Bram Moolenaara6878372014-03-22 21:02:50 +010011508 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010011509 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011510 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010011511 let s:user = substitute(a:dirname,dirpat,'\3','')
11512 let s:machine = substitute(a:dirname,dirpat,'\4','')
11513 let s:port = substitute(a:dirname,dirpat,'\5','')
11514 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020011515 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010011516 if s:machine =~ '@'
11517 let dirpat = '^\(.*\)@\(.\{-}\)$'
11518 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
11519 let s:machine = substitute(s:machine,dirpat,'\2','')
11520 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011521
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011522" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
11523" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
11524" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
11525" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
11526" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
11527" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011528
11529" call Dret("s:RemotePathAnalysis")
11530endfun
11531
11532" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011533" s:RemoteSystem: runs a command on a remote host using ssh {{{2
11534" Returns status
11535" Runs system() on
11536" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011537" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000011538fun! s:RemoteSystem(cmd)
11539" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
11540 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011541 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 +000011542 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011543 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011544 else
11545 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
11546 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
11547 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011548 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000011549 else
11550 let cmd= cmd.' '
11551 endif
11552 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011553" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011554 let ret= system(cmd)
11555 endif
11556" call Dret("s:RemoteSystem ".ret)
11557 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000011558endfun
11559
11560" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011561" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011562fun! s:RestoreWinVars()
11563" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011564 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011565 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
11566 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
11567 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
11568 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
11569 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
11570 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
11571 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
11572 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
11573 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
11574 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
11575 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
11576 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000011577 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
11578 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011579 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
11580 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
11581 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
11582" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011583endfun
11584
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011585" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011586" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
11587"
11588" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
11589" is true) and a command, :Rexplore, which call this function.
11590"
Bram Moolenaar85850f32019-07-19 22:05:51 +020011591" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011592"
11593" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000011594fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020011595 if exists("s:netrwdrag")
11596 return
11597 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011598" 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 +010011599" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
11600" 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 +010011601
11602 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011603 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011604" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011605 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011606 unlet w:netrw_rexfile
11607" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020011608 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011609" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011610" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
11611" 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 +020011612 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011613
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011614 " ---------------------------
11615 " :Rex issued while in a file
11616 " ---------------------------
11617
Bram Moolenaara6878372014-03-22 21:02:50 +010011618 " record current file so :Rex can return to it from netrw
11619 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011620" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011621
11622 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011623" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010011624 return
11625 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011626" 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 +020011627 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011628 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011629 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011630 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011631 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011632 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010011633 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020011634 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011635 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011636" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
11637 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011638" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
11639 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011640 if exists("s:rexposn_".bufnr('%'))
11641 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011642 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011643 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011644" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011645 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011646
Bram Moolenaar85850f32019-07-19 22:05:51 +020011647 if has("syntax") && exists("g:syntax_on") && g:syntax_on
11648 if exists("s:explore_match")
11649 exe "2match netrwMarkFile /".s:explore_match."/"
11650 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010011651 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011652
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011653" 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 +010011654" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011655endfun
11656
11657" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011658" s:SaveBufVars: save selected b: variables to s: variables {{{2
11659" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000011660fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011661" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011662
11663 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
11664 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
11665 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
11666 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
11667 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
11668 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
11669
11670" call Dret("s:SaveBufVars")
11671endfun
11672
11673" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011674" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
11675fun! s:SavePosn(posndict)
11676" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
11677
Bram Moolenaar85850f32019-07-19 22:05:51 +020011678 if !exists("a:posndict[bufnr('%')]")
11679 let a:posndict[bufnr("%")]= []
11680 endif
11681" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11682 call add(a:posndict[bufnr("%")],winsaveview())
11683" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011684
11685" call Dret("s:SavePosn posndict")
11686 return a:posndict
11687endfun
11688
11689" ---------------------------------------------------------------------
11690" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
11691fun! s:RestorePosn(posndict)
11692" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011693 if exists("a:posndict")
11694 if has_key(a:posndict,bufnr("%"))
11695" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11696 let posnlen= len(a:posndict[bufnr("%")])
11697 if posnlen > 0
11698 let posnlen= posnlen - 1
11699" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
11700 call winrestview(a:posndict[bufnr("%")][posnlen])
11701 call remove(a:posndict[bufnr("%")],posnlen)
11702" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11703 endif
11704 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011705 endif
11706" call Dret("s:RestorePosn")
11707endfun
11708
11709" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011710" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011711fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011712" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011713 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
11714 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
11715 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
11716 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
11717 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
11718 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
11719 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
11720 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
11721 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
11722 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
11723 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
11724 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
11725 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
11726 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
11727 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
11728 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
11729 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
11730 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
11731" call Dret("s:SaveWinVars")
11732endfun
11733
11734" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011735" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011736" To allow separate windows to have their own activities, such as
11737" Explore **/pattern, several variables have been made window-oriented.
11738" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011739" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011740" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011741fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011742" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011743 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
11744 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
11745 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
11746 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
11747 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
11748 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
11749 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
11750 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
11751 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
11752 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
11753" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011754endfun
11755
11756" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011757" s:SetRexDir: set directory for :Rexplore {{{2
11758fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011759" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011760 let w:netrw_rexdir = a:dirname
11761 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011762 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011763" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
11764" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011765" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011766" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011767" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011768endfun
11769
11770" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011771" s:ShowLink: used to modify thin and tree listings to show links {{{2
11772fun! s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011773 if exists("b:netrw_curdir")
11774 norm! $?\a
Tom Benham64a536d2024-11-07 21:15:03 +010011775 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
11776 let basedir = s:NetrwTreePath(w:netrw_treetop)
11777 else
11778 let basedir = b:netrw_curdir.'/'
11779 endif
11780 let fname = basedir.s:NetrwGetWord()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011781 let resname = resolve(fname)
Tom Benham64a536d2024-11-07 21:15:03 +010011782 if resname =~ '^\M'.basedir
11783 let dirlen = strlen(basedir)
11784 let resname = strpart(resname,dirlen)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011785 endif
11786 let modline = getline(".")."\t --> ".resname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011787 setl noro ma
11788 call setline(".",modline)
11789 setl ro noma nomod
11790 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011791endfun
11792
11793" ---------------------------------------------------------------------
11794" s:ShowStyle: {{{2
11795fun! s:ShowStyle()
11796 if !exists("w:netrw_liststyle")
11797 let liststyle= g:netrw_liststyle
11798 else
11799 let liststyle= w:netrw_liststyle
11800 endif
11801 if liststyle == s:THINLIST
11802 return s:THINLIST.":thin"
11803 elseif liststyle == s:LONGLIST
11804 return s:LONGLIST.":long"
11805 elseif liststyle == s:WIDELIST
11806 return s:WIDELIST.":wide"
11807 elseif liststyle == s:TREELIST
11808 return s:TREELIST.":tree"
11809 else
11810 return 'n/a'
11811 endif
11812endfun
11813
11814" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011815" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
11816" Solution from Nicolai Weibull, vim docs (:help strlen()),
11817" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000011818fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011819" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
11820
11821 if v:version >= 703 && exists("*strdisplaywidth")
11822 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011823
Bram Moolenaar8d043172014-01-23 14:24:41 +010011824 elseif type(g:Align_xstrlen) == 1
11825 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
11826 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011827
Bram Moolenaar8d043172014-01-23 14:24:41 +010011828 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000011829 " number of codepoints (Latin a + combining circumflex is two codepoints)
11830 " (comment from TM, solution from NW)
11831 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011832
Bram Moolenaar8d043172014-01-23 14:24:41 +010011833 elseif g:Align_xstrlen == 2
11834 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000011835 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
11836 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011837 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011838
Bram Moolenaar8d043172014-01-23 14:24:41 +010011839 elseif g:Align_xstrlen == 3
11840 " virtual length (counting, for instance, tabs as anything between 1 and
11841 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000011842 " preceded by lam, one otherwise, etc.)
11843 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011844 let modkeep= &l:mod
11845 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011846 call setline(line("."),a:x)
11847 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010011848 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011849 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010011850 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011851
Bram Moolenaar446cb832008-06-24 21:56:24 +000011852 else
11853 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010011854 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011855 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010011856" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011857 return ret
11858endfun
11859
11860" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011861" s:ShellEscape: shellescape(), or special windows handling {{{2
11862fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011863 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011864 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011865 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011866 let f = a:0 > 0 ? a:1 : 0
11867 return shellescape(a:s, f)
11868endfun
11869
11870" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011871" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000011872fun! s:TreeListMove(dir)
11873" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011874 let curline = getline('.')
11875 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
11876 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
11877 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
11878 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
11879 let treedepthchr = substitute(s:treedepthstring,' ','','g')
11880 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
11881" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
11882" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
11883" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
11884" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
11885" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
11886 " COMBAK : need to handle when on a directory
11887 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000011888 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011889 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011890 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011891 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011892" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011893 elseif a:dir == '[]' && nxtline != ''
11894 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011895" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011896 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
11897 if nl != 0
11898 NetrwKeepj norm! k
11899 else
11900 NetrwKeepj norm! G
11901 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011902" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011903 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011904 endif
11905
11906" call Dret("s:TreeListMove")
11907endfun
11908
11909" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011910" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
11911" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
11912" can't be called except via emenu. But due to locale, that menu line may not be called
11913" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
11914fun! s:UpdateBuffersMenu()
11915" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011916 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011917 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020011918 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011919 catch /^Vim\%((\a\+)\)\=:E/
11920 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011921 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000011922 endtry
11923 endif
11924" call Dret("s:UpdateBuffersMenu")
11925endfun
11926
11927" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011928" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020011929" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011930fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000011931" call Dfunc("s:UseBufWinVars()")
11932 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011933 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
11934 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
11935 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
11936 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
11937 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
11938 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11939 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11940 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
11941 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 +000011942" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011943endfun
11944
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011945" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011946" s:UserMaps: supports user-defined UserMaps {{{2
11947" * calls a user-supplied funcref(islocal,curdir)
11948" * interprets result
11949" See netrw#UserMaps()
11950fun! s:UserMaps(islocal,funcname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011951 if !exists("b:netrw_curdir")
11952 let b:netrw_curdir= getcwd()
11953 endif
11954 let Funcref = function(a:funcname)
11955 let result = Funcref(a:islocal)
11956
11957 if type(result) == 1
11958 " if result from user's funcref is a string...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011959 if result == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011960 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011961 elseif result != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011962 exe result
11963 endif
11964
11965 elseif type(result) == 3
11966 " if result from user's funcref is a List...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011967 for action in result
11968 if action == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011969 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011970 elseif action != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011971 exe action
11972 endif
11973 endfor
11974 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011975endfun
11976
Bram Moolenaar85850f32019-07-19 22:05:51 +020011977" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011978" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011979" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000011980let &cpo= s:keepcpo
11981unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000011982
Bram Moolenaar85850f32019-07-19 22:05:51 +020011983" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000011984" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011985" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000011986" vim:ts=8 fdm=marker